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