2 from __future__ import unicode_literals
9 from .common import InfoExtractor
10 from ..compat import (
13 compat_urllib_request,
15 from .openload import PhantomJSwrapper
28 class PornHubBaseIE(InfoExtractor):
29 def _download_webpage_handle(self, *args, **kwargs):
30 def dl(*args, **kwargs):
31 return super(PornHubBaseIE, self)._download_webpage_handle(*args, **kwargs)
33 webpage, urlh = dl(*args, **kwargs)
35 if any(re.search(p, webpage) for p in (
36 r'<body\b[^>]+\bonload=["\']go\(\)',
37 r'document\.cookie\s*=\s*["\']RNKEY=',
38 r'document\.location\.reload\(true\)')):
39 url_or_request = args[0]
40 url = (url_or_request.get_full_url()
41 if isinstance(url_or_request, compat_urllib_request.Request)
43 phantom = PhantomJSwrapper(self, required_version='2.0')
44 phantom.get(url, html=webpage)
45 webpage, urlh = dl(*args, **kwargs)
50 class PornHubIE(PornHubBaseIE):
51 IE_DESC = 'PornHub and Thumbzilla'
55 (?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net))/(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
56 (?:www\.)?thumbzilla\.com/video/
61 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
62 'md5': '1e19b41231a02eba417839222ac9d58e',
66 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
68 'upload_date': '20130628',
80 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
85 'uploader': 'Unknown',
86 'upload_date': '20150213',
97 'skip_download': True,
101 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5af5fef7c2aa7',
103 'id': 'ph5af5fef7c2aa7',
105 'title': 'BFFS - Cute Teen Girls Share Cock On the Floor',
110 'dislike_count': int,
111 'comment_count': int,
122 'skip_download': True,
125 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
126 'only_matching': True,
128 # removed at the request of cam4.com
129 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
130 'only_matching': True,
132 # removed at the request of the copyright owner
133 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
134 'only_matching': True,
136 # removed by uploader
137 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
138 'only_matching': True,
141 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
142 'only_matching': True,
144 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
145 'only_matching': True,
147 'url': 'http://www.pornhub.com/video/show?viewkey=648719015',
148 'only_matching': True,
150 'url': 'https://www.pornhub.net/view_video.php?viewkey=203640933',
151 'only_matching': True,
153 'url': 'https://www.pornhubpremium.com/view_video.php?viewkey=ph5e4acdae54a82',
154 'only_matching': True,
158 def _extract_urls(webpage):
160 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub\.(?:com|net)/embed/[\da-z]+)',
163 def _extract_count(self, pattern, webpage, name):
164 return str_to_int(self._search_regex(
165 pattern, webpage, '%s count' % name, fatal=False))
167 def _real_extract(self, url):
168 mobj = re.match(self._VALID_URL, url)
169 host = mobj.group('host') or 'pornhub.com'
170 video_id = mobj.group('id')
172 if 'premium' in host:
173 if not self._downloader.params.get('cookiefile'):
174 raise ExtractorError(
175 'PornHub Premium requires authentication.'
176 ' You may want to use --cookies.',
179 self._set_cookie(host, 'age_verified', '1')
181 def dl_webpage(platform):
182 self._set_cookie(host, 'platform', platform)
183 return self._download_webpage(
184 'https://www.%s/view_video.php?viewkey=%s' % (host, video_id),
185 video_id, 'Downloading %s webpage' % platform)
187 webpage = dl_webpage('pc')
189 error_msg = self._html_search_regex(
190 r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
191 webpage, 'error message', default=None, group='error')
193 error_msg = re.sub(r'\s+', ' ', error_msg)
194 raise ExtractorError(
195 'PornHub said: %s' % error_msg,
196 expected=True, video_id=video_id)
198 # video_title from flashvars contains whitespace instead of non-ASCII (see
199 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
201 title = self._html_search_meta(
202 'twitter:title', webpage, default=None) or self._html_search_regex(
203 (r'(?s)<h1[^>]+class=["\']title["\'][^>]*>(?P<title>.+?)</h1>',
204 r'<div[^>]+data-video-title=(["\'])(?P<title>(?:(?!\1).)+)\1',
205 r'shareTitle["\']\s*[=:]\s*(["\'])(?P<title>(?:(?!\1).)+)\1'),
206 webpage, 'title', group='title')
209 video_urls_set = set()
212 flashvars = self._parse_json(
214 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
217 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
219 subtitles.setdefault('en', []).append({
223 thumbnail = flashvars.get('image_url')
224 duration = int_or_none(flashvars.get('video_duration'))
225 media_definitions = flashvars.get('mediaDefinitions')
226 if isinstance(media_definitions, list):
227 for definition in media_definitions:
228 if not isinstance(definition, dict):
230 video_url = definition.get('videoUrl')
231 if not video_url or not isinstance(video_url, compat_str):
233 if video_url in video_urls_set:
235 video_urls_set.add(video_url)
237 (video_url, int_or_none(definition.get('quality'))))
239 thumbnail, duration = [None] * 2
241 def extract_js_vars(webpage, pattern, default=NO_DEFAULT):
242 assignments = self._search_regex(
243 pattern, webpage, 'encoded url', default=default)
247 assignments = assignments.split(';')
251 def parse_js_value(inp):
252 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
254 inps = inp.split('+')
255 return functools.reduce(
256 operator.concat, map(parse_js_value, inps))
260 return remove_quotes(inp)
262 for assn in assignments:
266 assn = re.sub(r'var\s+', '', assn)
267 vname, value = assn.split('=', 1)
268 js_vars[vname] = parse_js_value(value)
271 def add_video_url(video_url):
272 v_url = url_or_none(video_url)
275 if v_url in video_urls_set:
277 video_urls.append((v_url, None))
278 video_urls_set.add(v_url)
281 FORMAT_PREFIXES = ('media', 'quality')
282 js_vars = extract_js_vars(
283 webpage, r'(var\s+(?:%s)_.+)' % '|'.join(FORMAT_PREFIXES),
286 for key, format_url in js_vars.items():
287 if any(key.startswith(p) for p in FORMAT_PREFIXES):
288 add_video_url(format_url)
289 if not video_urls and re.search(
290 r'<[^>]+\bid=["\']lockedPlayer', webpage):
291 raise ExtractorError(
292 'Video %s is locked' % video_id, expected=True)
295 js_vars = extract_js_vars(
296 dl_webpage('tv'), r'(var.+?mediastring.+?)</script>')
297 add_video_url(js_vars['mediastring'])
299 for mobj in re.finditer(
300 r'<a[^>]+\bclass=["\']downloadBtn\b[^>]+\bhref=(["\'])(?P<url>(?:(?!\1).)+)\1',
302 video_url = mobj.group('url')
303 if video_url not in video_urls_set:
304 video_urls.append((video_url, None))
305 video_urls_set.add(video_url)
309 for video_url, height in video_urls:
311 upload_date = self._search_regex(
312 r'/(\d{6}/\d{2})/', video_url, 'upload data', default=None)
314 upload_date = upload_date.replace('/', '')
315 ext = determine_ext(video_url)
317 formats.extend(self._extract_mpd_formats(
318 video_url, video_id, mpd_id='dash', fatal=False))
321 formats.extend(self._extract_m3u8_formats(
322 video_url, video_id, 'mp4', entry_protocol='m3u8_native',
323 m3u8_id='hls', fatal=False))
326 mobj = re.search(r'(?P<height>\d+)[pP]?_(?P<tbr>\d+)[kK]', video_url)
329 height = int(mobj.group('height'))
330 tbr = int(mobj.group('tbr'))
333 'format_id': '%dp' % height if height else None,
337 self._sort_formats(formats)
339 video_uploader = self._html_search_regex(
340 r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?:(?:user|channel)s|model|pornstar)/|span\b[^>]+\bclass=["\']username)[^>]+>(.+?)<',
341 webpage, 'uploader', fatal=False)
343 view_count = self._extract_count(
344 r'<span class="count">([\d,\.]+)</span> [Vv]iews', webpage, 'view')
345 like_count = self._extract_count(
346 r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
347 dislike_count = self._extract_count(
348 r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
349 comment_count = self._extract_count(
350 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
352 def extract_list(meta_key):
353 div = self._search_regex(
354 r'(?s)<div[^>]+\bclass=["\'].*?\b%sWrapper[^>]*>(.+?)</div>'
355 % meta_key, webpage, meta_key, default=None)
357 return re.findall(r'<a[^>]+\bhref=[^>]+>([^<]+)', div)
361 'uploader': video_uploader,
362 'upload_date': upload_date,
364 'thumbnail': thumbnail,
365 'duration': duration,
366 'view_count': view_count,
367 'like_count': like_count,
368 'dislike_count': dislike_count,
369 'comment_count': comment_count,
372 'tags': extract_list('tags'),
373 'categories': extract_list('categories'),
374 'subtitles': subtitles,
378 class PornHubPlaylistBaseIE(PornHubBaseIE):
379 def _extract_entries(self, webpage, host):
380 # Only process container div with main playlist content skipping
381 # drop-down menu that uses similar pattern for videos (see
382 # https://github.com/ytdl-org/youtube-dl/issues/11594).
383 container = self._search_regex(
384 r'(?s)(<div[^>]+class=["\']container.+)', webpage,
385 'container', default=webpage)
389 'http://www.%s/%s' % (host, video_url),
390 PornHubIE.ie_key(), video_title=title)
391 for video_url, title in orderedSet(re.findall(
392 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
396 def _real_extract(self, url):
397 mobj = re.match(self._VALID_URL, url)
398 host = mobj.group('host')
399 playlist_id = mobj.group('id')
401 webpage = self._download_webpage(url, playlist_id)
403 entries = self._extract_entries(webpage, host)
405 playlist = self._parse_json(
407 r'(?:playlistObject|PLAYLIST_VIEW)\s*=\s*({.+?});', webpage,
408 'playlist', default='{}'),
409 playlist_id, fatal=False)
410 title = playlist.get('title') or self._search_regex(
411 r'>Videos\s+in\s+(.+?)\s+[Pp]laylist<', webpage, 'title', fatal=False)
413 return self.playlist_result(
414 entries, playlist_id, title, playlist.get('description'))
417 class PornHubUserIE(PornHubPlaylistBaseIE):
418 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net))/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/?#&]+))(?:[?#&]|/(?!videos)|$)'
420 'url': 'https://www.pornhub.com/model/zoe_ph',
421 'playlist_mincount': 118,
423 'url': 'https://www.pornhub.com/pornstar/liz-vicious',
427 'playlist_mincount': 118,
429 'url': 'https://www.pornhub.com/users/russianveet69',
430 'only_matching': True,
432 'url': 'https://www.pornhub.com/channels/povd',
433 'only_matching': True,
435 'url': 'https://www.pornhub.com/model/zoe_ph?abc=1',
436 'only_matching': True,
439 def _real_extract(self, url):
440 mobj = re.match(self._VALID_URL, url)
441 user_id = mobj.group('id')
442 return self.url_result(
443 '%s/videos' % mobj.group('url'), ie=PornHubPagedVideoListIE.ie_key(),
447 class PornHubPagedPlaylistBaseIE(PornHubPlaylistBaseIE):
449 def _has_more(webpage):
452 <li[^>]+\bclass=["\']page_next|
453 <link[^>]+\brel=["\']next|
454 <button[^>]+\bid=["\']moreDataBtn
455 ''', webpage) is not None
457 def _real_extract(self, url):
458 mobj = re.match(self._VALID_URL, url)
459 host = mobj.group('host')
460 item_id = mobj.group('id')
462 page = int_or_none(self._search_regex(
463 r'\bpage=(\d+)', url, 'page', default=None))
466 for page_num in (page, ) if page is not None else itertools.count(1):
468 webpage = self._download_webpage(
469 url, item_id, 'Downloading page %d' % page_num,
470 query={'page': page_num})
471 except ExtractorError as e:
472 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
475 page_entries = self._extract_entries(webpage, host)
478 entries.extend(page_entries)
479 if not self._has_more(webpage):
482 return self.playlist_result(orderedSet(entries), item_id)
485 class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
486 _VALID_URL = r'https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net))/(?P<id>(?:[^/]+/)*[^/?#&]+)'
488 'url': 'https://www.pornhub.com/model/zoe_ph/videos',
489 'only_matching': True,
491 'url': 'http://www.pornhub.com/users/rushandlia/videos',
492 'only_matching': True,
494 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos',
496 'id': 'pornstar/jenny-blighe/videos',
498 'playlist_mincount': 149,
500 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos?page=3',
502 'id': 'pornstar/jenny-blighe/videos',
504 'playlist_mincount': 40,
506 # default sorting as Top Rated Videos
507 'url': 'https://www.pornhub.com/channels/povd/videos',
509 'id': 'channels/povd/videos',
511 'playlist_mincount': 293,
514 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
515 'only_matching': True,
518 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
519 'only_matching': True,
522 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
523 'only_matching': True,
525 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
526 'only_matching': True,
529 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=mv',
530 'only_matching': True,
533 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=tr',
534 'only_matching': True,
537 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=lg',
538 'only_matching': True,
541 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=cm',
542 'only_matching': True,
544 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/paid',
545 'only_matching': True,
547 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/fanonly',
548 'only_matching': True,
550 'url': 'https://www.pornhub.com/video',
551 'only_matching': True,
553 'url': 'https://www.pornhub.com/video?page=3',
554 'only_matching': True,
556 'url': 'https://www.pornhub.com/video/search?search=123',
557 'only_matching': True,
559 'url': 'https://www.pornhub.com/categories/teen',
560 'only_matching': True,
562 'url': 'https://www.pornhub.com/categories/teen?page=3',
563 'only_matching': True,
565 'url': 'https://www.pornhub.com/hd',
566 'only_matching': True,
568 'url': 'https://www.pornhub.com/hd?page=3',
569 'only_matching': True,
571 'url': 'https://www.pornhub.com/described-video',
572 'only_matching': True,
574 'url': 'https://www.pornhub.com/described-video?page=2',
575 'only_matching': True,
577 'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
578 'only_matching': True,
580 'url': 'https://www.pornhub.com/playlist/44121572',
582 'id': 'playlist/44121572',
584 'playlist_mincount': 132,
586 'url': 'https://www.pornhub.com/playlist/4667351',
587 'only_matching': True,
589 'url': 'https://de.pornhub.com/playlist/4667351',
590 'only_matching': True,
594 def suitable(cls, url):
596 if PornHubIE.suitable(url) or PornHubUserIE.suitable(url) or PornHubUserVideosUploadIE.suitable(url)
597 else super(PornHubPagedVideoListIE, cls).suitable(url))
600 class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
601 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?(?P<host>pornhub(?:premium)?\.(?:com|net))/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)'
603 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
605 'id': 'jenny-blighe',
607 'playlist_mincount': 129,
609 'url': 'https://www.pornhub.com/model/zoe_ph/videos/upload',
610 'only_matching': True,