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.

133 lines
4.6 KiB

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