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