2 from __future__ import unicode_literals
10 from .common import InfoExtractor
11 from ..compat import (
13 # compat_urllib_parse_unquote,
14 # compat_urllib_parse_unquote_plus,
15 # compat_urllib_parse_urlparse,
31 class PornHubIE(InfoExtractor):
32 IE_DESC = 'PornHub and Thumbzilla'
36 (?:[a-z]+\.)?pornhub\.com/(?:(?:view_video\.php|video/show)\?viewkey=|embed/)|
37 (?:www\.)?thumbzilla\.com/video/
42 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
43 'md5': '1e19b41231a02eba417839222ac9d58e',
47 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
60 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
65 'uploader': 'cj397186295',
76 'skip_download': True,
79 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
80 'only_matching': True,
82 # removed at the request of cam4.com
83 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
84 'only_matching': True,
86 # removed at the request of the copyright owner
87 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
88 'only_matching': True,
91 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
92 'only_matching': True,
95 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
96 'only_matching': True,
98 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
99 'only_matching': True,
101 'url': 'http://www.pornhub.com/video/show?viewkey=648719015',
102 'only_matching': True,
106 def _extract_urls(webpage):
108 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/[\da-z]+)',
111 def _extract_count(self, pattern, webpage, name):
112 return str_to_int(self._search_regex(
113 pattern, webpage, '%s count' % name, fatal=False))
115 def _real_extract(self, url):
116 video_id = self._match_id(url)
118 self._set_cookie('pornhub.com', 'age_verified', '1')
120 def dl_webpage(platform):
121 self._set_cookie('pornhub.com', 'platform', platform)
122 return self._download_webpage(
123 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id,
126 webpage = dl_webpage('pc')
128 error_msg = self._html_search_regex(
129 r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
130 webpage, 'error message', default=None, group='error')
132 error_msg = re.sub(r'\s+', ' ', error_msg)
133 raise ExtractorError(
134 'PornHub said: %s' % error_msg,
135 expected=True, video_id=video_id)
137 tv_webpage = dl_webpage('tv')
139 assignments = self._search_regex(
140 r'(var.+?mediastring.+?)</script>', tv_webpage,
141 'encoded url').split(';')
145 def parse_js_value(inp):
146 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
148 inps = inp.split('+')
149 return functools.reduce(
150 operator.concat, map(parse_js_value, inps))
154 return remove_quotes(inp)
156 for assn in assignments:
160 assn = re.sub(r'var\s+', '', assn)
161 vname, value = assn.split('=', 1)
162 js_vars[vname] = parse_js_value(value)
164 video_url = js_vars['mediastring']
166 title = self._search_regex(
167 r'<h1>([^>]+)</h1>', tv_webpage, 'title', default=None)
169 # video_title from flashvars contains whitespace instead of non-ASCII (see
170 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
172 title = title or self._html_search_meta(
173 'twitter:title', webpage, default=None) or self._search_regex(
174 (r'<h1[^>]+class=["\']title["\'][^>]*>(?P<title>[^<]+)',
175 r'<div[^>]+data-video-title=(["\'])(?P<title>.+?)\1',
176 r'shareTitle\s*=\s*(["\'])(?P<title>.+?)\1'),
177 webpage, 'title', group='title')
179 flashvars = self._parse_json(
181 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
184 thumbnail = flashvars.get('image_url')
185 duration = int_or_none(flashvars.get('video_duration'))
187 title, thumbnail, duration = [None] * 3
189 video_uploader = self._html_search_regex(
190 r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?:user|channel)s/|span\b[^>]+\bclass=["\']username)[^>]+>(.+?)<',
191 webpage, 'uploader', fatal=False)
193 view_count = self._extract_count(
194 r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
195 like_count = self._extract_count(
196 r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
197 dislike_count = self._extract_count(
198 r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
199 comment_count = self._extract_count(
200 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
202 page_params = self._parse_json(self._search_regex(
203 r'page_params\.zoneDetails\[([\'"])[^\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
204 webpage, 'page parameters', group='data', default='{}'),
205 video_id, transform_source=js_to_json, fatal=False)
206 tags = categories = None
208 tags = page_params.get('tags', '').split(',')
209 categories = page_params.get('categories', '').split(',')
214 'uploader': video_uploader,
216 'thumbnail': thumbnail,
217 'duration': duration,
218 'view_count': view_count,
219 'like_count': like_count,
220 'dislike_count': dislike_count,
221 'comment_count': comment_count,
222 # 'formats': formats,
225 'categories': categories,
229 class PornHubPlaylistBaseIE(InfoExtractor):
230 def _extract_entries(self, webpage):
231 # Only process container div with main playlist content skipping
232 # drop-down menu that uses similar pattern for videos (see
233 # https://github.com/rg3/youtube-dl/issues/11594).
234 container = self._search_regex(
235 r'(?s)(<div[^>]+class=["\']container.+)', webpage,
236 'container', default=webpage)
240 'http://www.pornhub.com/%s' % video_url,
241 PornHubIE.ie_key(), video_title=title)
242 for video_url, title in orderedSet(re.findall(
243 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
247 def _real_extract(self, url):
248 playlist_id = self._match_id(url)
250 webpage = self._download_webpage(url, playlist_id)
252 entries = self._extract_entries(webpage)
254 playlist = self._parse_json(
256 r'(?:playlistObject|PLAYLIST_VIEW)\s*=\s*({.+?});', webpage,
257 'playlist', default='{}'),
258 playlist_id, fatal=False)
259 title = playlist.get('title') or self._search_regex(
260 r'>Videos\s+in\s+(.+?)\s+[Pp]laylist<', webpage, 'title', fatal=False)
262 return self.playlist_result(
263 entries, playlist_id, title, playlist.get('description'))
266 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
267 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
269 'url': 'http://www.pornhub.com/playlist/4667351',
272 'title': 'Nataly Hot',
274 'playlist_mincount': 2,
278 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
279 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/(?:user|channel)s/(?P<id>[^/]+)/videos'
281 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
285 'playlist_mincount': 171,
287 'url': 'http://www.pornhub.com/users/rushandlia/videos',
288 'only_matching': True,
290 # default sorting as Top Rated Videos
291 'url': 'https://www.pornhub.com/channels/povd/videos',
295 'playlist_mincount': 293,
298 'url': 'https://www.pornhub.com/channels/povd/videos?o=ra',
299 'only_matching': True,
302 'url': 'https://www.pornhub.com/channels/povd/videos?o=da',
303 'only_matching': True,
306 'url': 'https://www.pornhub.com/channels/povd/videos?o=vi',
307 'only_matching': True,
310 def _real_extract(self, url):
311 user_id = self._match_id(url)
314 for page_num in itertools.count(1):
316 webpage = self._download_webpage(
317 url, user_id, 'Downloading page %d' % page_num,
318 query={'page': page_num})
319 except ExtractorError as e:
320 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
323 page_entries = self._extract_entries(webpage)
326 entries.extend(page_entries)
328 return self.playlist_result(entries, user_id)