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.

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