2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import (
13 compat_urllib_request
,
15 from .openload
import PhantomJSwrapper
32 class PornHubBaseIE(InfoExtractor
):
33 _NETRC_MACHINE
= 'pornhub'
35 def _download_webpage_handle(self
, *args
, **kwargs
):
36 def dl(*args
, **kwargs
):
37 return super(PornHubBaseIE
, self
)._download
_webpage
_handle
(*args
, **kwargs
)
39 ret
= dl(*args
, **kwargs
)
46 if any(re
.search(p
, webpage
) for p
in (
47 r
'<body\b[^>]+\bonload=["\']go\
(\
)',
48 r'document\
.cookie\s
*=\s
*["\']RNKEY=',
49 r'document\.location\.reload\(true\)')):
50 url_or_request = args[0]
51 url = (url_or_request.get_full_url()
52 if isinstance(url_or_request, compat_urllib_request.Request)
54 phantom = PhantomJSwrapper(self, required_version='2.0')
55 phantom.get(url, html=webpage)
56 webpage, urlh = dl(*args, **kwargs)
60 def _real_initialize(self):
61 self._logged_in = False
63 def _login(self, host):
67 site = host.split('.')[0]
69 # Both sites pornhub and pornhubpremium have separate accounts
70 # so there should be an option to provide credentials for both.
71 # At the same time some videos are available under the same video id
72 # on both sites so that we have to identify them as the same video.
73 # For that purpose we have to keep both in the same extractor
74 # but under different netrc machines.
75 username, password = self._get_login_info(netrc_machine=site)
79 login_url = 'https://www.%s/%slogin' % (host, 'premium/' if 'premium' in host else '')
80 login_page = self._download_webpage(
81 login_url, None, 'Downloading %s login page' % site)
83 def is_logged(webpage):
84 return any(re.search(p, webpage) for p in (
85 r'class=["\']signOut
',
86 r'>Sign\s
+[Oo
]ut\s
*<'))
88 if is_logged(login_page):
89 self._logged_in = True
92 login_form = self._hidden_inputs(login_page)
99 response = self._download_json(
100 'https
://www
.%s/front
/authenticate
' % host, None,
101 'Logging
in to
%s' % site,
102 data=urlencode_postdata(login_form),
104 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
; charset
=UTF
-8',
105 'Referer
': login_url,
106 'X
-Requested
-With
': 'XMLHttpRequest
',
109 if response.get('success
') == '1':
110 self._logged_in = True
113 message = response.get('message
')
114 if message is not None:
115 raise ExtractorError(
116 'Unable to login
: %s' % message, expected=True)
118 raise ExtractorError('Unable to log
in')
121 class PornHubIE(PornHubBaseIE):
122 IE_DESC = 'PornHub
and Thumbzilla
'
123 _VALID_URL = r'''(?x)
126 (?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net|org))/(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
127 (?:www\.)?thumbzilla\.com/video/
132 'url
': 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=648719015',
133 'md5
': 'a6391306d050e4547f62b3f485dd9ba9
',
137 'title
': 'Seductive Indian beauty strips down
and fingers her pink pussy
',
139 'upload_date
': '20130628',
140 'timestamp
': 1372447216,
144 'dislike_count
': int,
145 'comment_count
': int,
153 'url
': 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=1331683002',
158 'upload_date
': '20150213',
159 'timestamp
': 1423804862,
163 'dislike_count
': int,
164 'comment_count
': int,
170 'skip_download
': True,
172 'skip
': 'Video has been flagged
for verification
in accordance
with our trust
and safety policy
',
175 'url
': 'https
://www
.pornhub
.com
/view_video
.php?viewkey
=ph5af5fef7c2aa7
',
177 'id': 'ph5af5fef7c2aa7
',
179 'title
': 'BFFS
- Cute Teen Girls Share Cock On the Floor
',
184 'dislike_count
': int,
185 'comment_count
': int,
196 'skip_download
': True,
198 'skip
': 'This video has been disabled
',
200 'url
': 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=ph557bbb6676d2d
',
201 'only_matching
': True,
203 # removed at the request of cam4.com
204 'url
': 'http
://fr
.pornhub
.com
/view_video
.php?viewkey
=ph55ca2f9760862
',
205 'only_matching
': True,
207 # removed at the request of the copyright owner
208 'url
': 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=788152859',
209 'only_matching
': True,
211 # removed by uploader
212 'url
': 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=ph572716d15a111
',
213 'only_matching
': True,
216 'url
': 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=ph56fd731fce6b7
',
217 'only_matching
': True,
219 'url
': 'https
://www
.thumbzilla
.com
/video
/ph56c6114abd99a
/horny
-girlfriend
-sex
',
220 'only_matching
': True,
222 'url
': 'http
://www
.pornhub
.com
/video
/show?viewkey
=648719015',
223 'only_matching
': True,
225 'url
': 'https
://www
.pornhub
.net
/view_video
.php?viewkey
=203640933',
226 'only_matching
': True,
228 'url
': 'https
://www
.pornhub
.org
/view_video
.php?viewkey
=203640933',
229 'only_matching
': True,
231 'url
': 'https
://www
.pornhubpremium
.com
/view_video
.php?viewkey
=ph5e4acdae54a82
',
232 'only_matching
': True,
234 # Some videos are available with the same id on both premium
235 # and non-premium sites (e.g. this and the following test)
236 'url
': 'https
://www
.pornhub
.com
/view_video
.php?viewkey
=ph5f75b0f4b18e3
',
237 'only_matching
': True,
239 'url
': 'https
://www
.pornhubpremium
.com
/view_video
.php?viewkey
=ph5f75b0f4b18e3
',
240 'only_matching
': True,
244 def _extract_urls(webpage):
246 r'<iframe
[^
>]+?src
=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub(?:premium)?\.(?:com|net|org)/embed/[\da-z]+)',
249 def _extract_count(self, pattern, webpage, name):
250 return str_to_int(self._search_regex(
251 pattern, webpage, '%s count' % name, fatal=False))
253 def _real_extract(self, url):
254 mobj = re.match(self._VALID_URL, url)
255 host = mobj.group('host') or 'pornhub.com'
256 video_id = mobj.group('id')
260 self._set_cookie(host, 'age_verified', '1')
262 def dl_webpage(platform):
263 self._set_cookie(host, 'platform', platform)
264 return self._download_webpage(
265 'https://www.%s/view_video.php?viewkey=%s' % (host, video_id),
266 video_id, 'Downloading %s webpage' % platform)
268 webpage = dl_webpage('pc')
270 error_msg = self._html_search_regex(
271 (r'(?s)<div[^>]+class=(["\'])(?
:(?
!\
1).)*\b(?
:removed|userMessageSection
)\b(?
:(?
!\
1).)*\
1[^
>]*>(?P
<error
>.+?
)</div
>',
272 r'(?s
)<section
[^
>]+class=["\']noVideo["\'][^
>]*>(?P
<error
>.+?
)</section
>'),
273 webpage, 'error message
', default=None, group='error
')
275 error_msg = re.sub(r'\s
+', ' ', error_msg)
276 raise ExtractorError(
277 'PornHub said
: %s' % error_msg,
278 expected=True, video_id=video_id)
280 # video_title from flashvars contains whitespace instead of non-ASCII (see
281 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
283 title = self._html_search_meta(
284 'twitter
:title
', webpage, default=None) or self._html_search_regex(
285 (r'(?s
)<h1
[^
>]+class=["\']title["\'][^
>]*>(?P
<title
>.+?
)</h1
>',
286 r'<div
[^
>]+data
-video
-title
=(["\'])(?P<title>(?:(?!\1).)+)\1',
287 r'shareTitle["\']\s
*[=:]\s
*(["\'])(?P<title>(?:(?!\1).)+)\1'),
288 webpage, 'title', group='title')
291 video_urls_set = set()
294 flashvars = self._parse_json(
296 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
299 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
301 subtitles.setdefault('en', []).append({
305 thumbnail = flashvars.get('image_url')
306 duration = int_or_none(flashvars.get('video_duration'))
307 media_definitions = flashvars.get('mediaDefinitions')
308 if isinstance(media_definitions, list):
309 for definition in media_definitions:
310 if not isinstance(definition, dict):
312 video_url = definition.get('videoUrl')
313 if not video_url or not isinstance(video_url, compat_str):
315 if video_url in video_urls_set:
317 video_urls_set.add(video_url)
319 (video_url, int_or_none(definition.get('quality'))))
321 thumbnail, duration = [None] * 2
323 def extract_js_vars(webpage, pattern, default=NO_DEFAULT):
324 assignments = self._search_regex(
325 pattern, webpage, 'encoded url', default=default)
329 assignments = assignments.split(';')
333 def parse_js_value(inp):
334 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
336 inps = inp.split('+')
337 return functools.reduce(
338 operator.concat, map(parse_js_value, inps))
342 return remove_quotes(inp)
344 for assn in assignments:
348 assn = re.sub(r'var\s+', '', assn)
349 vname, value = assn.split('=', 1)
350 js_vars[vname] = parse_js_value(value)
353 def add_video_url(video_url):
354 v_url = url_or_none(video_url)
357 if v_url in video_urls_set:
359 video_urls.append((v_url, None))
360 video_urls_set.add(v_url)
362 def parse_quality_items(quality_items):
363 q_items = self._parse_json(quality_items, video_id, fatal=False)
364 if not isinstance(q_items, list):
367 if isinstance(item, dict):
368 add_video_url(item.get('url'))
371 FORMAT_PREFIXES = ('media', 'quality', 'qualityItems')
372 js_vars = extract_js_vars(
373 webpage, r'(var\s+(?:%s)_.+)' % '|'.join(FORMAT_PREFIXES),
376 for key, format_url in js_vars.items():
377 if key.startswith(FORMAT_PREFIXES[-1]):
378 parse_quality_items(format_url)
379 elif any(key.startswith(p) for p in FORMAT_PREFIXES[:2]):
380 add_video_url(format_url)
381 if not video_urls and re.search(
382 r'<[^>]+\bid=["\']lockedPlayer
', webpage):
383 raise ExtractorError(
384 'Video
%s is locked
' % video_id, expected=True)
387 js_vars = extract_js_vars(
388 dl_webpage('tv
'), r'(var
.+?mediastring
.+?
)</script
>')
389 add_video_url(js_vars['mediastring
'])
391 for mobj in re.finditer(
392 r'<a
[^
>]+\bclass
=["\']downloadBtn\b[^>]+\bhref=(["\'])(?P
<url
>(?
:(?
!\
1).)+)\
1',
394 video_url = mobj.group('url
')
395 if video_url not in video_urls_set:
396 video_urls.append((video_url, None))
397 video_urls_set.add(video_url)
402 def add_format(format_url, height=None):
403 ext = determine_ext(format_url)
405 formats.extend(self._extract_mpd_formats(
406 format_url, video_id, mpd_id='dash
', fatal=False))
409 formats.extend(self._extract_m3u8_formats(
410 format_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
411 m3u8_id='hls
', fatal=False))
414 mobj = re.search(r'(?P
<height
>\d
+)[pP
]?
_(?P
<tbr
>\d
+)[kK
]', format_url)
417 height = int(mobj.group('height
'))
418 tbr = int(mobj.group('tbr
'))
421 'format_id
': '%dp
' % height if height else None,
426 for video_url, height in video_urls:
428 upload_date = self._search_regex(
429 r'/(\d{6}
/\d{2}
)/', video_url, 'upload data
', default=None)
431 upload_date = upload_date.replace('/', '')
432 if '/video
/get_media
' in video_url:
433 medias = self._download_json(video_url, video_id, fatal=False)
434 if isinstance(medias, list):
436 if not isinstance(media, dict):
438 video_url = url_or_none(media.get('videoUrl
'))
441 height = int_or_none(media.get('quality
'))
442 add_format(video_url, height)
444 add_format(video_url)
445 self._sort_formats(formats)
447 video_uploader = self._html_search_regex(
448 r'(?s
)From
: 
;.+?
<(?
:a
\b[^
>]+\bhref
=["\']/(?:(?:user|channel)s|model|pornstar)/|span\b[^>]+\bclass=["\']username
)[^
>]+>(.+?
)<',
449 webpage, 'uploader
', default=None)
451 def extract_vote_count(kind, name):
452 return self._extract_count(
453 (r'<span
[^
>]+\bclass
="votes%s"[^
>]*>([\d
,\
.]+)</span
>' % kind,
454 r'<span
[^
>]+\bclass
=["\']votes%s["\'][^
>]*\bdata
-rating
=["\'](\d+)' % kind),
457 view_count = self._extract_count(
458 r'<span class="count
">([\d,\.]+)</span> [Vv]iews', webpage, 'view')
459 like_count = extract_vote_count('Up', 'like')
460 dislike_count = extract_vote_count('Down', 'dislike')
461 comment_count = self._extract_count(
462 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
464 def extract_list(meta_key):
465 div = self._search_regex(
466 r'(?s)<div[^>]+\bclass=["\'].*?
\b%sWrapper
[^
>]*>(.+?
)</div
>'
467 % meta_key, webpage, meta_key, default=None)
469 return [clean_html(x).strip() for x in re.findall(r'(?s
)<a
[^
>]+\bhref
=[^
>]+>.+?
</a
>', div)]
471 info = self._search_json_ld(webpage, video_id, default={})
472 # description provided in JSON-LD is irrelevant
473 info['description
'] = None
477 'uploader
': video_uploader,
478 'upload_date
': upload_date,
480 'thumbnail
': thumbnail,
481 'duration
': duration,
482 'view_count
': view_count,
483 'like_count
': like_count,
484 'dislike_count
': dislike_count,
485 'comment_count
': comment_count,
488 'tags
': extract_list('tags
'),
489 'categories
': extract_list('categories
'),
490 'cast
': extract_list('pornstars
'),
491 'subtitles
': subtitles,
495 class PornHubPlaylistBaseIE(PornHubBaseIE):
496 def _extract_page(self, url):
497 return int_or_none(self._search_regex(
498 r'\bpage
=(\d
+)', url, 'page
', default=None))
500 def _extract_entries(self, webpage, host):
501 # Only process container div with main playlist content skipping
502 # drop-down menu that uses similar pattern for videos (see
503 # https://github.com/ytdl-org/youtube-dl/issues/11594).
504 container = self._search_regex(
505 r'(?s
)(<div
[^
>]+class=["\']container.+)', webpage,
506 'container', default=webpage)
510 'http://www.%s/%s' % (host, video_url),
511 PornHubIE.ie_key(), video_title=title)
512 for video_url, title in orderedSet(re.findall(
513 r'href="/?
(view_video\
.php
\?.*\bviewkey
=[\da
-z
]+[^
"]*)"[^
>]*\s
+title
="([^"]+)"',
518 class PornHubUserIE(PornHubPlaylistBaseIE):
519 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net|org))/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/?#&]+))(?:[?#&]|/(?!videos)|$)'
521 'url': 'https://www.pornhub.com/model/zoe_ph',
522 'playlist_mincount': 118,
524 'url': 'https://www.pornhub.com/pornstar/liz-vicious',
528 'playlist_mincount': 118,
530 'url': 'https://www.pornhub.com/users/russianveet69',
531 'only_matching': True,
533 'url': 'https://www.pornhub.com/channels/povd',
534 'only_matching': True,
536 'url': 'https://www.pornhub.com/model/zoe_ph?abc=1',
537 'only_matching': True,
539 # Unavailable via /videos page, but available with direct pagination
540 # on pornstar page (see [1]), requires premium
541 # 1. https://github.com/ytdl-org/youtube-dl/issues/27853
542 'url': 'https://www.pornhubpremium.com/pornstar/sienna-west',
543 'only_matching': True,
545 # Same as before, multi page
546 'url': 'https://www.pornhubpremium.com/pornstar/lily-labeau',
547 'only_matching': True,
550 def _real_extract(self, url):
551 mobj = re.match(self._VALID_URL, url)
552 user_id = mobj.group('id')
553 videos_url = '%s/videos' % mobj.group('url')
554 page = self._extract_page(url)
556 videos_url = update_url_query(videos_url, {'page': page})
557 return self.url_result(
558 videos_url, ie=PornHubPagedVideoListIE.ie_key(), video_id=user_id)
561 class PornHubPagedPlaylistBaseIE(PornHubPlaylistBaseIE):
563 def _has_more(webpage):
566 <li[^>]+\bclass=["\']page_next|
567 <link
[^
>]+\brel
=["\']next|
568 <button[^>]+\bid=["\']moreDataBtn
569 ''', webpage) is not None
571 def _entries(self, url, host, item_id):
572 page = self._extract_page(url)
576 def download_page(base_url, num, fallback=False):
577 note = 'Downloading page %d%s' % (num, ' (switch to fallback)' if fallback else '')
578 return self._download_webpage(
579 base_url, item_id, note, query={'page': num})
582 return isinstance(e.cause, compat_HTTPError) and e.cause.code == 404
585 has_page = page is not None
586 first_page = page if has_page else 1
587 for page_num in (first_page, ) if has_page else itertools.count(first_page):
590 webpage = download_page(base_url, page_num)
591 except ExtractorError as e:
592 # Some sources may not be available via /videos page,
593 # trying to fallback to main page pagination (see [1])
594 # 1. https://github.com/ytdl-org/youtube-dl/issues/27853
595 if is_404(e) and page_num == first_page and VIDEOS in base_url:
596 base_url = base_url.replace(VIDEOS, '')
597 webpage = download_page(base_url, page_num, fallback=True)
600 except ExtractorError as e:
601 if is_404(e) and page_num != first_page:
604 page_entries = self._extract_entries(webpage, host)
607 for e in page_entries:
609 if not self._has_more(webpage):
612 def _real_extract(self, url):
613 mobj = re.match(self._VALID_URL, url)
614 host = mobj.group('host')
615 item_id = mobj.group('id')
619 return self.playlist_result(self._entries(url, host, item_id), item_id)
622 class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
623 _VALID_URL = r'https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net|org))/(?P<id>(?:[^/]+/)*[^/?#&]+)'
625 'url': 'https://www.pornhub.com/model/zoe_ph/videos',
626 'only_matching': True,
628 'url': 'http://www.pornhub.com/users/rushandlia/videos',
629 'only_matching': True,
631 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos',
633 'id': 'pornstar/jenny-blighe/videos',
635 'playlist_mincount': 149,
637 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos?page=3',
639 'id': 'pornstar/jenny-blighe/videos',
641 'playlist_mincount': 40,
643 # default sorting as Top Rated Videos
644 'url': 'https://www.pornhub.com/channels/povd/videos',
646 'id': 'channels/povd/videos',
648 'playlist_mincount': 293,
651 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
652 'only_matching': True,
655 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
656 'only_matching': True,
659 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
660 'only_matching': True,
662 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
663 'only_matching': True,
666 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=mv',
667 'only_matching': True,
670 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=tr',
671 'only_matching': True,
674 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=lg',
675 'only_matching': True,
678 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=cm',
679 'only_matching': True,
681 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/paid',
682 'only_matching': True,
684 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/fanonly',
685 'only_matching': True,
687 'url': 'https://www.pornhub.com/video',
688 'only_matching': True,
690 'url': 'https://www.pornhub.com/video?page=3',
691 'only_matching': True,
693 'url': 'https://www.pornhub.com/video/search?search=123',
694 'only_matching': True,
696 'url': 'https://www.pornhub.com/categories/teen',
697 'only_matching': True,
699 'url': 'https://www.pornhub.com/categories/teen?page=3',
700 'only_matching': True,
702 'url': 'https://www.pornhub.com/hd',
703 'only_matching': True,
705 'url': 'https://www.pornhub.com/hd?page=3',
706 'only_matching': True,
708 'url': 'https://www.pornhub.com/described-video',
709 'only_matching': True,
711 'url': 'https://www.pornhub.com/described-video?page=2',
712 'only_matching': True,
714 'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
715 'only_matching': True,
717 'url': 'https://www.pornhub.com/playlist/44121572',
719 'id': 'playlist/44121572',
721 'playlist_mincount': 132,
723 'url': 'https://www.pornhub.com/playlist/4667351',
724 'only_matching': True,
726 'url': 'https://de.pornhub.com/playlist/4667351',
727 'only_matching': True,
731 def suitable(cls, url):
733 if PornHubIE.suitable(url) or PornHubUserIE.suitable(url) or PornHubUserVideosUploadIE.suitable(url)
734 else super(PornHubPagedVideoListIE, cls).suitable(url))
737 class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
738 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net|org))/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)'
740 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
742 'id': 'jenny-blighe',
744 'playlist_mincount': 129,
746 'url': 'https://www.pornhub.com/model/zoe_ph/videos/upload',
747 'only_matching': True,