keezmovies.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..aes import aes_decrypt_text
  5. from ..compat import (
  6. compat_str,
  7. compat_urllib_parse_unquote,
  8. )
  9. from ..utils import (
  10. determine_ext,
  11. ExtractorError,
  12. int_or_none,
  13. str_to_int,
  14. strip_or_none,
  15. )
  16. class KeezMoviesIE(InfoExtractor):
  17. _VALID_URL = r'https?://(?:www\.)?keezmovies\.com/video/(?:(?P<display_id>[^/]+)-)?(?P<id>\d+)'
  18. _TESTS = [{
  19. 'url': 'https://www.keezmovies.com/video/arab-wife-want-it-so-bad-i-see-she-thirsty-and-has-tiny-money-18070681',
  20. 'md5': '2ac69cdb882055f71d82db4311732a1a',
  21. 'info_dict': {
  22. 'id': '18070681',
  23. 'display_id': 'arab-wife-want-it-so-bad-i-see-she-thirsty-and-has-tiny-money',
  24. 'ext': 'mp4',
  25. 'title': 'Arab wife want it so bad I see she thirsty and has tiny money.',
  26. 'thumbnail': None,
  27. 'view_count': int,
  28. 'age_limit': 18,
  29. }
  30. }, {
  31. 'url': 'http://www.keezmovies.com/video/18070681',
  32. 'only_matching': True,
  33. }]
  34. def _extract_info(self, url, fatal=True):
  35. mobj = re.match(self._VALID_URL, url)
  36. video_id = mobj.group('id')
  37. display_id = (mobj.group('display_id')
  38. if 'display_id' in mobj.groupdict()
  39. else None) or mobj.group('id')
  40. webpage = self._download_webpage(
  41. url, display_id, headers={'Cookie': 'age_verified=1'})
  42. formats = []
  43. format_urls = set()
  44. title = None
  45. thumbnail = None
  46. duration = None
  47. encrypted = False
  48. def extract_format(format_url, height=None):
  49. if not isinstance(format_url, compat_str) or not format_url.startswith(('http', '//')):
  50. return
  51. if format_url in format_urls:
  52. return
  53. format_urls.add(format_url)
  54. tbr = int_or_none(self._search_regex(
  55. r'[/_](\d+)[kK][/_]', format_url, 'tbr', default=None))
  56. if not height:
  57. height = int_or_none(self._search_regex(
  58. r'[/_](\d+)[pP][/_]', format_url, 'height', default=None))
  59. if encrypted:
  60. format_url = aes_decrypt_text(
  61. video_url, title, 32).decode('utf-8')
  62. formats.append({
  63. 'url': format_url,
  64. 'format_id': '%dp' % height if height else None,
  65. 'height': height,
  66. 'tbr': tbr,
  67. })
  68. flashvars = self._parse_json(
  69. self._search_regex(
  70. r'flashvars\s*=\s*({.+?});', webpage,
  71. 'flashvars', default='{}'),
  72. display_id, fatal=False)
  73. if flashvars:
  74. title = flashvars.get('video_title')
  75. thumbnail = flashvars.get('image_url')
  76. duration = int_or_none(flashvars.get('video_duration'))
  77. encrypted = flashvars.get('encrypted') is True
  78. for key, value in flashvars.items():
  79. mobj = re.search(r'quality_(\d+)[pP]', key)
  80. if mobj:
  81. extract_format(value, int(mobj.group(1)))
  82. video_url = flashvars.get('video_url')
  83. if video_url and determine_ext(video_url, None):
  84. extract_format(video_url)
  85. video_url = self._html_search_regex(
  86. r'flashvars\.video_url\s*=\s*(["\'])(?P<url>http.+?)\1',
  87. webpage, 'video url', default=None, group='url')
  88. if video_url:
  89. extract_format(compat_urllib_parse_unquote(video_url))
  90. if not formats:
  91. if 'title="This video is no longer available"' in webpage:
  92. raise ExtractorError(
  93. 'Video %s is no longer available' % video_id, expected=True)
  94. try:
  95. self._sort_formats(formats)
  96. except ExtractorError:
  97. if fatal:
  98. raise
  99. if not title:
  100. title = self._html_search_regex(
  101. r'<h1[^>]*>([^<]+)', webpage, 'title')
  102. return webpage, {
  103. 'id': video_id,
  104. 'display_id': display_id,
  105. 'title': strip_or_none(title),
  106. 'thumbnail': thumbnail,
  107. 'duration': duration,
  108. 'age_limit': 18,
  109. 'formats': formats,
  110. }
  111. def _real_extract(self, url):
  112. webpage, info = self._extract_info(url, fatal=False)
  113. if not info['formats']:
  114. return self.url_result(url, 'Generic')
  115. info['view_count'] = str_to_int(self._search_regex(
  116. r'<b>([\d,.]+)</b> Views?', webpage, 'view count', fatal=False))
  117. return info