]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/pornhub.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / pornhub.py
1 import functools
2 import itertools
3 import math
4 import operator
5 import re
6 import urllib.request
7
8 from .common import InfoExtractor
9 from .openload import PhantomJSwrapper
10 from ..compat import compat_HTTPError, compat_str
11 from ..utils import (
12 NO_DEFAULT,
13 ExtractorError,
14 clean_html,
15 determine_ext,
16 format_field,
17 int_or_none,
18 merge_dicts,
19 orderedSet,
20 remove_quotes,
21 remove_start,
22 str_to_int,
23 update_url_query,
24 url_or_none,
25 urlencode_postdata,
26 )
27
28
29 class PornHubBaseIE(InfoExtractor):
30 _NETRC_MACHINE = 'pornhub'
31 _PORNHUB_HOST_RE = r'(?:(?P<host>pornhub(?:premium)?\.(?:com|net|org))|pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd\.onion)'
32
33 def _download_webpage_handle(self, *args, **kwargs):
34 def dl(*args, **kwargs):
35 return super(PornHubBaseIE, self)._download_webpage_handle(*args, **kwargs)
36
37 ret = dl(*args, **kwargs)
38
39 if not ret:
40 return ret
41
42 webpage, urlh = ret
43
44 if any(re.search(p, webpage) for p in (
45 r'<body\b[^>]+\bonload=["\']go\(\)',
46 r'document\.cookie\s*=\s*["\']RNKEY=',
47 r'document\.location\.reload\(true\)')):
48 url_or_request = args[0]
49 url = (url_or_request.get_full_url()
50 if isinstance(url_or_request, urllib.request.Request)
51 else url_or_request)
52 phantom = PhantomJSwrapper(self, required_version='2.0')
53 phantom.get(url, html=webpage)
54 webpage, urlh = dl(*args, **kwargs)
55
56 return webpage, urlh
57
58 def _real_initialize(self):
59 self._logged_in = False
60
61 def _login(self, host):
62 if self._logged_in:
63 return
64
65 site = host.split('.')[0]
66
67 # Both sites pornhub and pornhubpremium have separate accounts
68 # so there should be an option to provide credentials for both.
69 # At the same time some videos are available under the same video id
70 # on both sites so that we have to identify them as the same video.
71 # For that purpose we have to keep both in the same extractor
72 # but under different netrc machines.
73 username, password = self._get_login_info(netrc_machine=site)
74 if username is None:
75 return
76
77 login_url = 'https://www.%s/%slogin' % (host, 'premium/' if 'premium' in host else '')
78 login_page = self._download_webpage(
79 login_url, None, 'Downloading %s login page' % site)
80
81 def is_logged(webpage):
82 return any(re.search(p, webpage) for p in (
83 r'class=["\']signOut',
84 r'>Sign\s+[Oo]ut\s*<'))
85
86 if is_logged(login_page):
87 self._logged_in = True
88 return
89
90 login_form = self._hidden_inputs(login_page)
91
92 login_form.update({
93 'username': username,
94 'password': password,
95 })
96
97 response = self._download_json(
98 'https://www.%s/front/authenticate' % host, None,
99 'Logging in to %s' % site,
100 data=urlencode_postdata(login_form),
101 headers={
102 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
103 'Referer': login_url,
104 'X-Requested-With': 'XMLHttpRequest',
105 })
106
107 if response.get('success') == '1':
108 self._logged_in = True
109 return
110
111 message = response.get('message')
112 if message is not None:
113 raise ExtractorError(
114 'Unable to login: %s' % message, expected=True)
115
116 raise ExtractorError('Unable to log in')
117
118
119 class PornHubIE(PornHubBaseIE):
120 IE_DESC = 'PornHub and Thumbzilla'
121 _VALID_URL = r'''(?x)
122 https?://
123 (?:
124 (?:[^/]+\.)?
125 %s
126 /(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
127 (?:www\.)?thumbzilla\.com/video/
128 )
129 (?P<id>[\da-z]+)
130 ''' % PornHubBaseIE._PORNHUB_HOST_RE
131 _EMBED_REGEX = [r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub(?:premium)?\.(?:com|net|org)/embed/[\da-z]+)']
132 _TESTS = [{
133 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
134 'md5': 'a6391306d050e4547f62b3f485dd9ba9',
135 'info_dict': {
136 'id': '648719015',
137 'ext': 'mp4',
138 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
139 'uploader': 'Babes',
140 'upload_date': '20130628',
141 'timestamp': 1372447216,
142 'duration': 361,
143 'view_count': int,
144 'like_count': int,
145 'dislike_count': int,
146 'comment_count': int,
147 'age_limit': 18,
148 'tags': list,
149 'categories': list,
150 'cast': list,
151 },
152 }, {
153 # non-ASCII title
154 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
155 'info_dict': {
156 'id': '1331683002',
157 'ext': 'mp4',
158 'title': '重庆婷婷女王足交',
159 'upload_date': '20150213',
160 'timestamp': 1423804862,
161 'duration': 1753,
162 'view_count': int,
163 'like_count': int,
164 'dislike_count': int,
165 'comment_count': int,
166 'age_limit': 18,
167 'tags': list,
168 'categories': list,
169 },
170 'params': {
171 'skip_download': True,
172 },
173 'skip': 'Video has been flagged for verification in accordance with our trust and safety policy',
174 }, {
175 # subtitles
176 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5af5fef7c2aa7',
177 'info_dict': {
178 'id': 'ph5af5fef7c2aa7',
179 'ext': 'mp4',
180 'title': 'BFFS - Cute Teen Girls Share Cock On the Floor',
181 'uploader': 'BFFs',
182 'duration': 622,
183 'view_count': int,
184 'like_count': int,
185 'dislike_count': int,
186 'comment_count': int,
187 'age_limit': 18,
188 'tags': list,
189 'categories': list,
190 'subtitles': {
191 'en': [{
192 "ext": 'srt'
193 }]
194 },
195 },
196 'params': {
197 'skip_download': True,
198 },
199 'skip': 'This video has been disabled',
200 }, {
201 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph601dc30bae19a',
202 'info_dict': {
203 'id': 'ph601dc30bae19a',
204 'uploader': 'Projekt Melody',
205 'uploader_id': 'projekt-melody',
206 'upload_date': '20210205',
207 'title': '"Welcome to My Pussy Mansion" - CB Stream (02/03/21)',
208 'thumbnail': r're:https?://.+',
209 },
210 }, {
211 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
212 'only_matching': True,
213 }, {
214 # removed at the request of cam4.com
215 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
216 'only_matching': True,
217 }, {
218 # removed at the request of the copyright owner
219 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
220 'only_matching': True,
221 }, {
222 # removed by uploader
223 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
224 'only_matching': True,
225 }, {
226 # private video
227 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
228 'only_matching': True,
229 }, {
230 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
231 'only_matching': True,
232 }, {
233 'url': 'http://www.pornhub.com/video/show?viewkey=648719015',
234 'only_matching': True,
235 }, {
236 'url': 'https://www.pornhub.net/view_video.php?viewkey=203640933',
237 'only_matching': True,
238 }, {
239 'url': 'https://www.pornhub.org/view_video.php?viewkey=203640933',
240 'only_matching': True,
241 }, {
242 'url': 'https://www.pornhubpremium.com/view_video.php?viewkey=ph5e4acdae54a82',
243 'only_matching': True,
244 }, {
245 # Some videos are available with the same id on both premium
246 # and non-premium sites (e.g. this and the following test)
247 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5f75b0f4b18e3',
248 'only_matching': True,
249 }, {
250 'url': 'https://www.pornhubpremium.com/view_video.php?viewkey=ph5f75b0f4b18e3',
251 'only_matching': True,
252 }, {
253 # geo restricted
254 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5a9813bfa7156',
255 'only_matching': True,
256 }, {
257 'url': 'http://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/view_video.php?viewkey=ph5a9813bfa7156',
258 'only_matching': True,
259 }]
260
261 def _extract_count(self, pattern, webpage, name):
262 return str_to_int(self._search_regex(pattern, webpage, '%s count' % name, default=None))
263
264 def _real_extract(self, url):
265 mobj = self._match_valid_url(url)
266 host = mobj.group('host') or 'pornhub.com'
267 video_id = mobj.group('id')
268
269 self._login(host)
270
271 self._set_cookie(host, 'age_verified', '1')
272
273 def dl_webpage(platform):
274 self._set_cookie(host, 'platform', platform)
275 return self._download_webpage(
276 'https://www.%s/view_video.php?viewkey=%s' % (host, video_id),
277 video_id, 'Downloading %s webpage' % platform)
278
279 webpage = dl_webpage('pc')
280
281 error_msg = self._html_search_regex(
282 (r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
283 r'(?s)<section[^>]+class=["\']noVideo["\'][^>]*>(?P<error>.+?)</section>'),
284 webpage, 'error message', default=None, group='error')
285 if error_msg:
286 error_msg = re.sub(r'\s+', ' ', error_msg)
287 raise ExtractorError(
288 'PornHub said: %s' % error_msg,
289 expected=True, video_id=video_id)
290
291 if any(re.search(p, webpage) for p in (
292 r'class=["\']geoBlocked["\']',
293 r'>\s*This content is unavailable in your country')):
294 self.raise_geo_restricted()
295
296 # video_title from flashvars contains whitespace instead of non-ASCII (see
297 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
298 # on that anymore.
299 title = self._html_search_meta(
300 'twitter:title', webpage, default=None) or self._html_search_regex(
301 (r'(?s)<h1[^>]+class=["\']title["\'][^>]*>(?P<title>.+?)</h1>',
302 r'<div[^>]+data-video-title=(["\'])(?P<title>(?:(?!\1).)+)\1',
303 r'shareTitle["\']\s*[=:]\s*(["\'])(?P<title>(?:(?!\1).)+)\1'),
304 webpage, 'title', group='title')
305
306 video_urls = []
307 video_urls_set = set()
308 subtitles = {}
309
310 flashvars = self._parse_json(
311 self._search_regex(
312 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
313 video_id)
314 if flashvars:
315 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
316 if subtitle_url:
317 subtitles.setdefault('en', []).append({
318 'url': subtitle_url,
319 'ext': 'srt',
320 })
321 thumbnail = flashvars.get('image_url')
322 duration = int_or_none(flashvars.get('video_duration'))
323 media_definitions = flashvars.get('mediaDefinitions')
324 if isinstance(media_definitions, list):
325 for definition in media_definitions:
326 if not isinstance(definition, dict):
327 continue
328 video_url = definition.get('videoUrl')
329 if not video_url or not isinstance(video_url, compat_str):
330 continue
331 if video_url in video_urls_set:
332 continue
333 video_urls_set.add(video_url)
334 video_urls.append(
335 (video_url, int_or_none(definition.get('quality'))))
336 else:
337 thumbnail, duration = [None] * 2
338
339 def extract_js_vars(webpage, pattern, default=NO_DEFAULT):
340 assignments = self._search_regex(
341 pattern, webpage, 'encoded url', default=default)
342 if not assignments:
343 return {}
344
345 assignments = assignments.split(';')
346
347 js_vars = {}
348
349 def parse_js_value(inp):
350 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
351 if '+' in inp:
352 inps = inp.split('+')
353 return functools.reduce(
354 operator.concat, map(parse_js_value, inps))
355 inp = inp.strip()
356 if inp in js_vars:
357 return js_vars[inp]
358 return remove_quotes(inp)
359
360 for assn in assignments:
361 assn = assn.strip()
362 if not assn:
363 continue
364 assn = re.sub(r'var\s+', '', assn)
365 vname, value = assn.split('=', 1)
366 js_vars[vname] = parse_js_value(value)
367 return js_vars
368
369 def add_video_url(video_url):
370 v_url = url_or_none(video_url)
371 if not v_url:
372 return
373 if v_url in video_urls_set:
374 return
375 video_urls.append((v_url, None))
376 video_urls_set.add(v_url)
377
378 def parse_quality_items(quality_items):
379 q_items = self._parse_json(quality_items, video_id, fatal=False)
380 if not isinstance(q_items, list):
381 return
382 for item in q_items:
383 if isinstance(item, dict):
384 add_video_url(item.get('url'))
385
386 if not video_urls:
387 FORMAT_PREFIXES = ('media', 'quality', 'qualityItems')
388 js_vars = extract_js_vars(
389 webpage, r'(var\s+(?:%s)_.+)' % '|'.join(FORMAT_PREFIXES),
390 default=None)
391 if js_vars:
392 for key, format_url in js_vars.items():
393 if key.startswith(FORMAT_PREFIXES[-1]):
394 parse_quality_items(format_url)
395 elif any(key.startswith(p) for p in FORMAT_PREFIXES[:2]):
396 add_video_url(format_url)
397 if not video_urls and re.search(
398 r'<[^>]+\bid=["\']lockedPlayer', webpage):
399 raise ExtractorError(
400 'Video %s is locked' % video_id, expected=True)
401
402 if not video_urls:
403 js_vars = extract_js_vars(
404 dl_webpage('tv'), r'(var.+?mediastring.+?)</script>')
405 add_video_url(js_vars['mediastring'])
406
407 for mobj in re.finditer(
408 r'<a[^>]+\bclass=["\']downloadBtn\b[^>]+\bhref=(["\'])(?P<url>(?:(?!\1).)+)\1',
409 webpage):
410 video_url = mobj.group('url')
411 if video_url not in video_urls_set:
412 video_urls.append((video_url, None))
413 video_urls_set.add(video_url)
414
415 upload_date = None
416 formats = []
417
418 def add_format(format_url, height=None):
419 ext = determine_ext(format_url)
420 if ext == 'mpd':
421 formats.extend(self._extract_mpd_formats(
422 format_url, video_id, mpd_id='dash', fatal=False))
423 return
424 if ext == 'm3u8':
425 formats.extend(self._extract_m3u8_formats(
426 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
427 m3u8_id='hls', fatal=False))
428 return
429 if not height:
430 height = int_or_none(self._search_regex(
431 r'(?P<height>\d+)[pP]?_\d+[kK]', format_url, 'height',
432 default=None))
433 formats.append({
434 'url': format_url,
435 'format_id': format_field(height, None, '%dp'),
436 'height': height,
437 })
438
439 for video_url, height in video_urls:
440 if not upload_date:
441 upload_date = self._search_regex(
442 r'/(\d{6}/\d{2})/', video_url, 'upload data', default=None)
443 if upload_date:
444 upload_date = upload_date.replace('/', '')
445 if '/video/get_media' in video_url:
446 medias = self._download_json(video_url, video_id, fatal=False)
447 if isinstance(medias, list):
448 for media in medias:
449 if not isinstance(media, dict):
450 continue
451 video_url = url_or_none(media.get('videoUrl'))
452 if not video_url:
453 continue
454 height = int_or_none(media.get('quality'))
455 add_format(video_url, height)
456 continue
457 add_format(video_url)
458
459 model_profile = self._search_json(
460 r'var\s+MODEL_PROFILE\s*=', webpage, 'model profile', video_id, fatal=False)
461 video_uploader = self._html_search_regex(
462 r'(?s)From:&nbsp;.+?<(?:a\b[^>]+\bhref=["\']/(?:(?:user|channel)s|model|pornstar)/|span\b[^>]+\bclass=["\']username)[^>]+>(.+?)<',
463 webpage, 'uploader', default=None) or model_profile.get('username')
464
465 def extract_vote_count(kind, name):
466 return self._extract_count(
467 (r'<span[^>]+\bclass="votes%s"[^>]*>([\d,\.]+)</span>' % kind,
468 r'<span[^>]+\bclass=["\']votes%s["\'][^>]*\bdata-rating=["\'](\d+)' % kind),
469 webpage, name)
470
471 view_count = self._extract_count(
472 r'<span class="count">([\d,\.]+)</span> [Vv]iews', webpage, 'view')
473 like_count = extract_vote_count('Up', 'like')
474 dislike_count = extract_vote_count('Down', 'dislike')
475 comment_count = self._extract_count(
476 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
477
478 def extract_list(meta_key):
479 div = self._search_regex(
480 r'(?s)<div[^>]+\bclass=["\'].*?\b%sWrapper[^>]*>(.+?)</div>'
481 % meta_key, webpage, meta_key, default=None)
482 if div:
483 return [clean_html(x).strip() for x in re.findall(r'(?s)<a[^>]+\bhref=[^>]+>.+?</a>', div)]
484
485 info = self._search_json_ld(webpage, video_id, default={})
486 # description provided in JSON-LD is irrelevant
487 info['description'] = None
488
489 return merge_dicts({
490 'id': video_id,
491 'uploader': video_uploader,
492 'uploader_id': remove_start(model_profile.get('modelProfileLink'), '/model/'),
493 'upload_date': upload_date,
494 'title': title,
495 'thumbnail': thumbnail,
496 'duration': duration,
497 'view_count': view_count,
498 'like_count': like_count,
499 'dislike_count': dislike_count,
500 'comment_count': comment_count,
501 'formats': formats,
502 'age_limit': 18,
503 'tags': extract_list('tags'),
504 'categories': extract_list('categories'),
505 'cast': extract_list('pornstars'),
506 'subtitles': subtitles,
507 }, info)
508
509
510 class PornHubPlaylistBaseIE(PornHubBaseIE):
511 def _extract_page(self, url):
512 return int_or_none(self._search_regex(
513 r'\bpage=(\d+)', url, 'page', default=None))
514
515 def _extract_entries(self, webpage, host):
516 # Only process container div with main playlist content skipping
517 # drop-down menu that uses similar pattern for videos (see
518 # https://github.com/ytdl-org/youtube-dl/issues/11594).
519 container = self._search_regex(
520 r'(?s)(<div[^>]+class=["\']container.+)', webpage,
521 'container', default=webpage)
522
523 return [
524 self.url_result(
525 'http://www.%s/%s' % (host, video_url),
526 PornHubIE.ie_key(), video_title=title)
527 for video_url, title in orderedSet(re.findall(
528 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
529 container))
530 ]
531
532
533 class PornHubUserIE(PornHubPlaylistBaseIE):
534 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?%s/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/?#&]+))(?:[?#&]|/(?!videos)|$)' % PornHubBaseIE._PORNHUB_HOST_RE
535 _TESTS = [{
536 'url': 'https://www.pornhub.com/model/zoe_ph',
537 'playlist_mincount': 118,
538 }, {
539 'url': 'https://www.pornhub.com/pornstar/liz-vicious',
540 'info_dict': {
541 'id': 'liz-vicious',
542 },
543 'playlist_mincount': 118,
544 }, {
545 'url': 'https://www.pornhub.com/users/russianveet69',
546 'only_matching': True,
547 }, {
548 'url': 'https://www.pornhub.com/channels/povd',
549 'only_matching': True,
550 }, {
551 'url': 'https://www.pornhub.com/model/zoe_ph?abc=1',
552 'only_matching': True,
553 }, {
554 # Unavailable via /videos page, but available with direct pagination
555 # on pornstar page (see [1]), requires premium
556 # 1. https://github.com/ytdl-org/youtube-dl/issues/27853
557 'url': 'https://www.pornhubpremium.com/pornstar/sienna-west',
558 'only_matching': True,
559 }, {
560 # Same as before, multi page
561 'url': 'https://www.pornhubpremium.com/pornstar/lily-labeau',
562 'only_matching': True,
563 }, {
564 'url': 'https://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/model/zoe_ph',
565 'only_matching': True,
566 }]
567
568 def _real_extract(self, url):
569 mobj = self._match_valid_url(url)
570 user_id = mobj.group('id')
571 videos_url = '%s/videos' % mobj.group('url')
572 page = self._extract_page(url)
573 if page:
574 videos_url = update_url_query(videos_url, {'page': page})
575 return self.url_result(
576 videos_url, ie=PornHubPagedVideoListIE.ie_key(), video_id=user_id)
577
578
579 class PornHubPagedPlaylistBaseIE(PornHubPlaylistBaseIE):
580 @staticmethod
581 def _has_more(webpage):
582 return re.search(
583 r'''(?x)
584 <li[^>]+\bclass=["\']page_next|
585 <link[^>]+\brel=["\']next|
586 <button[^>]+\bid=["\']moreDataBtn
587 ''', webpage) is not None
588
589 def _entries(self, url, host, item_id):
590 page = self._extract_page(url)
591
592 VIDEOS = '/videos'
593
594 def download_page(base_url, num, fallback=False):
595 note = 'Downloading page %d%s' % (num, ' (switch to fallback)' if fallback else '')
596 return self._download_webpage(
597 base_url, item_id, note, query={'page': num})
598
599 def is_404(e):
600 return isinstance(e.cause, compat_HTTPError) and e.cause.code == 404
601
602 base_url = url
603 has_page = page is not None
604 first_page = page if has_page else 1
605 for page_num in (first_page, ) if has_page else itertools.count(first_page):
606 try:
607 try:
608 webpage = download_page(base_url, page_num)
609 except ExtractorError as e:
610 # Some sources may not be available via /videos page,
611 # trying to fallback to main page pagination (see [1])
612 # 1. https://github.com/ytdl-org/youtube-dl/issues/27853
613 if is_404(e) and page_num == first_page and VIDEOS in base_url:
614 base_url = base_url.replace(VIDEOS, '')
615 webpage = download_page(base_url, page_num, fallback=True)
616 else:
617 raise
618 except ExtractorError as e:
619 if is_404(e) and page_num != first_page:
620 break
621 raise
622 page_entries = self._extract_entries(webpage, host)
623 if not page_entries:
624 break
625 for e in page_entries:
626 yield e
627 if not self._has_more(webpage):
628 break
629
630 def _real_extract(self, url):
631 mobj = self._match_valid_url(url)
632 host = mobj.group('host')
633 item_id = mobj.group('id')
634
635 self._login(host)
636
637 return self.playlist_result(self._entries(url, host, item_id), item_id)
638
639
640 class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
641 _VALID_URL = r'https?://(?:[^/]+\.)?%s/(?!playlist/)(?P<id>(?:[^/]+/)*[^/?#&]+)' % PornHubBaseIE._PORNHUB_HOST_RE
642 _TESTS = [{
643 'url': 'https://www.pornhub.com/model/zoe_ph/videos',
644 'only_matching': True,
645 }, {
646 'url': 'http://www.pornhub.com/users/rushandlia/videos',
647 'only_matching': True,
648 }, {
649 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos',
650 'info_dict': {
651 'id': 'pornstar/jenny-blighe/videos',
652 },
653 'playlist_mincount': 149,
654 }, {
655 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos?page=3',
656 'info_dict': {
657 'id': 'pornstar/jenny-blighe/videos',
658 },
659 'playlist_mincount': 40,
660 }, {
661 # default sorting as Top Rated Videos
662 'url': 'https://www.pornhub.com/channels/povd/videos',
663 'info_dict': {
664 'id': 'channels/povd/videos',
665 },
666 'playlist_mincount': 293,
667 }, {
668 # Top Rated Videos
669 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
670 'only_matching': True,
671 }, {
672 # Most Recent Videos
673 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
674 'only_matching': True,
675 }, {
676 # Most Viewed Videos
677 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
678 'only_matching': True,
679 }, {
680 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
681 'only_matching': True,
682 }, {
683 # Most Viewed Videos
684 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=mv',
685 'only_matching': True,
686 }, {
687 # Top Rated Videos
688 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=tr',
689 'only_matching': True,
690 }, {
691 # Longest Videos
692 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=lg',
693 'only_matching': True,
694 }, {
695 # Newest Videos
696 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=cm',
697 'only_matching': True,
698 }, {
699 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/paid',
700 'only_matching': True,
701 }, {
702 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/fanonly',
703 'only_matching': True,
704 }, {
705 'url': 'https://www.pornhub.com/video',
706 'only_matching': True,
707 }, {
708 'url': 'https://www.pornhub.com/video?page=3',
709 'only_matching': True,
710 }, {
711 'url': 'https://www.pornhub.com/video/search?search=123',
712 'only_matching': True,
713 }, {
714 'url': 'https://www.pornhub.com/categories/teen',
715 'only_matching': True,
716 }, {
717 'url': 'https://www.pornhub.com/categories/teen?page=3',
718 'only_matching': True,
719 }, {
720 'url': 'https://www.pornhub.com/hd',
721 'only_matching': True,
722 }, {
723 'url': 'https://www.pornhub.com/hd?page=3',
724 'only_matching': True,
725 }, {
726 'url': 'https://www.pornhub.com/described-video',
727 'only_matching': True,
728 }, {
729 'url': 'https://www.pornhub.com/described-video?page=2',
730 'only_matching': True,
731 }, {
732 'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
733 'only_matching': True,
734 }, {
735 'url': 'https://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/model/zoe_ph/videos',
736 'only_matching': True,
737 }]
738
739 @classmethod
740 def suitable(cls, url):
741 return (False
742 if PornHubIE.suitable(url) or PornHubUserIE.suitable(url) or PornHubUserVideosUploadIE.suitable(url)
743 else super(PornHubPagedVideoListIE, cls).suitable(url))
744
745
746 class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
747 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?%s/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)' % PornHubBaseIE._PORNHUB_HOST_RE
748 _TESTS = [{
749 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
750 'info_dict': {
751 'id': 'jenny-blighe',
752 },
753 'playlist_mincount': 129,
754 }, {
755 'url': 'https://www.pornhub.com/model/zoe_ph/videos/upload',
756 'only_matching': True,
757 }, {
758 'url': 'http://pornhubvybmsymdol4iibwgwtkpwmeyd6luq2gxajgjzfjvotyt5zhyd.onion/pornstar/jenny-blighe/videos/upload',
759 'only_matching': True,
760 }]
761
762
763 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
764 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?%s/playlist/(?P<id>[^/?#&]+))' % PornHubBaseIE._PORNHUB_HOST_RE
765 _TESTS = [{
766 'url': 'https://www.pornhub.com/playlist/44121572',
767 'info_dict': {
768 'id': '44121572',
769 },
770 'playlist_count': 77,
771 }, {
772 'url': 'https://www.pornhub.com/playlist/4667351',
773 'only_matching': True,
774 }, {
775 'url': 'https://de.pornhub.com/playlist/4667351',
776 'only_matching': True,
777 }, {
778 'url': 'https://de.pornhub.com/playlist/4667351?page=2',
779 'only_matching': True,
780 }]
781
782 def _entries(self, url, host, item_id):
783 webpage = self._download_webpage(url, item_id, 'Downloading page 1')
784 playlist_id = self._search_regex(r'var\s+playlistId\s*=\s*"([^"]+)"', webpage, 'playlist_id')
785 video_count = int_or_none(
786 self._search_regex(r'var\s+itemsCount\s*=\s*([0-9]+)\s*\|\|', webpage, 'video_count'))
787 token = self._search_regex(r'var\s+token\s*=\s*"([^"]+)"', webpage, 'token')
788 page_count = math.ceil((video_count - 36) / 40.) + 1
789 page_entries = self._extract_entries(webpage, host)
790
791 def download_page(page_num):
792 note = 'Downloading page {}'.format(page_num)
793 page_url = 'https://www.{}/playlist/viewChunked'.format(host)
794 return self._download_webpage(page_url, item_id, note, query={
795 'id': playlist_id,
796 'page': page_num,
797 'token': token,
798 })
799
800 for page_num in range(1, page_count + 1):
801 if page_num > 1:
802 webpage = download_page(page_num)
803 page_entries = self._extract_entries(webpage, host)
804 if not page_entries:
805 break
806 for e in page_entries:
807 yield e
808
809 def _real_extract(self, url):
810 mobj = self._match_valid_url(url)
811 host = mobj.group('host')
812 item_id = mobj.group('id')
813
814 self._login(host)
815
816 return self.playlist_result(self._entries(mobj.group('url'), host, item_id), item_id)