]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/eporner.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / eporner.py
CommitLineData
1d57b252 1from .common import InfoExtractor
48d4681e 2from ..utils import (
b13647cf
S
3 encode_base_n,
4 ExtractorError,
5 int_or_none,
96dbf70d 6 merge_dicts,
48d4681e
PH
7 parse_duration,
8 str_to_int,
3052a30d 9 url_or_none,
48d4681e
PH
10)
11
1d57b252 12
13class EpornerIE(InfoExtractor):
29f7c58a 14 _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:(?:hd-porn|embed)/|video-)(?P<id>\w+)(?:/(?P<display_id>[\w-]+))?'
4ee0b8af 15 _TESTS = [{
1d57b252 16 'url': 'http://www.eporner.com/hd-porn/95008/Infamous-Tiffany-Teen-Strip-Tease-Video/',
8c23945c 17 'md5': '39d486f046212d8e1b911c52ab4691f8',
1d57b252 18 'info_dict': {
b13647cf 19 'id': 'qlDUmNsj6VS',
a7862a1b 20 'display_id': 'Infamous-Tiffany-Teen-Strip-Tease-Video',
8c23945c 21 'ext': 'mp4',
1d57b252 22 'title': 'Infamous Tiffany Teen Strip Tease Video',
96dbf70d
S
23 'description': 'md5:764f39abf932daafa37485eb46efa152',
24 'timestamp': 1232520922,
25 'upload_date': '20090121',
6a68bb57 26 'duration': 1838,
48d4681e 27 'view_count': int,
563f6dea 28 'age_limit': 18,
4ee0b8af 29 },
96dbf70d
S
30 'params': {
31 'proxy': '127.0.0.1:8118'
32 }
6f748df4
S
33 }, {
34 # New (May 2016) URL layout
4ee0b8af 35 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0/Star-Wars-XXX-Parody/',
6f748df4 36 'only_matching': True,
b13647cf
S
37 }, {
38 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
acc4ea62
S
39 'only_matching': True,
40 }, {
29f7c58a 41 'url': 'http://www.eporner.com/embed/3YRUtzMcWn0',
42 'only_matching': True,
43 }, {
44 'url': 'https://www.eporner.com/video-FJsA19J3Y3H/one-of-the-greats/',
b13647cf 45 'only_matching': True,
4ee0b8af 46 }]
1d57b252 47
48 def _real_extract(self, url):
5ad28e7f 49 mobj = self._match_valid_url(url)
1d57b252 50 video_id = mobj.group('id')
b13647cf
S
51 display_id = mobj.group('display_id') or video_id
52
53 webpage, urlh = self._download_webpage_handle(url, display_id)
54
7947a1f7 55 video_id = self._match_id(urlh.geturl())
a7862a1b 56
b13647cf 57 hash = self._search_regex(
29f7c58a 58 r'hash\s*[:=]\s*["\']([\da-f]{32})', webpage, 'hash')
1d57b252 59
b13647cf
S
60 title = self._og_search_title(webpage, default=None) or self._html_search_regex(
61 r'<title>(.+?) - EPORNER', webpage, 'title')
a7862a1b 62
b13647cf
S
63 # Reverse engineered from vjs.js
64 def calc_hash(s):
65 return ''.join((encode_base_n(int(s[lb:lb + 8], 16), 36) for lb in range(0, 32, 8)))
66
67 video = self._download_json(
68 'http://www.eporner.com/xhr/video/%s' % video_id,
69 display_id, note='Downloading video JSON',
70 query={
71 'hash': calc_hash(hash),
72 'device': 'generic',
73 'domain': 'www.eporner.com',
74 'fallback': 'false',
75 })
76
77 if video.get('available') is False:
78 raise ExtractorError(
79 '%s said: %s' % (self.IE_NAME, video['message']), expected=True)
80
81 sources = video['sources']
a7862a1b
S
82
83 formats = []
b13647cf
S
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
3052a30d
S
90 src = url_or_none(format_dict.get('src'))
91 if not src or not src.startswith('http'):
b13647cf
S
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))
102
103 formats.append({
104 'url': src,
105 'format_id': format_id,
106 'height': height,
107 'fps': fps,
108 })
1d57b252 109
96dbf70d
S
110 json_ld = self._search_json_ld(webpage, display_id, default={})
111
112 duration = parse_duration(self._html_search_meta(
113 'duration', webpage, default=None))
48d4681e 114 view_count = str_to_int(self._search_regex(
29f7c58a 115 r'id=["\']cinemaviews1["\'][^>]*>\s*([0-9,]+)',
116 webpage, 'view count', default=None))
1d57b252 117
96dbf70d 118 return merge_dicts(json_ld, {
1d57b252 119 'id': video_id,
a7862a1b 120 'display_id': display_id,
1d57b252 121 'title': title,
48d4681e
PH
122 'duration': duration,
123 'view_count': view_count,
a7862a1b 124 'formats': formats,
37f88565 125 'age_limit': 18,
96dbf70d 126 })