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,
30 class PornHubIE(InfoExtractor):
31 IE_DESC = 'PornHub and Thumbzilla'
35 (?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)|
36 (?:www\.)?thumbzilla\.com/video/
41 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
42 'md5': '1e19b41231a02eba417839222ac9d58e',
46 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
59 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
64 'uploader': 'cj397186295',
75 'skip_download': True,
78 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
79 'only_matching': True,
81 # removed at the request of cam4.com
82 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
83 'only_matching': True,
85 # removed at the request of the copyright owner
86 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
87 'only_matching': True,
90 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
91 'only_matching': True,
94 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
95 'only_matching': True,
97 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
98 'only_matching': True,
102 def _extract_urls(webpage):
104 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/[\da-z]+)',
107 def _extract_count(self, pattern, webpage, name):
108 return str_to_int(self._search_regex(
109 pattern, webpage, '%s count' % name, fatal=False))
111 def _real_extract(self, url):
112 video_id = self._match_id(url)
114 def dl_webpage(platform):
115 return self._download_webpage(
116 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id,
118 'Cookie': 'age_verified=1; platform=%s' % platform,
121 webpage = dl_webpage('pc')
123 error_msg = self._html_search_regex(
124 r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
125 webpage, 'error message', default=None, group='error')
127 error_msg = re.sub(r'\s+', ' ', error_msg)
128 raise ExtractorError(
129 'PornHub said: %s' % error_msg,
130 expected=True, video_id=video_id)
132 tv_webpage = dl_webpage('tv')
134 encoded_url = self._search_regex(r'(var.*mediastring.*)</script>',
135 tv_webpage, 'encoded url')
136 assignments = encoded_url.split(";")
139 def parse_js_value(inp):
140 inp = re.sub(r'/\*[^*]*\*/', "", inp)
143 inps = inp.split("+")
144 return functools.reduce(operator.concat, map(parse_js_value, inps))
150 # Hope it's a string!
151 assert inp.startswith('"') and inp.endswith('"')
154 for assn in assignments:
159 assert assn.startswith("var ")
161 vname, value = assn.split("=", 1)
163 js_vars[vname] = parse_js_value(value)
165 video_url = js_vars["mediastring"]
167 title = self._search_regex(
168 r'<h1>([^>]+)</h1>', tv_webpage, 'title', default=None)
170 # video_title from flashvars contains whitespace instead of non-ASCII (see
171 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
173 title = title or self._html_search_meta(
174 'twitter:title', webpage, default=None) or self._search_regex(
175 (r'<h1[^>]+class=["\']title["\'][^>]*>(?P<title>[^<]+)',
176 r'<div[^>]+data-video-title=(["\'])(?P<title>.+?)\1',
177 r'shareTitle\s*=\s*(["\'])(?P<title>.+?)\1'),
178 webpage, 'title', group='title')
180 flashvars = self._parse_json(
182 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
185 thumbnail = flashvars.get('image_url')
186 duration = int_or_none(flashvars.get('video_duration'))
188 title, thumbnail, duration = [None] * 3
190 video_uploader = self._html_search_regex(
191 r'(?s)From: .+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
192 webpage, 'uploader', fatal=False)
194 view_count = self._extract_count(
195 r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
196 like_count = self._extract_count(
197 r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
198 dislike_count = self._extract_count(
199 r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
200 comment_count = self._extract_count(
201 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
203 page_params = self._parse_json(self._search_regex(
204 r'page_params\.zoneDetails\[([\'"])[^\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
205 webpage, 'page parameters', group='data', default='{}'),
206 video_id, transform_source=js_to_json, fatal=False)
207 tags = categories = None
209 tags = page_params.get('tags', '').split(',')
210 categories = page_params.get('categories', '').split(',')
215 'uploader': video_uploader,
217 'thumbnail': thumbnail,
218 'duration': duration,
219 'view_count': view_count,
220 'like_count': like_count,
221 'dislike_count': dislike_count,
222 'comment_count': comment_count,
223 # 'formats': formats,
226 'categories': categories,
230 class PornHubPlaylistBaseIE(InfoExtractor):
231 def _extract_entries(self, webpage):
234 'http://www.pornhub.com/%s' % video_url,
235 PornHubIE.ie_key(), video_title=title)
236 for video_url, title in orderedSet(re.findall(
237 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
241 def _real_extract(self, url):
242 playlist_id = self._match_id(url)
244 webpage = self._download_webpage(url, playlist_id)
246 # Only process container div with main playlist content skipping
247 # drop-down menu that uses similar pattern for videos (see
248 # https://github.com/rg3/youtube-dl/issues/11594).
249 container = self._search_regex(
250 r'(?s)(<div[^>]+class=["\']container.+)', webpage,
251 'container', default=webpage)
253 entries = self._extract_entries(container)
255 playlist = self._parse_json(
257 r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
260 return self.playlist_result(
261 entries, playlist_id, playlist.get('title'), playlist.get('description'))
264 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
265 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
267 'url': 'http://www.pornhub.com/playlist/4667351',
270 'title': 'Nataly Hot',
272 'playlist_mincount': 2,
276 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
277 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
279 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
283 'playlist_mincount': 171,
285 'url': 'http://www.pornhub.com/users/rushandlia/videos',
286 'only_matching': True,
289 def _real_extract(self, url):
290 user_id = self._match_id(url)
293 for page_num in itertools.count(1):
295 webpage = self._download_webpage(
296 url, user_id, 'Downloading page %d' % page_num,
297 query={'page': page_num})
298 except ExtractorError as e:
299 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
301 page_entries = self._extract_entries(webpage)
304 entries.extend(page_entries)
306 return self.playlist_result(entries, user_id)