2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import (
13 compat_urllib_request
,
15 from .openload
import PhantomJSwrapper
29 class PornHubBaseIE(InfoExtractor
):
30 def _download_webpage_handle(self
, *args
, **kwargs
):
31 def dl(*args
, **kwargs
):
32 return super(PornHubBaseIE
, self
)._download
_webpage
_handle
(*args
, **kwargs
)
34 ret
= dl(*args
, **kwargs
)
41 if any(re
.search(p
, webpage
) for p
in (
42 r
'<body\b[^>]+\bonload=["\']go\
(\
)',
43 r'document\
.cookie\s
*=\s
*["\']RNKEY=',
44 r'document\.location\.reload\(true\)')):
45 url_or_request = args[0]
46 url = (url_or_request.get_full_url()
47 if isinstance(url_or_request, compat_urllib_request.Request)
49 phantom = PhantomJSwrapper(self, required_version='2.0')
50 phantom.get(url, html=webpage)
51 webpage, urlh = dl(*args, **kwargs)
56 class PornHubIE(PornHubBaseIE):
57 IE_DESC = 'PornHub and Thumbzilla'
61 (?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net|org))/(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
62 (?:www\.)?thumbzilla\.com/video/
67 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
68 'md5': 'a6391306d050e4547f62b3f485dd9ba9',
72 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
74 'upload_date': '20130628',
75 'timestamp': 1372447216,
87 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
92 'upload_date': '20150213',
93 'timestamp': 1423804862,
104 'skip_download': True,
108 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5af5fef7c2aa7',
110 'id': 'ph5af5fef7c2aa7',
112 'title': 'BFFS - Cute Teen Girls Share Cock On the Floor',
117 'dislike_count': int,
118 'comment_count': int,
129 'skip_download': True,
131 'skip': 'This video has been disabled',
133 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
134 'only_matching': True,
136 # removed at the request of cam4.com
137 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
138 'only_matching': True,
140 # removed at the request of the copyright owner
141 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
142 'only_matching': True,
144 # removed by uploader
145 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
146 'only_matching': True,
149 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
150 'only_matching': True,
152 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
153 'only_matching': True,
155 'url': 'http://www.pornhub.com/video/show?viewkey=648719015',
156 'only_matching': True,
158 'url': 'https://www.pornhub.net/view_video.php?viewkey=203640933',
159 'only_matching': True,
161 'url': 'https://www.pornhub.org/view_video.php?viewkey=203640933',
162 'only_matching': True,
164 'url': 'https://www.pornhubpremium.com/view_video.php?viewkey=ph5e4acdae54a82',
165 'only_matching': True,
169 def _extract_urls(webpage):
171 r'<iframe[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.(?
:com|net|org
)/embed
/[\da
-z
]+)',
174 def _extract_count(self, pattern, webpage, name):
175 return str_to_int(self._search_regex(
176 pattern, webpage, '%s count
' % name, fatal=False))
178 def _real_extract(self, url):
179 mobj = re.match(self._VALID_URL, url)
180 host = mobj.group('host
') or 'pornhub
.com
'
181 video_id = mobj.group('id')
183 if 'premium
' in host:
184 if not self._downloader.params.get('cookiefile
'):
185 raise ExtractorError(
186 'PornHub Premium requires authentication
.'
187 ' You may want to use
--cookies
.',
190 self._set_cookie(host, 'age_verified
', '1')
192 def dl_webpage(platform):
193 self._set_cookie(host, 'platform
', platform)
194 return self._download_webpage(
195 'https
://www
.%s/view_video
.php?viewkey
=%s' % (host, video_id),
196 video_id, 'Downloading
%s webpage
' % platform)
198 webpage = dl_webpage('pc
')
200 error_msg = self._html_search_regex(
201 r'(?s
)<div
[^
>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
202 webpage, 'error message', default=None, group='error')
204 error_msg = re.sub(r'\s+', ' ', error_msg)
205 raise ExtractorError(
206 'PornHub said: %s' % error_msg,
207 expected=True, video_id=video_id)
209 # video_title from flashvars contains whitespace instead of non-ASCII (see
210 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
212 title = self._html_search_meta(
213 'twitter:title', webpage, default=None) or self._html_search_regex(
214 (r'(?s)<h1[^>]+class=["\']title
["\'][^>]*>(?P<title>.+?)</h1>',
215 r'<div[^>]+data-video-title=(["\'])(?P
<title
>(?
:(?
!\
1).)+)\
1',
216 r'shareTitle
["\']\s*[=:]\s*(["\'])(?P
<title
>(?
:(?
!\
1).)+)\
1'),
217 webpage, 'title
', group='title
')
220 video_urls_set = set()
223 flashvars = self._parse_json(
225 r'var\s
+flashvars_\d
+\s
*=\s
*({.+?}
);', webpage, 'flashvars
', default='{}'),
228 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile
'))
230 subtitles.setdefault('en
', []).append({
234 thumbnail = flashvars.get('image_url
')
235 duration = int_or_none(flashvars.get('video_duration
'))
236 media_definitions = flashvars.get('mediaDefinitions
')
237 if isinstance(media_definitions, list):
238 for definition in media_definitions:
239 if not isinstance(definition, dict):
241 video_url = definition.get('videoUrl
')
242 if not video_url or not isinstance(video_url, compat_str):
244 if video_url in video_urls_set:
246 video_urls_set.add(video_url)
248 (video_url, int_or_none(definition.get('quality
'))))
250 thumbnail, duration = [None] * 2
252 def extract_js_vars(webpage, pattern, default=NO_DEFAULT):
253 assignments = self._search_regex(
254 pattern, webpage, 'encoded url
', default=default)
258 assignments = assignments.split(';')
262 def parse_js_value(inp):
263 inp = re.sub(r'/\
*(?
:(?
!\
*/).)*?\
*/', '', inp)
265 inps = inp.split('+')
266 return functools.reduce(
267 operator.concat, map(parse_js_value, inps))
271 return remove_quotes(inp)
273 for assn in assignments:
277 assn = re.sub(r'var\s
+', '', assn)
278 vname, value = assn.split('=', 1)
279 js_vars[vname] = parse_js_value(value)
282 def add_video_url(video_url):
283 v_url = url_or_none(video_url)
286 if v_url in video_urls_set:
288 video_urls.append((v_url, None))
289 video_urls_set.add(v_url)
291 def parse_quality_items(quality_items):
292 q_items = self._parse_json(quality_items, video_id, fatal=False)
293 if not isinstance(q_items, list):
296 if isinstance(item, dict):
297 add_video_url(item.get('url
'))
300 FORMAT_PREFIXES = ('media
', 'quality
', 'qualityItems
')
301 js_vars = extract_js_vars(
302 webpage, r'(var\s
+(?
:%s)_
.+)' % '|
'.join(FORMAT_PREFIXES),
305 for key, format_url in js_vars.items():
306 if key.startswith(FORMAT_PREFIXES[-1]):
307 parse_quality_items(format_url)
308 elif any(key.startswith(p) for p in FORMAT_PREFIXES[:2]):
309 add_video_url(format_url)
310 if not video_urls and re.search(
311 r'<[^
>]+\bid
=["\']lockedPlayer', webpage):
312 raise ExtractorError(
313 'Video %s is locked' % video_id, expected=True)
316 js_vars = extract_js_vars(
317 dl_webpage('tv'), r'(var.+?mediastring.+?)</script>')
318 add_video_url(js_vars['mediastring'])
320 for mobj in re.finditer(
321 r'<a[^>]+\bclass=["\']downloadBtn
\b[^
>]+\bhref
=(["\'])(?P<url>(?:(?!\1).)+)\1',
323 video_url = mobj.group('url')
324 if video_url not in video_urls_set:
325 video_urls.append((video_url, None))
326 video_urls_set.add(video_url)
330 for video_url, height in video_urls:
332 upload_date = self._search_regex(
333 r'/(\d{6}/\d{2})/', video_url, 'upload data', default=None)
335 upload_date = upload_date.replace('/', '')
336 ext = determine_ext(video_url)
338 formats.extend(self._extract_mpd_formats(
339 video_url, video_id, mpd_id='dash', fatal=False))
342 formats.extend(self._extract_m3u8_formats(
343 video_url, video_id, 'mp4', entry_protocol='m3u8_native',
344 m3u8_id='hls', fatal=False))
347 mobj = re.search(r'(?P<height>\d+)[pP]?_(?P<tbr>\d+)[kK]', video_url)
350 height = int(mobj.group('height'))
351 tbr = int(mobj.group('tbr'))
354 'format_id': '%dp' % height if height else None,
358 self._sort_formats(formats)
360 video_uploader = self._html_search_regex(
361 r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?
:(?
:user|channel
)s|model|pornstar
)/|span
\b[^
>]+\bclass
=["\']username)[^>]+>(.+?)<',
362 webpage, 'uploader', default=None)
364 def extract_vote_count(kind, name):
365 return self._extract_count(
366 (r'<span[^>]+\bclass="votes
%s"[^>]*>([\d,\.]+)</span>' % kind,
367 r'<span[^>]+\bclass=["\']votes
%s["\'][^>]*\bdata-rating=["\'](\d
+)' % kind),
370 view_count = self._extract_count(
371 r'<span
class="count">([\d
,\
.]+)</span
> [Vv
]iews
', webpage, 'view
')
372 like_count = extract_vote_count('Up
', 'like
')
373 dislike_count = extract_vote_count('Down
', 'dislike
')
374 comment_count = self._extract_count(
375 r'All Comments\s
*<span
>\
(([\d
,.]+)\
)', webpage, 'comment
')
377 def extract_list(meta_key):
378 div = self._search_regex(
379 r'(?s
)<div
[^
>]+\bclass
=["\'].*?\b%sWrapper[^>]*>(.+?)</div>'
380 % meta_key, webpage, meta_key, default=None)
382 return re.findall(r'<a[^>]+\bhref=[^>]+>([^<]+)', div)
384 info = self._search_json_ld(webpage, video_id, default={})
385 # description provided in JSON-LD is irrelevant
386 info['description'] = None
390 'uploader': video_uploader,
391 'upload_date': upload_date,
393 'thumbnail': thumbnail,
394 'duration': duration,
395 'view_count': view_count,
396 'like_count': like_count,
397 'dislike_count': dislike_count,
398 'comment_count': comment_count,
401 'tags': extract_list('tags'),
402 'categories': extract_list('categories'),
403 'subtitles': subtitles,
407 class PornHubPlaylistBaseIE(PornHubBaseIE):
408 def _extract_entries(self, webpage, host):
409 # Only process container div with main playlist content skipping
410 # drop-down menu that uses similar pattern for videos (see
411 # https://github.com/ytdl-org/youtube-dl/issues/11594).
412 container = self._search_regex(
413 r'(?s)(<div[^>]+class=["\']container
.+)', webpage,
414 'container
', default=webpage)
418 'http
://www
.%s/%s' % (host, video_url),
419 PornHubIE.ie_key(), video_title=title)
420 for video_url, title in orderedSet(re.findall(
421 r'href
="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^
"]+)"',
425 def _real_extract(self, url):
426 mobj = re.match(self._VALID_URL, url)
427 host = mobj.group('host
')
428 playlist_id = mobj.group('id')
430 webpage = self._download_webpage(url, playlist_id)
432 entries = self._extract_entries(webpage, host)
434 playlist = self._parse_json(
436 r'(?
:playlistObject|PLAYLIST_VIEW
)\s
*=\s
*({.+?}
);', webpage,
437 'playlist
', default='{}'),
438 playlist_id, fatal=False)
439 title = playlist.get('title
') or self._search_regex(
440 r'>Videos\s
+in\s
+(.+?
)\s
+[Pp
]laylist
<', webpage, 'title
', fatal=False)
442 return self.playlist_result(
443 entries, playlist_id, title, playlist.get('description
'))
446 class PornHubUserIE(PornHubPlaylistBaseIE):
447 _VALID_URL = r'(?P
<url
>https?
://(?
:[^
/]+\
.)?
(?P
<host
>pornhub(?
:premium
)?\
.(?
:com|net|org
))/(?
:(?
:user|channel
)s|model|pornstar
)/(?P
<id>[^
/?
#&]+))(?:[?#&]|/(?!videos)|$)'
449 'url': 'https://www.pornhub.com/model/zoe_ph',
450 'playlist_mincount': 118,
452 'url': 'https://www.pornhub.com/pornstar/liz-vicious',
456 'playlist_mincount': 118,
458 'url': 'https://www.pornhub.com/users/russianveet69',
459 'only_matching': True,
461 'url': 'https://www.pornhub.com/channels/povd',
462 'only_matching': True,
464 'url': 'https://www.pornhub.com/model/zoe_ph?abc=1',
465 'only_matching': True,
468 def _real_extract(self
, url
):
469 mobj
= re
.match(self
._VALID
_URL
, url
)
470 user_id
= mobj
.group('id')
471 return self
.url_result(
472 '%s/videos' % mobj
.group('url'), ie
=PornHubPagedVideoListIE
.ie_key(),
476 class PornHubPagedPlaylistBaseIE(PornHubPlaylistBaseIE
):
478 def _has_more(webpage
):
481 <li[^>]+\bclass=["\']page_next|
482 <link
[^
>]+\brel
=["\']next|
483 <button[^>]+\bid=["\']moreDataBtn
484 ''', webpage) is not None
486 def _real_extract(self, url):
487 mobj = re.match(self._VALID_URL, url)
488 host = mobj.group('host')
489 item_id = mobj.group('id')
491 page = int_or_none(self._search_regex(
492 r'\bpage=(\d+)', url, 'page', default=None))
495 for page_num in (page, ) if page is not None else itertools.count(1):
497 webpage = self._download_webpage(
498 url, item_id, 'Downloading page %d' % page_num,
499 query={'page': page_num})
500 except ExtractorError as e:
501 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
504 page_entries = self._extract_entries(webpage, host)
507 entries.extend(page_entries)
508 if not self._has_more(webpage):
511 return self.playlist_result(orderedSet(entries), item_id)
514 class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
515 _VALID_URL = r'https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net|org))/(?P<id>(?:[^/]+/)*[^/?#&]+)'
517 'url': 'https://www.pornhub.com/model/zoe_ph/videos',
518 'only_matching': True,
520 'url': 'http://www.pornhub.com/users/rushandlia/videos',
521 'only_matching': True,
523 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos',
525 'id': 'pornstar/jenny-blighe/videos',
527 'playlist_mincount': 149,
529 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos?page=3',
531 'id': 'pornstar/jenny-blighe/videos',
533 'playlist_mincount': 40,
535 # default sorting as Top Rated Videos
536 'url': 'https://www.pornhub.com/channels/povd/videos',
538 'id': 'channels/povd/videos',
540 'playlist_mincount': 293,
543 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
544 'only_matching': True,
547 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
548 'only_matching': True,
551 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
552 'only_matching': True,
554 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
555 'only_matching': True,
558 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=mv',
559 'only_matching': True,
562 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=tr',
563 'only_matching': True,
566 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=lg',
567 'only_matching': True,
570 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=cm',
571 'only_matching': True,
573 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/paid',
574 'only_matching': True,
576 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/fanonly',
577 'only_matching': True,
579 'url': 'https://www.pornhub.com/video',
580 'only_matching': True,
582 'url': 'https://www.pornhub.com/video?page=3',
583 'only_matching': True,
585 'url': 'https://www.pornhub.com/video/search?search=123',
586 'only_matching': True,
588 'url': 'https://www.pornhub.com/categories/teen',
589 'only_matching': True,
591 'url': 'https://www.pornhub.com/categories/teen?page=3',
592 'only_matching': True,
594 'url': 'https://www.pornhub.com/hd',
595 'only_matching': True,
597 'url': 'https://www.pornhub.com/hd?page=3',
598 'only_matching': True,
600 'url': 'https://www.pornhub.com/described-video',
601 'only_matching': True,
603 'url': 'https://www.pornhub.com/described-video?page=2',
604 'only_matching': True,
606 'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
607 'only_matching': True,
609 'url': 'https://www.pornhub.com/playlist/44121572',
611 'id': 'playlist/44121572',
613 'playlist_mincount': 132,
615 'url': 'https://www.pornhub.com/playlist/4667351',
616 'only_matching': True,
618 'url': 'https://de.pornhub.com/playlist/4667351',
619 'only_matching': True,
623 def suitable(cls, url):
625 if PornHubIE.suitable(url) or PornHubUserIE.suitable(url) or PornHubUserVideosUploadIE.suitable(url)
626 else super(PornHubPagedVideoListIE, cls).suitable(url))
629 class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
630 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net|org))/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)'
632 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
634 'id': 'jenny-blighe',
636 'playlist_mincount': 129,
638 'url': 'https://www.pornhub.com/model/zoe_ph/videos/upload',
639 'only_matching': True,