]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pornhub.py
11b8cfcf73f13f7db93a005d04b81ee80e06ed08
2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import (
13 compat_urllib_request
,
15 from .openload
import PhantomJSwrapper
27 class PornHubBaseIE(InfoExtractor
):
28 def _download_webpage_handle(self
, *args
, **kwargs
):
29 def dl(*args
, **kwargs
):
30 return super(PornHubBaseIE
, self
)._download
_webpage
_handle
(*args
, **kwargs
)
32 webpage
, urlh
= dl(*args
, **kwargs
)
34 if any(re
.search(p
, webpage
) for p
in (
35 r
'<body\b[^>]+\bonload=["\']go\
(\
)',
36 r'document\
.cookie\s
*=\s
*["\']RNKEY=',
37 r'document\.location\.reload\(true\)')):
38 url_or_request = args[0]
39 url = (url_or_request.get_full_url()
40 if isinstance(url_or_request, compat_urllib_request.Request)
42 phantom = PhantomJSwrapper(self, required_version='2.0')
43 phantom.get(url, html=webpage)
44 webpage, urlh = dl(*args, **kwargs)
49 class PornHubIE(PornHubBaseIE):
50 IE_DESC = 'PornHub and Thumbzilla'
54 (?:[^/]+\.)?(?P<host>pornhub\.(?:com|net))/(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
55 (?:www\.)?thumbzilla\.com/video/
60 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
61 'md5': '1e19b41231a02eba417839222ac9d58e',
65 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
67 'upload_date': '20130628',
79 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
84 'uploader': 'Unknown',
85 'upload_date': '20150213',
96 'skip_download': True,
100 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5af5fef7c2aa7',
102 'id': 'ph5af5fef7c2aa7',
104 'title': 'BFFS - Cute Teen Girls Share Cock On the Floor',
109 'dislike_count': int,
110 'comment_count': int,
121 'skip_download': True,
124 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
125 'only_matching': True,
127 # removed at the request of cam4.com
128 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
129 'only_matching': True,
131 # removed at the request of the copyright owner
132 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
133 'only_matching': True,
135 # removed by uploader
136 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
137 'only_matching': True,
140 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
141 'only_matching': True,
143 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
144 'only_matching': True,
146 'url': 'http://www.pornhub.com/video/show?viewkey=648719015',
147 'only_matching': True,
149 'url': 'https://www.pornhub.net/view_video.php?viewkey=203640933',
150 'only_matching': True,
154 def _extract_urls(webpage):
156 r'<iframe[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.(?
:com|net
)/embed
/[\da
-z
]+)',
159 def _extract_count(self, pattern, webpage, name):
160 return str_to_int(self._search_regex(
161 pattern, webpage, '%s count
' % name, fatal=False))
163 def _real_extract(self, url):
164 mobj = re.match(self._VALID_URL, url)
165 host = mobj.group('host
') or 'pornhub
.com
'
166 video_id = mobj.group('id')
168 self._set_cookie(host, 'age_verified
', '1')
170 def dl_webpage(platform):
171 self._set_cookie(host, 'platform
', platform)
172 return self._download_webpage(
173 'https
://www
.%s/view_video
.php?viewkey
=%s' % (host, video_id),
174 video_id, 'Downloading
%s webpage
' % platform)
176 webpage = dl_webpage('pc
')
178 error_msg = self._html_search_regex(
179 r'(?s
)<div
[^
>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
180 webpage, 'error message', default=None, group='error')
182 error_msg = re.sub(r'\s+', ' ', error_msg)
183 raise ExtractorError(
184 'PornHub said: %s' % error_msg,
185 expected=True, video_id=video_id)
187 # video_title from flashvars contains whitespace instead of non-ASCII (see
188 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
190 title = self._html_search_meta(
191 'twitter:title', webpage, default=None) or self._search_regex(
192 (r'<h1[^>]+class=["\']title
["\'][^>]*>(?P<title>[^<]+)',
193 r'<div[^>]+data-video-title=(["\'])(?P
<title
>.+?
)\
1',
194 r'shareTitle\s
*=\s
*(["\'])(?P<title>.+?)\1'),
195 webpage, 'title', group='title')
198 video_urls_set = set()
201 flashvars = self._parse_json(
203 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
206 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
208 subtitles.setdefault('en', []).append({
212 thumbnail = flashvars.get('image_url')
213 duration = int_or_none(flashvars.get('video_duration'))
214 media_definitions = flashvars.get('mediaDefinitions')
215 if isinstance(media_definitions, list):
216 for definition in media_definitions:
217 if not isinstance(definition, dict):
219 video_url = definition.get('videoUrl')
220 if not video_url or not isinstance(video_url, compat_str):
222 if video_url in video_urls_set:
224 video_urls_set.add(video_url)
226 (video_url, int_or_none(definition.get('quality'))))
228 thumbnail, duration = [None] * 2
231 tv_webpage = dl_webpage('tv')
233 assignments = self._search_regex(
234 r'(var.+?mediastring.+?)</script>', tv_webpage,
235 'encoded url').split(';')
239 def parse_js_value(inp):
240 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
242 inps = inp.split('+')
243 return functools.reduce(
244 operator.concat, map(parse_js_value, inps))
248 return remove_quotes(inp)
250 for assn in assignments:
254 assn = re.sub(r'var\s+', '', assn)
255 vname, value = assn.split('=', 1)
256 js_vars[vname] = parse_js_value(value)
258 video_url = js_vars['mediastring']
259 if video_url not in video_urls_set:
260 video_urls.append((video_url, None))
261 video_urls_set.add(video_url)
263 for mobj in re.finditer(
264 r'<a[^>]+\bclass=["\']downloadBtn
\b[^
>]+\bhref
=(["\'])(?P<url>(?:(?!\1).)+)\1',
266 video_url = mobj.group('url')
267 if video_url not in video_urls_set:
268 video_urls.append((video_url, None))
269 video_urls_set.add(video_url)
273 for video_url, height in video_urls:
275 upload_date = self._search_regex(
276 r'/(\d{6}/\d{2})/', video_url, 'upload data', default=None)
278 upload_date = upload_date.replace('/', '')
279 if determine_ext(video_url) == 'mpd':
280 formats.extend(self._extract_mpd_formats(
281 video_url, video_id, mpd_id='dash', fatal=False))
284 mobj = re.search(r'(?P<height>\d+)[pP]?_(?P<tbr>\d+)[kK]', video_url)
287 height = int(mobj.group('height'))
288 tbr = int(mobj.group('tbr'))
291 'format_id': '%dp' % height if height else None,
295 self._sort_formats(formats)
297 video_uploader = self._html_search_regex(
298 r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?
:(?
:user|channel
)s|model|pornstar
)/|span
\b[^
>]+\bclass
=["\']username)[^>]+>(.+?)<',
299 webpage, 'uploader', fatal=False)
301 view_count = self._extract_count(
302 r'<span class="count
">([\d,\.]+)</span> views', webpage, 'view')
303 like_count = self._extract_count(
304 r'<span class="votesUp
">([\d,\.]+)</span>', webpage, 'like')
305 dislike_count = self._extract_count(
306 r'<span class="votesDown
">([\d,\.]+)</span>', webpage, 'dislike')
307 comment_count = self._extract_count(
308 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
310 def extract_list(meta_key):
311 div = self._search_regex(
312 r'(?s)<div[^>]+\bclass=["\'].*?
\b%sWrapper
[^
>]*>(.+?
)</div
>'
313 % meta_key, webpage, meta_key, default=None)
315 return re.findall(r'<a
[^
>]+\bhref
=[^
>]+>([^
<]+)', div)
319 'uploader
': video_uploader,
320 'upload_date
': upload_date,
322 'thumbnail
': thumbnail,
323 'duration
': duration,
324 'view_count
': view_count,
325 'like_count
': like_count,
326 'dislike_count
': dislike_count,
327 'comment_count
': comment_count,
330 'tags
': extract_list('tags
'),
331 'categories
': extract_list('categories
'),
332 'subtitles
': subtitles,
336 class PornHubPlaylistBaseIE(PornHubBaseIE):
337 def _extract_entries(self, webpage, host):
338 # Only process container div with main playlist content skipping
339 # drop-down menu that uses similar pattern for videos (see
340 # https://github.com/ytdl-org/youtube-dl/issues/11594).
341 container = self._search_regex(
342 r'(?s
)(<div
[^
>]+class=["\']container.+)', webpage,
343 'container', default=webpage)
347 'http://www.%s/%s' % (host, video_url),
348 PornHubIE.ie_key(), video_title=title)
349 for video_url, title in orderedSet(re.findall(
350 r'href="/?
(view_video\
.php
\?.*\bviewkey
=[\da
-z
]+[^
"]*)"[^
>]*\s
+title
="([^"]+)"',
354 def _real_extract(self, url):
355 mobj = re.match(self._VALID_URL, url)
356 host = mobj.group('host')
357 playlist_id = mobj.group('id')
359 webpage = self._download_webpage(url, playlist_id)
361 entries = self._extract_entries(webpage, host)
363 playlist = self._parse_json(
365 r'(?:playlistObject|PLAYLIST_VIEW)\s*=\s*({.+?});', webpage,
366 'playlist', default='{}'),
367 playlist_id, fatal=False)
368 title = playlist.get('title') or self._search_regex(
369 r'>Videos\s+in\s+(.+?)\s+[Pp]laylist<', webpage, 'title', fatal=False)
371 return self.playlist_result(
372 entries, playlist_id, title, playlist.get('description'))
375 class PornHubUserIE(PornHubPlaylistBaseIE):
376 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?pornhub\.(?:com|net)/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/?#&]+))(?:[?#&]|/(?!videos)|$)'
378 'url': 'https://www.pornhub.com/model/zoe_ph',
379 'playlist_mincount': 118,
381 'url': 'https://www.pornhub.com/pornstar/liz-vicious',
385 'playlist_mincount': 118,
387 'url': 'https://www.pornhub.com/users/russianveet69',
388 'only_matching': True,
390 'url': 'https://www.pornhub.com/channels/povd',
391 'only_matching': True,
393 'url': 'https://www.pornhub.com/model/zoe_ph?abc=1',
394 'only_matching': True,
397 def _real_extract(self, url):
398 mobj = re.match(self._VALID_URL, url)
399 user_id = mobj.group('id')
400 return self.url_result(
401 '%s/videos' % mobj.group('url'), ie=PornHubPagedVideoListIE.ie_key(),
405 class PornHubPagedPlaylistBaseIE(PornHubPlaylistBaseIE):
406 def _real_extract(self, url):
407 mobj = re.match(self._VALID_URL, url)
408 host = mobj.group('host')
409 item_id = mobj.group('id')
411 page = int_or_none(self._search_regex(
412 r'\bpage=(\d+)', url, 'page', default=None))
414 page_url = self._make_page_url(url)
417 for page_num in (page, ) if page is not None else itertools.count(1):
419 webpage = self._download_webpage(
420 page_url, item_id, 'Downloading page %d' % page_num,
421 query={'page': page_num})
422 except ExtractorError as e:
423 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
426 page_entries = self._extract_entries(webpage, host)
429 entries.extend(page_entries)
430 if not self._has_more(webpage):
433 return self.playlist_result(orderedSet(entries), item_id)
436 class PornHubPagedVideoListIE(PornHubPagedPlaylistBaseIE):
437 _VALID_URL = r'https?://(?:[^/]+\.)?(?P<host>pornhub\.(?:com|net))/(?P<id>(?:[^/]+/)*[^/?#&]+)'
439 'url': 'https://www.pornhub.com/model/zoe_ph/videos',
440 'only_matching': True,
442 'url': 'http://www.pornhub.com/users/rushandlia/videos',
443 'only_matching': True,
445 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos',
447 'id': 'pornstar/jenny-blighe/videos',
449 'playlist_mincount': 149,
451 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos?page=3',
453 'id': 'pornstar/jenny-blighe/videos',
455 'playlist_mincount': 40,
457 # default sorting as Top Rated Videos
458 'url': 'https://www.pornhub.com/channels/povd/videos',
460 'id': 'channels/povd/videos',
462 'playlist_mincount': 293,
465 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
466 'only_matching': True,
469 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
470 'only_matching': True,
473 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
474 'only_matching': True,
476 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
477 'only_matching': True,
480 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=mv',
481 'only_matching': True,
484 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=tr',
485 'only_matching': True,
488 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=lg',
489 'only_matching': True,
492 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos?o=cm',
493 'only_matching': True,
495 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/paid',
496 'only_matching': True,
498 'url': 'https://www.pornhub.com/pornstar/liz-vicious/videos/fanonly',
499 'only_matching': True,
501 'url': 'https://www.pornhub.com/video',
502 'only_matching': True,
504 'url': 'https://www.pornhub.com/video?page=3',
505 'only_matching': True,
507 'url': 'https://www.pornhub.com/video/search?search=123',
508 'only_matching': True,
510 'url': 'https://www.pornhub.com/categories/teen',
511 'only_matching': True,
513 'url': 'https://www.pornhub.com/categories/teen?page=3',
514 'only_matching': True,
516 'url': 'https://www.pornhub.com/hd',
517 'only_matching': True,
519 'url': 'https://www.pornhub.com/hd?page=3',
520 'only_matching': True,
522 'url': 'https://www.pornhub.com/described-video',
523 'only_matching': True,
525 'url': 'https://www.pornhub.com/described-video?page=2',
526 'only_matching': True,
528 'url': 'https://www.pornhub.com/video/incategories/60fps-1/hd-porn',
529 'only_matching': True,
531 'url': 'https://www.pornhub.com/playlist/44121572',
533 'id': 'playlist/44121572',
535 'playlist_mincount': 132,
537 'url': 'https://www.pornhub.com/playlist/4667351',
538 'only_matching': True,
540 'url': 'https://de.pornhub.com/playlist/4667351',
541 'only_matching': True,
545 def suitable(cls, url):
547 if PornHubIE.suitable(url) or PornHubUserIE.suitable(url) or PornHubUserVideosUploadIE.suitable(url)
548 else super(PornHubPagedVideoListIE, cls).suitable(url))
550 def _make_page_url(self, url):
554 def _has_more(webpage):
557 <li[^>]+\bclass=["\']page_next|
558 <link
[^
>]+\brel
=["\']next|
559 <button[^>]+\bid=["\']moreDataBtn
560 ''', webpage) is not None
563 class PornHubUserVideosUploadIE(PornHubPagedPlaylistBaseIE):
564 _VALID_URL = r'(?P<url>https?://(?:[^/]+\.)?(?P<host>pornhub\.(?:com|net))/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos/upload)'
566 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
568 'id': 'jenny-blighe',
570 'playlist_mincount': 129,
572 'url': 'https://www.pornhub.com/model/zoe_ph/videos/upload',
573 'only_matching': True,
576 def _make_page_url(self, url):
577 mobj = re.match(self._VALID_URL, url)
578 return '%s/ajax' % mobj.group('url')
581 def _has_more(webpage):