2 from __future__ import unicode_literals
8 from .common import InfoExtractor
11 compat_urllib_parse_unquote,
12 compat_urllib_parse_unquote_plus,
13 compat_urllib_parse_urlparse,
28 class PornHubIE(InfoExtractor):
29 IE_DESC = 'PornHub and Thumbzilla'
33 (?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)|
34 (?:www\.)?thumbzilla\.com/video/
39 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
40 'md5': '1e19b41231a02eba417839222ac9d58e',
44 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
57 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
62 'uploader': 'cj397186295',
73 'skip_download': True,
76 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
77 'only_matching': True,
79 # removed at the request of cam4.com
80 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
81 'only_matching': True,
83 # removed at the request of the copyright owner
84 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
85 'only_matching': True,
88 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
89 'only_matching': True,
92 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
93 'only_matching': True,
95 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
96 'only_matching': True,
100 def _extract_urls(webpage):
102 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?pornhub\.com/embed/[\da-z]+)',
105 def _extract_count(self, pattern, webpage, name):
106 return str_to_int(self._search_regex(
107 pattern, webpage, '%s count' % name, fatal=False))
109 def _real_extract(self, url):
110 video_id = self._match_id(url)
112 req = sanitized_Request(
113 'http://www.pornhub.com/view_video.php?viewkey=%s' % video_id)
114 req.add_header('Cookie', 'age_verified=1')
115 webpage = self._download_webpage(req, video_id)
117 error_msg = self._html_search_regex(
118 r'(?s)<div[^>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
119 webpage, 'error message', default=None, group='error')
121 error_msg = re.sub(r'\s+', ' ', error_msg)
122 raise ExtractorError(
123 'PornHub said: %s' % error_msg,
124 expected=True, video_id=video_id)
126 # video_title from flashvars contains whitespace instead of non-ASCII (see
127 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
129 title = self._html_search_meta(
130 'twitter:title', webpage, default=None) or self._search_regex(
131 (r'<h1[^>]+class=["\']title["\'][^>]*>(?P<title>[^<]+)',
132 r'<div[^>]+data-video-title=(["\'])(?P<title>.+?)\1',
133 r'shareTitle\s*=\s*(["\'])(?P<title>.+?)\1'),
134 webpage, 'title', group='title')
136 flashvars = self._parse_json(
138 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
141 thumbnail = flashvars.get('image_url')
142 duration = int_or_none(flashvars.get('video_duration'))
144 title, thumbnail, duration = [None] * 3
146 video_uploader = self._html_search_regex(
147 r'(?s)From: .+?<(?:a href="/users/|a href="/channels/|span class="username)[^>]+>(.+?)<',
148 webpage, 'uploader', fatal=False)
150 view_count = self._extract_count(
151 r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
152 like_count = self._extract_count(
153 r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
154 dislike_count = self._extract_count(
155 r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
156 comment_count = self._extract_count(
157 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
160 for video_variablename, quote, video_variable in re.findall(
161 r'(player_quality_[0-9]{3,4}p[0-9a-z]+?)=\s*(["\'])(.*?)\2;', webpage):
162 video_variables[video_variablename] = video_variable
164 encoded_video_urls = []
165 for encoded_video_url in re.findall(
166 r'player_quality_[0-9]{3,4}p\s*=(.*?);', webpage):
167 encoded_video_urls.append(encoded_video_url)
171 for url in encoded_video_urls:
172 for varname, varval in video_variables.items():
173 url = url.replace(varname, varval)
174 url = url.replace('+', '')
175 url = url.replace(' ', '')
176 video_urls.append(url)
178 if webpage.find('"encrypted":true') != -1:
179 password = compat_urllib_parse_unquote_plus(
180 self._search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
181 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
184 for video_url in video_urls:
185 path = compat_urllib_parse_urlparse(video_url).path
186 extension = os.path.splitext(path)[1][1:]
187 format = path.split('/')[5].split('_')[:2]
188 format = '-'.join(format)
190 m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
195 height = int(m.group('height'))
196 tbr = int(m.group('tbr'))
206 self._sort_formats(formats)
208 page_params = self._parse_json(self._search_regex(
209 r'page_params\.zoneDetails\[([\'"])[^\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
210 webpage, 'page parameters', group='data', default='{}'),
211 video_id, transform_source=js_to_json, fatal=False)
212 tags = categories = None
214 tags = page_params.get('tags', '').split(',')
215 categories = page_params.get('categories', '').split(',')
219 'uploader': video_uploader,
221 'thumbnail': thumbnail,
222 'duration': duration,
223 'view_count': view_count,
224 'like_count': like_count,
225 'dislike_count': dislike_count,
226 'comment_count': comment_count,
230 'categories': categories,
234 class PornHubPlaylistBaseIE(InfoExtractor):
235 def _extract_entries(self, webpage):
238 'http://www.pornhub.com/%s' % video_url,
239 PornHubIE.ie_key(), video_title=title)
240 for video_url, title in orderedSet(re.findall(
241 r'href="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^"]+)"',
245 def _real_extract(self, url):
246 playlist_id = self._match_id(url)
248 webpage = self._download_webpage(url, playlist_id)
250 # Only process container div with main playlist content skipping
251 # drop-down menu that uses similar pattern for videos (see
252 # https://github.com/rg3/youtube-dl/issues/11594).
253 container = self._search_regex(
254 r'(?s)(<div[^>]+class=["\']container.+)', webpage,
255 'container', default=webpage)
257 entries = self._extract_entries(container)
259 playlist = self._parse_json(
261 r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
264 return self.playlist_result(
265 entries, playlist_id, playlist.get('title'), playlist.get('description'))
268 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
269 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
271 'url': 'http://www.pornhub.com/playlist/4667351',
274 'title': 'Nataly Hot',
276 'playlist_mincount': 2,
280 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
281 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
283 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
287 'playlist_mincount': 171,
289 'url': 'http://www.pornhub.com/users/rushandlia/videos',
290 'only_matching': True,
293 def _real_extract(self, url):
294 user_id = self._match_id(url)
297 for page_num in itertools.count(1):
299 webpage = self._download_webpage(
300 url, user_id, 'Downloading page %d' % page_num,
301 query={'page': page_num})
302 except ExtractorError as e:
303 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
305 page_entries = self._extract_entries(webpage)
308 entries.extend(page_entries)
310 return self.playlist_result(entries, user_id)