You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_str
  4. from ..utils import (
  5. int_or_none,
  6. qualities,
  7. )
  8. class KamcordIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?kamcord\.com/v/(?P<id>[^/?#&]+)'
  10. _TEST = {
  11. 'url': 'https://www.kamcord.com/v/hNYRduDgWb4',
  12. 'md5': 'c3180e8a9cfac2e86e1b88cb8751b54c',
  13. 'info_dict': {
  14. 'id': 'hNYRduDgWb4',
  15. 'ext': 'mp4',
  16. 'title': 'Drinking Madness',
  17. 'uploader': 'jacksfilms',
  18. 'uploader_id': '3044562',
  19. 'view_count': int,
  20. 'like_count': int,
  21. 'comment_count': int,
  22. },
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. video = self._parse_json(
  28. self._search_regex(
  29. r'window\.__props\s*=\s*({.+?});?(?:\n|\s*</script)',
  30. webpage, 'video'),
  31. video_id)['video']
  32. title = video['title']
  33. formats = self._extract_m3u8_formats(
  34. video['play']['hls'], video_id, 'mp4', entry_protocol='m3u8_native')
  35. self._sort_formats(formats)
  36. uploader = video.get('user', {}).get('username')
  37. uploader_id = video.get('user', {}).get('id')
  38. view_count = int_or_none(video.get('viewCount'))
  39. like_count = int_or_none(video.get('heartCount'))
  40. comment_count = int_or_none(video.get('messageCount'))
  41. preference_key = qualities(('small', 'medium', 'large'))
  42. thumbnails = [{
  43. 'url': thumbnail_url,
  44. 'id': thumbnail_id,
  45. 'preference': preference_key(thumbnail_id),
  46. } for thumbnail_id, thumbnail_url in (video.get('thumbnail') or {}).items()
  47. if isinstance(thumbnail_id, compat_str) and isinstance(thumbnail_url, compat_str)]
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'uploader': uploader,
  52. 'uploader_id': uploader_id,
  53. 'view_count': view_count,
  54. 'like_count': like_count,
  55. 'comment_count': comment_count,
  56. 'thumbnails': thumbnails,
  57. 'formats': formats,
  58. }