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/(?:(?: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',
54 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
59 'uploader': 'Unknown',
70 'skip_download': True,
74 'url': 'https://www.pornhub.com/view_video.php?viewkey=ph5af5fef7c2aa7',
76 'id': 'ph5af5fef7c2aa7',
78 'title': 'BFFS - Cute Teen Girls Share Cock On the Floor',
95 'skip_download': True,
98 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
99 'only_matching': True,
101 # removed at the request of cam4.com
102 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
103 'only_matching': True,
105 # removed at the request of the copyright owner
106 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
107 'only_matching': True,
109 # removed by uploader
110 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
111 'only_matching': True,
114 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
115 'only_matching': True,
117 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
118 'only_matching': True,
120 'url': 'http://www.pornhub.com/video/show?viewkey=648719015',
121 'only_matching': True,
125 def _extract_urls(webpage
):
127 r
'<iframe[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.com
/embed
/[\da
-z
]+)',
130 def _extract_count(self, pattern, webpage, name):
131 return str_to_int(self._search_regex(
132 pattern, webpage, '%s count
' % name, fatal=False))
134 def _real_extract(self, url):
135 video_id = self._match_id(url)
137 self._set_cookie('pornhub
.com
', 'age_verified
', '1')
139 def dl_webpage(platform):
140 self._set_cookie('pornhub
.com
', 'platform
', platform)
141 return self._download_webpage(
142 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=%s' % video_id,
143 video_id, 'Downloading
%s webpage
' % platform)
145 webpage = dl_webpage('pc
')
147 error_msg = self._html_search_regex(
148 r'(?s
)<div
[^
>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
149 webpage, 'error message', default=None, group='error')
151 error_msg = re.sub(r'\s+', ' ', error_msg)
152 raise ExtractorError(
153 'PornHub said: %s' % error_msg,
154 expected=True, video_id=video_id)
156 # video_title from flashvars contains whitespace instead of non-ASCII (see
157 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
159 title = self._html_search_meta(
160 'twitter:title', webpage, default=None) or self._search_regex(
161 (r'<h1[^>]+class=["\']title
["\'][^>]*>(?P<title>[^<]+)',
162 r'<div[^>]+data-video-title=(["\'])(?P
<title
>.+?
)\
1',
163 r'shareTitle\s
*=\s
*(["\'])(?P<title>.+?)\1'),
164 webpage, 'title', group='title')
167 video_urls_set = set()
170 flashvars = self._parse_json(
172 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
175 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
177 subtitles.setdefault('en', []).append({
181 thumbnail = flashvars.get('image_url')
182 duration = int_or_none(flashvars.get('video_duration'))
183 media_definitions = flashvars.get('mediaDefinitions')
184 if isinstance(media_definitions, list):
185 for definition in media_definitions:
186 if not isinstance(definition, dict):
188 video_url = definition.get('videoUrl')
189 if not video_url or not isinstance(video_url, compat_str):
191 if video_url in video_urls_set:
193 video_urls_set.add(video_url)
195 (video_url, int_or_none(definition.get('quality'))))
197 thumbnail, duration = [None] * 2
200 tv_webpage = dl_webpage('tv')
202 assignments = self._search_regex(
203 r'(var.+?mediastring.+?)</script>', tv_webpage,
204 'encoded url').split(';')
208 def parse_js_value(inp):
209 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
211 inps = inp.split('+')
212 return functools.reduce(
213 operator.concat, map(parse_js_value, inps))
217 return remove_quotes(inp)
219 for assn in assignments:
223 assn = re.sub(r'var\s+', '', assn)
224 vname, value = assn.split('=', 1)
225 js_vars[vname] = parse_js_value(value)
227 video_url = js_vars['mediastring']
228 if video_url not in video_urls_set:
229 video_urls.append((video_url, None))
230 video_urls_set.add(video_url)
232 for mobj in re.finditer(
233 r'<a[^>]+\bclass=["\']downloadBtn
\b[^
>]+\bhref
=(["\'])(?P<url>(?:(?!\1).)+)\1',
235 video_url = mobj.group('url')
236 if video_url not in video_urls_set:
237 video_urls.append((video_url, None))
238 video_urls_set.add(video_url)
241 for video_url, height in video_urls:
243 mobj = re.search(r'(?P<height>\d+)[pP]?_(?P<tbr>\d+)[kK]', video_url)
246 height = int(mobj.group('height'))
247 tbr = int(mobj.group('tbr'))
250 'format_id': '%dp' % height if height else None,
254 self._sort_formats(formats)
256 video_uploader = self._html_search_regex(
257 r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?
:(?
:user|channel
)s|model|pornstar
)/|span
\b[^
>]+\bclass
=["\']username)[^>]+>(.+?)<',
258 webpage, 'uploader', fatal=False)
260 view_count = self._extract_count(
261 r'<span class="count
">([\d,\.]+)</span> views', webpage, 'view')
262 like_count = self._extract_count(
263 r'<span class="votesUp
">([\d,\.]+)</span>', webpage, 'like')
264 dislike_count = self._extract_count(
265 r'<span class="votesDown
">([\d,\.]+)</span>', webpage, 'dislike')
266 comment_count = self._extract_count(
267 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
269 page_params = self._parse_json(self._search_regex(
270 r'page_params\.zoneDetails\[([\'"])[^
\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
271 webpage, 'page parameters', group='data', default='{}'),
272 video_id, transform_source=js_to_json, fatal=False)
273 tags = categories = None
275 tags = page_params.get('tags', '').split(',')
276 categories = page_params.get('categories', '').split(',')
280 'uploader': video_uploader,
282 'thumbnail': thumbnail,
283 'duration': duration,
284 'view_count': view_count,
285 'like_count': like_count,
286 'dislike_count': dislike_count,
287 'comment_count': comment_count,
291 'categories': categories,
292 'subtitles': subtitles,
296 class PornHubPlaylistBaseIE(InfoExtractor):
297 def _extract_entries(self, webpage):
298 # Only process container div with main playlist content skipping
299 # drop-down menu that uses similar pattern for videos (see
300 # https://github.com/rg3/youtube-dl/issues/11594).
301 container = self._search_regex(
302 r'(?s)(<div[^>]+class=["\']container
.+)', webpage,
303 'container
', default=webpage)
307 'http
://www
.pornhub
.com
/%s' % video_url,
308 PornHubIE.ie_key(), video_title=title)
309 for video_url, title in orderedSet(re.findall(
310 r'href
="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^
"]+)"',
314 def _real_extract(self, url):
315 playlist_id = self._match_id(url)
317 webpage = self._download_webpage(url, playlist_id)
319 entries = self._extract_entries(webpage)
321 playlist = self._parse_json(
323 r'(?
:playlistObject|PLAYLIST_VIEW
)\s
*=\s
*({.+?
});', webpage,
324 'playlist
', default='{}'),
325 playlist_id, fatal=False)
326 title = playlist.get('title
') or self._search_regex(
327 r'>Videos\s
+in\s
+(.+?
)\s
+[Pp
]laylist
<', webpage, 'title
', fatal=False)
329 return self.playlist_result(
330 entries, playlist_id, title, playlist.get('description
'))
333 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
334 _VALID_URL = r'https?
://(?
:[^
/]+\
.)?pornhub\
.com
/playlist
/(?P
<id>\d
+)'
336 'url
': 'http
://www
.pornhub
.com
/playlist
/4667351',
339 'title
': 'Nataly Hot
',
341 'playlist_mincount
': 2,
343 'url
': 'https
://de
.pornhub
.com
/playlist
/4667351',
344 'only_matching
': True,
348 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
349 _VALID_URL = r'https?
://(?
:[^
/]+\
.)?pornhub\
.com
/(?
:(?
:user|channel
)s|model|pornstar
)/(?P
<id>[^
/]+)/videos
'
351 'url
': 'http
://www
.pornhub
.com
/users
/zoe_ph
/videos
/public
',
355 'playlist_mincount
': 171,
357 'url
': 'http
://www
.pornhub
.com
/users
/rushandlia
/videos
',
358 'only_matching
': True,
360 # default sorting as Top Rated Videos
361 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos
',
365 'playlist_mincount
': 293,
368 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos?o
=ra
',
369 'only_matching
': True,
372 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos?o
=da
',
373 'only_matching
': True,
376 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos?o
=vi
',
377 'only_matching
': True,
379 'url
': 'http
://www
.pornhub
.com
/users
/zoe_ph
/videos
/public
',
380 'only_matching
': True,
382 'url
': 'https
://www
.pornhub
.com
/model
/jayndrea
/videos
/upload
',
383 'only_matching
': True,
385 'url
': 'https
://www
.pornhub
.com
/pornstar
/jenny
-blighe
/videos
/upload
',
386 'only_matching
': True,
389 def _real_extract(self, url):
390 user_id = self._match_id(url)
393 for page_num in itertools.count(1):
395 webpage = self._download_webpage(
396 url, user_id, 'Downloading page
%d' % page_num,
397 query={'page
': page_num})
398 except ExtractorError as e:
399 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
402 page_entries = self._extract_entries(webpage)
405 entries.extend(page_entries)
407 return self.playlist_result(entries, user_id)