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.

128 lines
4.3 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 (
  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': 'http://www.keezmovies.com/video/petite-asian-lady-mai-playing-in-bathtub-1214711',
  20. 'md5': '1c1e75d22ffa53320f45eeb07bc4cdc0',
  21. 'info_dict': {
  22. 'id': '1214711',
  23. 'display_id': 'petite-asian-lady-mai-playing-in-bathtub',
  24. 'ext': 'mp4',
  25. 'title': 'Petite Asian Lady Mai Playing In Bathtub',
  26. 'thumbnail': 're:^https?://.*\.jpg$',
  27. 'view_count': int,
  28. 'age_limit': 18,
  29. }
  30. }, {
  31. 'url': 'http://www.keezmovies.com/video/1214711',
  32. 'only_matching': True,
  33. }]
  34. def _extract_info(self, url):
  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. self._sort_formats(formats)
  95. if not title:
  96. title = self._html_search_regex(
  97. r'<h1[^>]*>([^<]+)', webpage, 'title')
  98. return webpage, {
  99. 'id': video_id,
  100. 'display_id': display_id,
  101. 'title': strip_or_none(title),
  102. 'thumbnail': thumbnail,
  103. 'duration': duration,
  104. 'age_limit': 18,
  105. 'formats': formats,
  106. }
  107. def _real_extract(self, url):
  108. webpage, info = self._extract_info(url)
  109. info['view_count'] = str_to_int(self._search_regex(
  110. r'<b>([\d,.]+)</b> Views?', webpage, 'view count', fatal=False))
  111. return info