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