[ie/dplay] Fix extractors (#10471)
[yt-dlp3.git] / yt_dlp / extractor / eporner.py
blob2d25c6b4df24a75659dc814f78c3378c03e53ded
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 encode_base_n,
5 get_elements_by_class,
6 int_or_none,
7 join_nonempty,
8 merge_dicts,
9 parse_duration,
10 str_to_int,
11 url_or_none,
15 class EpornerIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:(?:hd-porn|embed)/|video-)(?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,
32 }, {
33 # New (May 2016) URL layout
34 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0/Star-Wars-XXX-Parody/',
35 'only_matching': True,
36 }, {
37 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
38 'only_matching': True,
39 }, {
40 'url': 'http://www.eporner.com/embed/3YRUtzMcWn0',
41 'only_matching': True,
42 }, {
43 'url': 'https://www.eporner.com/video-FJsA19J3Y3H/one-of-the-greats/',
44 'only_matching': True,
47 def _real_extract(self, url):
48 mobj = self._match_valid_url(url)
49 video_id = mobj.group('id')
50 display_id = mobj.group('display_id') or video_id
52 webpage, urlh = self._download_webpage_handle(url, display_id)
54 video_id = self._match_id(urlh.url)
56 vid_hash = self._search_regex(
57 r'hash\s*[:=]\s*["\']([\da-f]{32})', webpage, 'hash')
59 title = self._og_search_title(webpage, default=None) or self._html_search_regex(
60 r'<title>(.+?) - EPORNER', webpage, 'title')
62 # Reverse engineered from vjs.js
63 def calc_hash(s):
64 return ''.join(encode_base_n(int(s[lb:lb + 8], 16), 36) for lb in range(0, 32, 8))
66 video = self._download_json(
67 f'http://www.eporner.com/xhr/video/{video_id}',
68 display_id, note='Downloading video JSON',
69 query={
70 'hash': calc_hash(vid_hash),
71 'device': 'generic',
72 'domain': 'www.eporner.com',
73 'fallback': 'false',
76 if video.get('available') is False:
77 raise ExtractorError(
78 '{} said: {}'.format(self.IE_NAME, video['message']), expected=True)
80 sources = video['sources']
82 formats = []
83 has_av1 = bool(get_elements_by_class('download-av1', webpage))
84 for kind, formats_dict in sources.items():
85 if not isinstance(formats_dict, dict):
86 continue
87 for format_id, format_dict in formats_dict.items():
88 if not isinstance(format_dict, dict):
89 continue
90 src = url_or_none(format_dict.get('src'))
91 if not src or not src.startswith('http'):
92 continue
93 if kind == 'hls':
94 formats.extend(self._extract_m3u8_formats(
95 src, display_id, 'mp4', entry_protocol='m3u8_native',
96 m3u8_id=kind, fatal=False))
97 else:
98 height = int_or_none(self._search_regex(
99 r'(\d+)[pP]', format_id, 'height', default=None))
100 fps = int_or_none(self._search_regex(
101 r'(\d+)fps', format_id, 'fps', default=None))
103 formats.append({
104 'url': src,
105 'format_id': format_id,
106 'height': height,
107 'fps': fps,
109 if has_av1:
110 formats.append({
111 'url': src.replace('.mp4', '-av1.mp4'),
112 'format_id': join_nonempty('av1', format_id),
113 'height': height,
114 'fps': fps,
115 'vcodec': 'av1',
118 json_ld = self._search_json_ld(webpage, display_id, default={})
120 duration = parse_duration(self._html_search_meta(
121 'duration', webpage, default=None))
122 view_count = str_to_int(self._search_regex(
123 r'id=["\']cinemaviews1["\'][^>]*>\s*([0-9,]+)',
124 webpage, 'view count', default=None))
126 return merge_dicts(json_ld, {
127 'id': video_id,
128 'display_id': display_id,
129 'title': title,
130 'duration': duration,
131 'view_count': view_count,
132 'formats': formats,
133 'age_limit': 18,