logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

eporner.py (4670B)


  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)/|video-)(?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/embed/3YRUtzMcWn0',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'https://www.eporner.com/video-FJsA19J3Y3H/one-of-the-greats/',
  46. 'only_matching': True,
  47. }]
  48. def _real_extract(self, url):
  49. mobj = re.match(self._VALID_URL, url)
  50. video_id = mobj.group('id')
  51. display_id = mobj.group('display_id') or video_id
  52. webpage, urlh = self._download_webpage_handle(url, display_id)
  53. video_id = self._match_id(urlh.geturl())
  54. hash = self._search_regex(
  55. r'hash\s*[:=]\s*["\']([\da-f]{32})', webpage, 'hash')
  56. title = self._og_search_title(webpage, default=None) or self._html_search_regex(
  57. r'<title>(.+?) - EPORNER', webpage, 'title')
  58. # Reverse engineered from vjs.js
  59. def calc_hash(s):
  60. return ''.join((encode_base_n(int(s[lb:lb + 8], 16), 36) for lb in range(0, 32, 8)))
  61. video = self._download_json(
  62. 'http://www.eporner.com/xhr/video/%s' % video_id,
  63. display_id, note='Downloading video JSON',
  64. query={
  65. 'hash': calc_hash(hash),
  66. 'device': 'generic',
  67. 'domain': 'www.eporner.com',
  68. 'fallback': 'false',
  69. })
  70. if video.get('available') is False:
  71. raise ExtractorError(
  72. '%s said: %s' % (self.IE_NAME, video['message']), expected=True)
  73. sources = video['sources']
  74. formats = []
  75. for kind, formats_dict in sources.items():
  76. if not isinstance(formats_dict, dict):
  77. continue
  78. for format_id, format_dict in formats_dict.items():
  79. if not isinstance(format_dict, dict):
  80. continue
  81. src = url_or_none(format_dict.get('src'))
  82. if not src or not src.startswith('http'):
  83. continue
  84. if kind == 'hls':
  85. formats.extend(self._extract_m3u8_formats(
  86. src, display_id, 'mp4', entry_protocol='m3u8_native',
  87. m3u8_id=kind, fatal=False))
  88. else:
  89. height = int_or_none(self._search_regex(
  90. r'(\d+)[pP]', format_id, 'height', default=None))
  91. fps = int_or_none(self._search_regex(
  92. r'(\d+)fps', format_id, 'fps', default=None))
  93. formats.append({
  94. 'url': src,
  95. 'format_id': format_id,
  96. 'height': height,
  97. 'fps': fps,
  98. })
  99. self._sort_formats(formats)
  100. json_ld = self._search_json_ld(webpage, display_id, default={})
  101. duration = parse_duration(self._html_search_meta(
  102. 'duration', webpage, default=None))
  103. view_count = str_to_int(self._search_regex(
  104. r'id=["\']cinemaviews1["\'][^>]*>\s*([0-9,]+)',
  105. webpage, 'view count', default=None))
  106. return merge_dicts(json_ld, {
  107. 'id': video_id,
  108. 'display_id': display_id,
  109. 'title': title,
  110. 'duration': duration,
  111. 'view_count': view_count,
  112. 'formats': formats,
  113. 'age_limit': 18,
  114. })