]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tnaflix.py
[cleanup] Fix infodict returned fields (#8906)
[yt-dlp.git] / yt_dlp / extractor / tnaflix.py
CommitLineData
a79bf783 1import re
2
1dba4a21 3from .common import InfoExtractor
d16154d1 4from ..compat import compat_str
1dba4a21 5from ..utils import (
eb833b7f 6 fix_xml_ampersands,
d16154d1
S
7 float_or_none,
8 int_or_none,
9 parse_duration,
10 str_to_int,
6b18a24e 11 unescapeHTML,
a79bf783 12 url_basename,
d16154d1 13 xpath_text,
1dba4a21 14)
15
eb833b7f 16
d16154d1
S
17class TNAFlixNetworkBaseIE(InfoExtractor):
18 # May be overridden in descendants if necessary
19 _CONFIG_REGEX = [
9b9b3501
S
20 r'flashvars\.config\s*=\s*escape\("(?P<url>[^"]+)"',
21 r'<input[^>]+name="config\d?" value="(?P<url>[^"]+)"',
22 r'config\s*=\s*(["\'])(?P<url>(?:https?:)?//(?:(?!\1).)+)\1',
ed5a637d 23 ]
d16154d1
S
24 _TITLE_REGEX = r'<input[^>]+name="title" value="([^"]+)"'
25 _DESCRIPTION_REGEX = r'<input[^>]+name="description" value="([^"]+)"'
26 _UPLOADER_REGEX = r'<input[^>]+name="username" value="([^"]+)"'
27 _VIEW_COUNT_REGEX = None
28 _COMMENT_COUNT_REGEX = None
29 _AVERAGE_RATING_REGEX = None
30 _CATEGORIES_REGEX = r'<li[^>]*>\s*<span[^>]+class="infoTitle"[^>]*>Categories:</span>\s*<span[^>]+class="listView"[^>]*>(.+?)</span>\s*</li>'
31
32 def _extract_thumbnails(self, flix_xml):
33
34 def get_child(elem, names):
35 for name in names:
36 child = elem.find(name)
37 if child is not None:
38 return child
39
40 timeline = get_child(flix_xml, ['timeline', 'rolloverBarImage'])
41 if timeline is None:
42 return
43
44 pattern_el = get_child(timeline, ['imagePattern', 'pattern'])
45 if pattern_el is None or not pattern_el.text:
46 return
47
48 first_el = get_child(timeline, ['imageFirst', 'first'])
49 last_el = get_child(timeline, ['imageLast', 'last'])
50 if first_el is None or last_el is None:
51 return
52
53 first_text = first_el.text
54 last_text = last_el.text
55 if not first_text.isdigit() or not last_text.isdigit():
56 return
57
58 first = int(first_text)
59 last = int(last_text)
60 if first > last:
61 return
62
63 width = int_or_none(xpath_text(timeline, './imageWidth', 'thumbnail width'))
64 height = int_or_none(xpath_text(timeline, './imageHeight', 'thumbnail height'))
65
66 return [{
67 'url': self._proto_relative_url(pattern_el.text.replace('#', compat_str(i)), 'http:'),
68 'width': width,
69 'height': height,
70 } for i in range(first, last + 1)]
1dba4a21 71
72 def _real_extract(self, url):
5ad28e7f 73 mobj = self._match_valid_url(url)
a79bf783 74 video_id, host = mobj.group('id', 'host')
b7785cf1
S
75 for display_id_key in ('display_id', 'display_id_2'):
76 if display_id_key in mobj.groupdict():
77 display_id = mobj.group(display_id_key)
78 if display_id:
79 break
80 else:
81 display_id = video_id
1dba4a21 82
83 webpage = self._download_webpage(url, display_id)
989f47b6 84 inputs = self._hidden_inputs(webpage)
85 query = {}
1dba4a21 86
a79bf783 87 # check for MovieFap-style config
68f705ca 88 cfg_url = self._proto_relative_url(self._html_search_regex(
9b9b3501
S
89 self._CONFIG_REGEX, webpage, 'flashvars.config', default=None,
90 group='url'), 'http:')
2f2fcf1a
S
91
92 if not cfg_url:
989f47b6 93 cfg_url = inputs.get('config')
94
95 # check for TNAFlix-style config
96 if not cfg_url and inputs.get('vkey') and inputs.get('nkey'):
97 cfg_url = f'http://cdn-fck.{host}.com/{host}/{inputs["vkey"]}.fid'
98 query.update({
99 'key': inputs['nkey'],
100 'VID': video_id,
101 'premium': '1',
102 'vip': '1',
103 'alpha': '',
104 })
a79bf783 105
106 formats, json_ld = [], {}
107
108 # TNAFlix and MovieFap extraction
109 if cfg_url:
110 cfg_xml = self._download_xml(
111 cfg_url, display_id, 'Downloading metadata',
112 transform_source=fix_xml_ampersands, headers={'Referer': url}, query=query)
113
114 def extract_video_url(vl):
115 # Any URL modification now results in HTTP Error 403: Forbidden
116 return unescapeHTML(vl.text)
117
118 video_link = cfg_xml.find('./videoLink')
119 if video_link is not None:
120 formats.append({
121 'url': extract_video_url(video_link),
122 'ext': xpath_text(cfg_xml, './videoConfig/type', 'type', default='flv'),
123 })
124
125 for item in cfg_xml.findall('./quality/item'):
126 video_link = item.find('./videoLink')
127 if video_link is None:
128 continue
129 res = item.find('res')
130 format_id = None if res is None else res.text
131 height = int_or_none(self._search_regex(
132 r'^(\d+)[pP]', format_id, 'height', default=None))
133 formats.append({
134 'url': self._proto_relative_url(extract_video_url(video_link), 'http:'),
135 'format_id': format_id,
136 'height': height,
137 })
138
139 thumbnails = self._extract_thumbnails(cfg_xml) or []
140 thumbnails.append({
141 'url': self._proto_relative_url(xpath_text(cfg_xml, './startThumb', 'thumbnail'), 'http:')
d16154d1
S
142 })
143
a79bf783 144 # check for EMPFlix-style JSON and extract
145 else:
146 player = self._download_json(
147 f'http://www.{host}.com/ajax/video-player/{video_id}', video_id,
148 headers={'Referer': url}).get('html', '')
149 for mobj in re.finditer(r'<source src="(?P<src>[^"]+)"', player):
150 video_url = mobj.group('src')
151 height = self._search_regex(r'-(\d+)p\.', url_basename(video_url), 'height', default=None)
152 formats.append({
153 'url': self._proto_relative_url(video_url, 'http:'),
154 'ext': url_basename(video_url).split('.')[-1],
155 'height': int_or_none(height),
156 'format_id': f'{height}p' if height else url_basename(video_url).split('.')[0],
157 })
158 thumbnail = self._proto_relative_url(self._search_regex(
159 r'data-poster="([^"]+)"', player, 'thumbnail', default=None), 'http:')
160 thumbnails = [{'url': thumbnail}] if thumbnail else None
161 json_ld = self._search_json_ld(webpage, display_id, default={})
d16154d1 162
a79bf783 163 def extract_field(pattern, name):
164 return self._html_search_regex(pattern, webpage, name, default=None) if pattern else None
d16154d1 165
1dba4a21 166 return {
167 'id': video_id,
168 'display_id': display_id,
a79bf783 169 'title': (extract_field(self._TITLE_REGEX, 'title')
170 or self._og_search_title(webpage, default=None)
171 or json_ld.get('title')),
172 'description': extract_field(self._DESCRIPTION_REGEX, 'description') or json_ld.get('description'),
d16154d1 173 'thumbnails': thumbnails,
a79bf783 174 'duration': parse_duration(
175 self._html_search_meta('duration', webpage, 'duration', default=None)) or json_ld.get('duration'),
176 'age_limit': self._rta_search(webpage) or 18,
177 'uploader': extract_field(self._UPLOADER_REGEX, 'uploader') or json_ld.get('uploader'),
178 'view_count': str_to_int(extract_field(self._VIEW_COUNT_REGEX, 'view count')),
179 'comment_count': str_to_int(extract_field(self._COMMENT_COUNT_REGEX, 'comment count')),
180 'average_rating': float_or_none(extract_field(self._AVERAGE_RATING_REGEX, 'average rating')),
181 'categories': list(map(str.strip, (extract_field(self._CATEGORIES_REGEX, 'categories') or '').split(','))),
eb833b7f 182 'formats': formats,
1dba4a21 183 }
d16154d1
S
184
185
d6e9c270 186class TNAFlixNetworkEmbedIE(TNAFlixNetworkBaseIE):
a79bf783 187 _VALID_URL = r'https?://player\.(?P<host>tnaflix|empflix)\.com/video/(?P<id>\d+)'
bfd973ec 188 _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.(?:tna|emp)flix\.com/video/\d+)\1']
d6e9c270 189
d6e9c270
S
190 _TESTS = [{
191 'url': 'https://player.tnaflix.com/video/6538',
192 'info_dict': {
193 'id': '6538',
194 'display_id': '6538',
195 'ext': 'mp4',
a79bf783 196 'title': 'Educational xxx video (G Spot)',
197 'description': 'md5:b4fab8f88a8621c8fabd361a173fe5b8',
ec85ded8 198 'thumbnail': r're:https?://.*\.jpg$',
d6e9c270 199 'age_limit': 18,
a79bf783 200 'duration': 164,
201 'uploader': 'bobwhite39',
202 'categories': list,
d6e9c270
S
203 },
204 'params': {
205 'skip_download': True,
206 },
207 }, {
a79bf783 208 'url': 'http://player.empflix.com/video/33051',
d6e9c270
S
209 'only_matching': True,
210 }]
211
a79bf783 212 def _real_extract(self, url):
213 mobj = self._match_valid_url(url)
214 video_id, host = mobj.group('id', 'host')
215 return self.url_result(f'http://www.{host}.com/category/{video_id}/video{video_id}')
216
d6e9c270 217
8cfbcfab
S
218class TNAEMPFlixBaseIE(TNAFlixNetworkBaseIE):
219 _DESCRIPTION_REGEX = r'(?s)>Description:</[^>]+>(.+?)<'
220 _UPLOADER_REGEX = r'<span>by\s*<a[^>]+\bhref=["\']/profile/[^>]+>([^<]+)<'
221 _CATEGORIES_REGEX = r'(?s)<span[^>]*>Categories:</span>(.+?)</div>'
222
223
224class TNAFlixIE(TNAEMPFlixBaseIE):
a79bf783 225 _VALID_URL = r'https?://(?:www\.)?(?P<host>tnaflix)\.com/[^/]+/(?P<display_id>[^/]+)/video(?P<id>\d+)'
d16154d1 226
b47a7501 227 _TITLE_REGEX = r'<title>(.+?) - (?:TNAFlix Porn Videos|TNAFlix\.com)</title>'
d16154d1
S
228
229 _TESTS = [{
230 # anonymous uploader, no categories
231 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878',
8cfbcfab 232 'md5': '7e569419fe6d69543d01e6be22f5f7c4',
d16154d1
S
233 'info_dict': {
234 'id': '553878',
235 'display_id': 'Carmella-Decesare-striptease',
236 'ext': 'mp4',
237 'title': 'Carmella Decesare - striptease',
ec85ded8 238 'thumbnail': r're:https?://.*\.jpg$',
d16154d1
S
239 'duration': 91,
240 'age_limit': 18,
a79bf783 241 'categories': list,
d16154d1
S
242 }
243 }, {
244 # non-anonymous uploader, categories
245 'url': 'https://www.tnaflix.com/teen-porn/Educational-xxx-video/video6538',
a79bf783 246 'md5': 'add5a9fa7f4da53d3e9d0845ac58f20c',
d16154d1
S
247 'info_dict': {
248 'id': '6538',
249 'display_id': 'Educational-xxx-video',
6b18a24e 250 'ext': 'mp4',
a79bf783 251 'title': 'Educational xxx video (G Spot)',
d16154d1 252 'description': 'md5:b4fab8f88a8621c8fabd361a173fe5b8',
ec85ded8 253 'thumbnail': r're:https?://.*\.jpg$',
d16154d1
S
254 'duration': 164,
255 'age_limit': 18,
256 'uploader': 'bobwhite39',
8cfbcfab 257 'categories': list,
d16154d1
S
258 }
259 }, {
260 'url': 'https://www.tnaflix.com/amateur-porn/bunzHD-Ms.Donk/video358632',
261 'only_matching': True,
262 }]
263
264
8cfbcfab 265class EMPFlixIE(TNAEMPFlixBaseIE):
a79bf783 266 _VALID_URL = r'https?://(?:www\.)?(?P<host>empflix)\.com/(?:videos/(?P<display_id>.+?)-|[^/]+/(?P<display_id_2>[^/]+)/video)(?P<id>[0-9]+)'
d16154d1
S
267
268 _TESTS = [{
a79bf783 269 'url': 'http://www.empflix.com/amateur-porn/Amateur-Finger-Fuck/video33051',
270 'md5': 'd761c7b26601bd14476cd9512f2654fc',
d16154d1
S
271 'info_dict': {
272 'id': '33051',
273 'display_id': 'Amateur-Finger-Fuck',
274 'ext': 'mp4',
275 'title': 'Amateur Finger Fuck',
276 'description': 'Amateur solo finger fucking.',
ec85ded8 277 'thumbnail': r're:https?://.*\.jpg$',
d16154d1
S
278 'duration': 83,
279 'age_limit': 18,
a79bf783 280 'categories': list,
d16154d1
S
281 }
282 }, {
283 'url': 'http://www.empflix.com/videos/[AROMA][ARMD-718]-Aoi-Yoshino-Sawa-25826.html',
284 'only_matching': True,
b7785cf1 285 }, {
a79bf783 286 'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html',
b7785cf1 287 'only_matching': True,
d16154d1
S
288 }]
289
290
291class MovieFapIE(TNAFlixNetworkBaseIE):
a79bf783 292 _VALID_URL = r'https?://(?:www\.)?(?P<host>moviefap)\.com/videos/(?P<id>[0-9a-f]+)/(?P<display_id>[^/]+)\.html'
d16154d1
S
293
294 _VIEW_COUNT_REGEX = r'<br>Views\s*<strong>([\d,.]+)</strong>'
295 _COMMENT_COUNT_REGEX = r'<span[^>]+id="comCount"[^>]*>([\d,.]+)</span>'
296 _AVERAGE_RATING_REGEX = r'Current Rating\s*<br>\s*<strong>([\d.]+)</strong>'
297 _CATEGORIES_REGEX = r'(?s)<div[^>]+id="vid_info"[^>]*>\s*<div[^>]*>.+?</div>(.*?)<br>'
298
299 _TESTS = [{
300 # normal, multi-format video
301 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
302 'md5': '26624b4e2523051b550067d547615906',
303 'info_dict': {
304 'id': 'be9867c9416c19f54a4a',
305 'display_id': 'experienced-milf-amazing-handjob',
306 'ext': 'mp4',
307 'title': 'Experienced MILF Amazing Handjob',
308 'description': 'Experienced MILF giving an Amazing Handjob',
ec85ded8 309 'thumbnail': r're:https?://.*\.jpg$',
d16154d1
S
310 'age_limit': 18,
311 'uploader': 'darvinfred06',
312 'view_count': int,
313 'comment_count': int,
314 'average_rating': float,
315 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing'],
316 }
317 }, {
318 # quirky single-format case where the extension is given as fid, but the video is really an flv
319 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html',
320 'md5': 'fa56683e291fc80635907168a743c9ad',
321 'info_dict': {
322 'id': 'e5da0d3edce5404418f5',
323 'display_id': 'jeune-couple-russe',
324 'ext': 'flv',
325 'title': 'Jeune Couple Russe',
326 'description': 'Amateur',
ec85ded8 327 'thumbnail': r're:https?://.*\.jpg$',
d16154d1
S
328 'age_limit': 18,
329 'uploader': 'whiskeyjar',
330 'view_count': int,
331 'comment_count': int,
332 'average_rating': float,
333 'categories': ['Amateur', 'Teen'],
a79bf783 334 },
335 'skip': 'This video does not exist',
d16154d1 336 }]