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.

129 lines
4.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. encode_base_n,
  7. ExtractorError,
  8. int_or_none,
  9. merge_dicts,
  10. parse_duration,
  11. str_to_int,
  12. url_or_none,
  13. )
  14. class EpornerIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:hd-porn|embed)/(?P<id>\w+)(?:/(?P<display_id>[\w-]+))?'
  16. _TESTS = [{
  17. 'url': 'http://www.eporner.com/hd-porn/95008/Infamous-Tiffany-Teen-Strip-Tease-Video/',
  18. 'md5': '39d486f046212d8e1b911c52ab4691f8',
  19. 'info_dict': {
  20. 'id': 'qlDUmNsj6VS',
  21. 'display_id': 'Infamous-Tiffany-Teen-Strip-Tease-Video',
  22. 'ext': 'mp4',
  23. 'title': 'Infamous Tiffany Teen Strip Tease Video',
  24. 'description': 'md5:764f39abf932daafa37485eb46efa152',
  25. 'timestamp': 1232520922,
  26. 'upload_date': '20090121',
  27. 'duration': 1838,
  28. 'view_count': int,
  29. 'age_limit': 18,
  30. },
  31. 'params': {
  32. 'proxy': '127.0.0.1:8118'
  33. }
  34. }, {
  35. # New (May 2016) URL layout
  36. 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0/Star-Wars-XXX-Parody/',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
  43. 'only_matching': True,
  44. }]
  45. def _real_extract(self, url):
  46. mobj = re.match(self._VALID_URL, url)
  47. video_id = mobj.group('id')
  48. display_id = mobj.group('display_id') or video_id
  49. webpage, urlh = self._download_webpage_handle(url, display_id)
  50. video_id = self._match_id(urlh.geturl())
  51. hash = self._search_regex(
  52. r'hash\s*:\s*["\']([\da-f]{32})', webpage, 'hash')
  53. title = self._og_search_title(webpage, default=None) or self._html_search_regex(
  54. r'<title>(.+?) - EPORNER', webpage, 'title')
  55. # Reverse engineered from vjs.js
  56. def calc_hash(s):
  57. return ''.join((encode_base_n(int(s[lb:lb + 8], 16), 36) for lb in range(0, 32, 8)))
  58. video = self._download_json(
  59. 'http://www.eporner.com/xhr/video/%s' % video_id,
  60. display_id, note='Downloading video JSON',
  61. query={
  62. 'hash': calc_hash(hash),
  63. 'device': 'generic',
  64. 'domain': 'www.eporner.com',
  65. 'fallback': 'false',
  66. })
  67. if video.get('available') is False:
  68. raise ExtractorError(
  69. '%s said: %s' % (self.IE_NAME, video['message']), expected=True)
  70. sources = video['sources']
  71. formats = []
  72. for kind, formats_dict in sources.items():
  73. if not isinstance(formats_dict, dict):
  74. continue
  75. for format_id, format_dict in formats_dict.items():
  76. if not isinstance(format_dict, dict):
  77. continue
  78. src = url_or_none(format_dict.get('src'))
  79. if not src or not src.startswith('http'):
  80. continue
  81. if kind == 'hls':
  82. formats.extend(self._extract_m3u8_formats(
  83. src, display_id, 'mp4', entry_protocol='m3u8_native',
  84. m3u8_id=kind, fatal=False))
  85. else:
  86. height = int_or_none(self._search_regex(
  87. r'(\d+)[pP]', format_id, 'height', default=None))
  88. fps = int_or_none(self._search_regex(
  89. r'(\d+)fps', format_id, 'fps', default=None))
  90. formats.append({
  91. 'url': src,
  92. 'format_id': format_id,
  93. 'height': height,
  94. 'fps': fps,
  95. })
  96. self._sort_formats(formats)
  97. json_ld = self._search_json_ld(webpage, display_id, default={})
  98. duration = parse_duration(self._html_search_meta(
  99. 'duration', webpage, default=None))
  100. view_count = str_to_int(self._search_regex(
  101. r'id="cinemaviews">\s*([0-9,]+)\s*<small>views',
  102. webpage, 'view count', fatal=False))
  103. return merge_dicts(json_ld, {
  104. 'id': video_id,
  105. 'display_id': display_id,
  106. 'title': title,
  107. 'duration': duration,
  108. 'view_count': view_count,
  109. 'formats': formats,
  110. 'age_limit': 18,
  111. })