2 from __future__ import unicode_literals
9 from .common import InfoExtractor
10 from ..compat import (
25 class PornHubIE(InfoExtractor):
26 IE_DESC = 'PornHub and Thumbzilla'
30 (?:[^/]+\.)?pornhub\.(?:com|net)/(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
31 (?:www\.)?thumbzilla\.com/video/
36 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
37 'md5': '1e19b41231a02eba417839222ac9d58e',
41 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
43 'upload_date': '20130628',
55 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
60 'uploader': 'Unknown',
61 'upload_date': '20150213',
72 'skip_download': True,
76 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5af5fef7c2aa7',
78 'id': 'ph5af5fef7c2aa7',
80 'title': 'BFFS - Cute Teen Girls Share Cock On the Floor',
97 'skip_download': True,
100 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
101 'only_matching': True,
103 # removed at the request of cam4.com
104 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
105 'only_matching': True,
107 # removed at the request of the copyright owner
108 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
109 'only_matching': True,
111 # removed by uploader
112 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
113 'only_matching': True,
116 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
117 'only_matching': True,
119 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
120 'only_matching': True,
122 'url': 'http://www.pornhub.com/video/show?viewkey=648719015',
123 'only_matching': True,
125 'url': 'https://www.pornhub.net/view_video.php?viewkey=203640933',
126 'only_matching': True,
130 def _extract_urls(webpage):
132 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/[\da-z]+)',
135 def _extract_count(self, pattern, webpage, name):
136 return str_to_int(self._search_regex(
137 pattern, webpage, '%s count' % name, fatal=False))
139 def _real_extract(self, url):
140 video_id = self._match_id(url)
142 self._set_cookie('pornhub.com', 'age_verified', '1')
144 def dl_webpage(platform):
145 self._set_cookie('pornhub.com', 'platform', platform)
146 return self._download_webpage(
147 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id,
148 video_id, 'Downloading %s webpage' % platform)
150 webpage = dl_webpage('pc')
152 error_msg = self._html_search_regex(
153 r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
154 webpage, 'error message', default=None, group='error')
156 error_msg = re.sub(r'\s+', ' ', error_msg)
157 raise ExtractorError(
158 'PornHub said: %s' % error_msg,
159 expected=True, video_id=video_id)
161 # video_title from flashvars contains whitespace instead of non-ASCII (see
162 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
164 title = self._html_search_meta(
165 'twitter:title', webpage, default=None) or self._search_regex(
166 (r'<h1[^>]+class=["\']title["\'][^>]*>(?P<title>[^<]+)',
167 r'<div[^>]+data-video-title=(["\'])(?P<title>.+?)\1',
168 r'shareTitle\s*=\s*(["\'])(?P<title>.+?)\1'),
169 webpage, 'title', group='title')
172 video_urls_set = set()
175 flashvars = self._parse_json(
177 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
180 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
182 subtitles.setdefault('en', []).append({
186 thumbnail = flashvars.get('image_url')
187 duration = int_or_none(flashvars.get('video_duration'))
188 media_definitions = flashvars.get('mediaDefinitions')
189 if isinstance(media_definitions, list):
190 for definition in media_definitions:
191 if not isinstance(definition, dict):
193 video_url = definition.get('videoUrl')
194 if not video_url or not isinstance(video_url, compat_str):
196 if video_url in video_urls_set:
198 video_urls_set.add(video_url)
200 (video_url, int_or_none(definition.get('quality'))))
202 thumbnail, duration = [None] * 2
205 tv_webpage = dl_webpage('tv')
207 assignments = self._search_regex(
208 r'(var.+?mediastring.+?)</script>', tv_webpage,
209 'encoded url').split(';')
213 def parse_js_value(inp):
214 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
216 inps = inp.split('+')
217 return functools.reduce(
218 operator.concat, map(parse_js_value, inps))
222 return remove_quotes(inp)
224 for assn in assignments:
228 assn = re.sub(r'var\s+', '', assn)
229 vname, value = assn.split('=', 1)
230 js_vars[vname] = parse_js_value(value)
232 video_url = js_vars['mediastring']
233 if video_url not in video_urls_set:
234 video_urls.append((video_url, None))
235 video_urls_set.add(video_url)
237 for mobj in re.finditer(
238 r'<a[^>]+\bclass=["\']downloadBtn\b[^>]+\bhref=(["\'])(?P<url>(?:(?!\1).)+)\1',
240 video_url = mobj.group('url')
241 if video_url not in video_urls_set:
242 video_urls.append((video_url, None))
243 video_urls_set.add(video_url)
247 for video_url, height in video_urls:
249 upload_date = self._search_regex(
250 r'/(\d{6}/\d{2})/', video_url, 'upload data', default=None)
252 upload_date = upload_date.replace('/', '')
254 mobj = re.search(r'(?P<height>\d+)[pP]?_(?P<tbr>\d+)[kK]', video_url)
257 height = int(mobj.group('height'))
258 tbr = int(mobj.group('tbr'))
261 'format_id': '%dp' % height if height else None,
265 self._sort_formats(formats)
267 video_uploader = self._html_search_regex(
268 r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?:(?:user|channel)s|model|pornstar)/|span\b[^>]+\bclass=["\']username)[^>]+>(.+?)<',
269 webpage, 'uploader', fatal=False)
271 view_count = self._extract_count(
272 r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
273 like_count = self._extract_count(
274 r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
275 dislike_count = self._extract_count(
276 r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
277 comment_count = self._extract_count(
278 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
280 page_params = self._parse_json(self._search_regex(
281 r'page_params\.zoneDetails\[([\'"])[^\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
282 webpage, 'page parameters', group='data', default='{}'),
283 video_id, transform_source=js_to_json, fatal=False)
284 tags = categories = None
286 tags = page_params.get('tags', '').split(',')
287 categories = page_params.get('categories', '').split(',')
291 'uploader': video_uploader,
292 'upload_date': upload_date,
294 'thumbnail': thumbnail,
295 'duration': duration,
296 'view_count': view_count,
297 'like_count': like_count,
298 'dislike_count': dislike_count,
299 'comment_count': comment_count,
303 'categories': categories,
304 'subtitles': subtitles,
308 class PornHubPlaylistBaseIE(InfoExtractor):
309 def _extract_entries(self, webpage):
310 # Only process container div with main playlist content skipping
311 # drop-down menu that uses similar pattern for videos (see
312 # https://github.com/rg3/youtube-dl/issues/11594).
313 container = self._search_regex(
314 r'(?s)(<div[^>]+class=["\']container.+)', webpage,
315 'container', default=webpage)
319 'http://www.pornhub.com/%s' % video_url,
320 PornHubIE.ie_key(), video_title=title)
321 for video_url, title in orderedSet(re.findall(
322 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
326 def _real_extract(self, url):
327 playlist_id = self._match_id(url)
329 webpage = self._download_webpage(url, playlist_id)
331 entries = self._extract_entries(webpage)
333 playlist = self._parse_json(
335 r'(?:playlistObject|PLAYLIST_VIEW)\s*=\s*({.+?});', webpage,
336 'playlist', default='{}'),
337 playlist_id, fatal=False)
338 title = playlist.get('title') or self._search_regex(
339 r'>Videos\s+in\s+(.+?)\s+[Pp]laylist<', webpage, 'title', fatal=False)
341 return self.playlist_result(
342 entries, playlist_id, title, playlist.get('description'))
345 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
346 _VALID_URL = r'https?://(?:[^/]+\.)?pornhub\.(?:com|net)/playlist/(?P<id>\d+)'
348 'url': 'http://www.pornhub.com/playlist/4667351',
351 'title': 'Nataly Hot',
353 'playlist_mincount': 2,
355 'url': 'https://de.pornhub.com/playlist/4667351',
356 'only_matching': True,
360 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
361 _VALID_URL = r'https?://(?:[^/]+\.)?pornhub\.(?:com|net)/(?:(?:user|channel)s|model|pornstar)/(?P<id>[^/]+)/videos'
363 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
367 'playlist_mincount': 171,
369 'url': 'http://www.pornhub.com/users/rushandlia/videos',
370 'only_matching': True,
372 # default sorting as Top Rated Videos
373 'url': 'https://www.pornhub.com/channels/povd/videos',
377 'playlist_mincount': 293,
380 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
381 'only_matching': True,
384 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
385 'only_matching': True,
388 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
389 'only_matching': True,
391 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
392 'only_matching': True,
394 'url': 'https://www.pornhub.com/model/jayndrea/videos/upload',
395 'only_matching': True,
397 'url': 'https://www.pornhub.com/pornstar/jenny-blighe/videos/upload',
398 'only_matching': True,
401 def _real_extract(self, url):
402 user_id = self._match_id(url)
405 for page_num in itertools.count(1):
407 webpage = self._download_webpage(
408 url, user_id, 'Downloading page %d' % page_num,
409 query={'page': page_num})
410 except ExtractorError as e:
411 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
414 page_entries = self._extract_entries(webpage)
417 entries.extend(page_entries)
419 return self.playlist_result(entries, user_id)