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\.(?: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,
155 def _extract_urls(webpage):
157 r'<iframe[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.(?
:com|net
)/embed
/[\da
-z
]+)',
160 def _extract_count(self, pattern, webpage, name):
161 return str_to_int(self._search_regex(
162 pattern, webpage, '%s count
' % name, fatal=False))
164 def _real_extract(self, url):
165 mobj = re.match(self._VALID_URL, url)
166 host = mobj.group('host
') or 'pornhub
.com
'
167 video_id = mobj.group('id')
169 self._set_cookie(host, 'age_verified
', '1')
171 def dl_webpage(platform):
172 self._set_cookie(host, 'platform
', platform)
173 return self._download_webpage(
174 'https
://www
.%s/view_video
.php?viewkey
=%s' % (host, video_id),
175 video_id, 'Downloading
%s webpage
' % platform)
177 webpage = dl_webpage('pc
')
179 error_msg = self._html_search_regex(
180 r'(?s
)<div
[^
>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
181 webpage, 'error message', default=None, group='error')
183 error_msg = re.sub(r'\s+', ' ', error_msg)
184 raise ExtractorError(
185 'PornHub said: %s' % error_msg,
186 expected=True, video_id=video_id)
188 # video_title from flashvars contains whitespace instead of non-ASCII (see
189 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
191 title = self._html_search_meta(
192 'twitter:title', webpage, default=None) or self._search_regex(
193 (r'<h1[^>]+class=["\']title
["\'][^>]*>(?P<title>[^<]+)',
194 r'<div[^>]+data-video-title=(["\'])(?P
<title
>.+?
)\
1',
195 r'shareTitle\s
*=\s
*(["\'])(?P<title>.+?)\1'),
196 webpage, 'title', group='title')
199 video_urls_set = set()
202 flashvars = self._parse_json(
204 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
207 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
209 subtitles.setdefault('en', []).append({
213 thumbnail = flashvars.get('image_url')
214 duration = int_or_none(flashvars.get('video_duration'))
215 media_definitions = flashvars.get('mediaDefinitions')
216 if isinstance(media_definitions, list):
217 for definition in media_definitions:
218 if not isinstance(definition, dict):
220 video_url = definition.get('videoUrl')
221 if not video_url or not isinstance(video_url, compat_str):
223 if video_url in video_urls_set:
225 video_urls_set.add(video_url)
227 (video_url, int_or_none(definition.get('quality'))))
229 thumbnail, duration = [None] * 2
231 def extract_js_vars(webpage, pattern, default=NO_DEFAULT):
232 assignments = self._search_regex(
233 pattern, webpage, 'encoded url', default=default)
237 assignments = assignments.split(';')
241 def parse_js_value(inp):
242 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
244 inps = inp.split('+')
245 return functools.reduce(
246 operator.concat, map(parse_js_value, inps))
250 return remove_quotes(inp)
252 for assn in assignments:
256 assn = re.sub(r'var\s+', '', assn)
257 vname, value = assn.split('=', 1)
258 js_vars[vname] = parse_js_value(value)
261 def add_video_url(video_url):
262 v_url = url_or_none(video_url)
265 if v_url in video_urls_set:
267 video_urls.append((v_url, None))
268 video_urls_set.add(v_url)
271 FORMAT_PREFIXES = ('media', 'quality')
272 js_vars = extract_js_vars(
273 webpage, r'(var\s+(?:%s)_.+)' % '|'.join(FORMAT_PREFIXES),
276 for key, format_url in js_vars.items():
277 if any(key.startswith(p) for p in FORMAT_PREFIXES):
278 add_video_url(format_url)
279 if not video_urls and re.search(
280 r'<[^>]+\bid=["\']lockedPlayer
', webpage):
281 raise ExtractorError(
282 'Video
%s is locked
' % video_id, expected=True)
285 js_vars = extract_js_vars(
286 dl_webpage('tv
'), r'(var
.+?mediastring
.+?
)</script
>')
287 add_video_url(js_vars['mediastring
'])
289 for mobj in re.finditer(
290 r'<a
[^
>]+\bclass
=["\']downloadBtn\b[^>]+\bhref=(["\'])(?P
<url
>(?
:(?
!\
1).)+)\
1',
292 video_url = mobj.group('url
')
293 if video_url not in video_urls_set:
294 video_urls.append((video_url, None))
295 video_urls_set.add(video_url)
299 for video_url, height in video_urls:
301 upload_date = self._search_regex(
302 r'/(\d{6}
/\d{2}
)/', video_url, 'upload data
', default=None)
304 upload_date = upload_date.replace('/', '')
305 ext = determine_ext(video_url)
307 formats.extend(self._extract_mpd_formats(
308 video_url, video_id, mpd_id='dash
', fatal=False))
311 formats.extend(self._extract_m3u8_formats(
312 video_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
313 m3u8_id='hls
', fatal=False))
316 mobj = re.search(r'(?P
<height
>\d
+)[pP
]?
_(?P
<tbr
>\d
+)[kK
]', video_url)
319 height = int(mobj.group('height
'))
320 tbr = int(mobj.group('tbr
'))
323 'format_id
': '%dp
' % height if height else None,
327 self._sort_formats(formats)
329 video_uploader = self._html_search_regex(
330 r'(?s
)From
: 
;.+?
<(?
:a
\b[^
>]+\bhref
=["\']/(?:(?:user|channel)s|model|pornstar)/|span\b[^>]+\bclass=["\']username
)[^
>]+>(.+?
)<',
331 webpage, 'uploader
', fatal=False)
333 view_count = self._extract_count(
334 r'<span
class="count">([\d
,\
.]+)</span
> views
', webpage, 'view
')
335 like_count = self._extract_count(
336 r'<span
class="votesUp">([\d
,\
.]+)</span
>', webpage, 'like
')
337 dislike_count = self._extract_count(
338 r'<span
class="votesDown">([\d
,\
.]+)</span
>', webpage, 'dislike
')
339 comment_count = self._extract_count(
340 r'All Comments\s
*<span
>\
(([\d
,.]+)\
)', webpage, 'comment
')
342 def extract_list(meta_key):
343 div = self._search_regex(
344 r'(?s
)<div
[^
>]+\bclass
=["\'].*?\b%sWrapper[^>]*>(.+?)</div>'
345 % meta_key, webpage, meta_key, default=None)
347 return re.findall(r'<a[^>]+\bhref=[^>]+>([^<]+)', div)
351 'uploader': video_uploader,
352 'upload_date': upload_date,
354 'thumbnail': thumbnail,
355 'duration': duration,
356 'view_count': view_count,
357 'like_count': like_count,
358 'dislike_count': dislike_count,
359 'comment_count': comment_count,
362 'tags': extract_list('tags'),
363 'categories': extract_list('categories'),
364 'subtitles': subtitles,
368 class PornHubPlaylistBaseIE(PornHubBaseIE):
369 def _extract_entries(self, webpage, host):
370 # Only process container div with main playlist content skipping
371 # drop-down menu that uses similar pattern for videos (see
372 # https://github.com/ytdl-org/youtube-dl/issues/11594).
373 container = self._search_regex(
374 r'(?s)(<div[^>]+class=["\']container
.+)', webpage,
375 'container
', default=webpage)
379 'http
://www
.%s/%s' % (host, video_url),
380 PornHubIE.ie_key(), video_title=title)
381 for video_url, title in orderedSet(re.findall(
382 r'href
="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^
"]+)"',
386 def _real_extract(self, url):
387 mobj = re.match(self._VALID_URL, url)
388 host = mobj.group('host
')
389 playlist_id = mobj.group('id')
391 webpage = self._download_webpage(url, playlist_id)
393 entries = self._extract_entries(webpage, host)
395 playlist = self._parse_json(
397 r'(?
:playlistObject|PLAYLIST_VIEW
)\s
*=\s
*({.+?
});', webpage,
398 'playlist
', default='{}'),
399 playlist_id, fatal=False)
400 title = playlist.get('title
') or self._search_regex(
401 r'>Videos\s
+in\s
+(.+?
)\s
+[Pp
]laylist
<', webpage, 'title
', fatal=False)
403 return self.playlist_result(
404 entries, playlist_id, title, playlist.get('description
'))
407 class PornHubUserIE(PornHubPlaylistBaseIE):
408 _VALID_URL = r'(?P
<url
>https?
://(?
:[^
/]+\
.)?pornhub\
.(?
:com|net
)/(?
:(?
:user|channel
)s|model|pornstar
)/(?P
<id>[^
/?
#&]+))(?:[?#&]|/(?!videos)|$)'
410 'url': 'https://www.pornhub.com/model/zoe_ph',
411 'playlist_mincount': 118,
413 'url': 'https://www.pornhub.com/pornstar/liz-vicious',
417 'playlist_mincount': 118,
419 'url': 'https://www.pornhub.com/users/russianveet69',
420 'only_matching': True,
422 'url': 'https://www.pornhub.com/channels/povd',
423 'only_matching': True,
425 'url': 'https://www.pornhub.com/model/zoe_ph?abc=1',
426 'only_matching': True,
429 def _real_extract(self
, url
):
430 mobj
= re
.match(self
._VALID
_URL
, url
)
431 user_id
= mobj
.group('id')
432 return self
.url_result(
433 '%s/videos' % mobj
.group('url'), ie
=PornHubPagedVideoListIE
.ie_key(),
437 class PornHubPagedPlaylistBaseIE(PornHubPlaylistBaseIE
):
439 def _has_more(webpage
):
442 <li[^>]+\bclass=["\']page_next|
443 <link
[^
>]+\brel
=["\']next|
444 <button[^>]+\bid=["\']moreDataBtn
445 ''', webpage) is not None
447 def _real_extract(self, url):
448 mobj = re.match(self._VALID_URL, url)
449 host = mobj.group('host')
450 item_id = mobj.group('id')
452 page = int_or_none(self._search_regex(
453 r'\bpage=(\d+)', url, 'page', default=None))
456 for page_num in (page, ) if page is not None else itertools.count(1):
458 webpage = self._download_webpage(
459 url, item_id, 'Downloading page %d' % page_num,
460 query={'page': page_num})
461 except ExtractorError as e:
462 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
465 page_entries = self._extract_entries(webpage, host)
468 entries.extend(page_entries)
469 if not self._has_more(webpage):
472 return self.playlist_result(orderedSet(entries), item_id)
475 class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
476 _VALID_URL = r'https?://(?:[^/]+\.)?(?P<host>pornhub\.(?:com|net))/(?P<id>(?:[^/]+/)*[^/?#&]+)'
478 'url': 'https://www.pornhub.com/model/zoe_ph/videos',
479 'only_matching': True,
481 'url': 'http://www.pornhub.com/users/rushandlia/videos',
482 'only_matching': True,
484 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos',
486 'id': 'pornstar/jenny-blighe/videos',
488 'playlist_mincount': 149,
490 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos?page=3',
492 'id': 'pornstar/jenny-blighe/videos',
494 'playlist_mincount': 40,
496 # default sorting as Top Rated Videos
497 'url': 'https://www.pornhub.com/channels/povd/videos',
499 'id': 'channels/povd/videos',
501 'playlist_mincount': 293,
504 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
505 'only_matching': True,
508 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
509 'only_matching': True,
512 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
513 'only_matching': True,
515 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
516 'only_matching': True,
519 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=mv',
520 'only_matching': True,
523 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=tr',
524 'only_matching': True,
527 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=lg',
528 'only_matching': True,
531 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=cm',
532 'only_matching': True,
534 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/paid',
535 'only_matching': True,
537 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/fanonly',
538 'only_matching': True,
540 'url': 'https://www.pornhub.com/video',
541 'only_matching': True,
543 'url': 'https://www.pornhub.com/video?page=3',
544 'only_matching': True,
546 'url': 'https://www.pornhub.com/video/search?search=123',
547 'only_matching': True,
549 'url': 'https://www.pornhub.com/categories/teen',
550 'only_matching': True,
552 'url': 'https://www.pornhub.com/categories/teen?page=3',
553 'only_matching': True,
555 'url': 'https://www.pornhub.com/hd',
556 'only_matching': True,
558 'url': 'https://www.pornhub.com/hd?page=3',
559 'only_matching': True,
561 'url': 'https://www.pornhub.com/described-video',
562 'only_matching': True,
564 'url': 'https://www.pornhub.com/described-video?page=2',
565 'only_matching': True,
567 'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
568 'only_matching': True,
570 'url': 'https://www.pornhub.com/playlist/44121572',
572 'id': 'playlist/44121572',
574 'playlist_mincount': 132,
576 'url': 'https://www.pornhub.com/playlist/4667351',
577 'only_matching': True,
579 'url': 'https://de.pornhub.com/playlist/4667351',
580 'only_matching': True,
584 def suitable(cls, url):
586 if PornHubIE.suitable(url) or PornHubUserIE.suitable(url) or PornHubUserVideosUploadIE.suitable(url)
587 else super(PornHubPagedVideoListIE, cls).suitable(url))
590 class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
591 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?(?P<host>pornhub\.(?:com|net))/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)'
593 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
595 'id': 'jenny-blighe',
597 'playlist_mincount': 129,
599 'url': 'https://www.pornhub.com/model/zoe_ph/videos/upload',
600 'only_matching': True,