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.

130 lines
4.5 KiB

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