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 (?:[^/]+\.)?(?P<host>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|net
)/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 mobj = re.match(self._VALID_URL, url)
141 host = mobj.group('host
') or 'pornhub
.com
'
142 video_id = mobj.group('id')
144 self._set_cookie(host, 'age_verified
', '1')
146 def dl_webpage(platform):
147 self._set_cookie(host, 'platform
', platform)
148 return self._download_webpage(
149 'http
://www
.%s/view_video
.php?viewkey
=%s' % (host, video_id),
150 video_id, 'Downloading
%s webpage
' % platform)
152 webpage = dl_webpage('pc
')
154 error_msg = self._html_search_regex(
155 r'(?s
)<div
[^
>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
156 webpage, 'error message', default=None, group='error')
158 error_msg = re.sub(r'\s+', ' ', error_msg)
159 raise ExtractorError(
160 'PornHub said: %s' % error_msg,
161 expected=True, video_id=video_id)
163 # video_title from flashvars contains whitespace instead of non-ASCII (see
164 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
166 title = self._html_search_meta(
167 'twitter:title', webpage, default=None) or self._search_regex(
168 (r'<h1[^>]+class=["\']title
["\'][^>]*>(?P<title>[^<]+)',
169 r'<div[^>]+data-video-title=(["\'])(?P
<title
>.+?
)\
1',
170 r'shareTitle\s
*=\s
*(["\'])(?P<title>.+?)\1'),
171 webpage, 'title', group='title')
174 video_urls_set = set()
177 flashvars = self._parse_json(
179 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
182 subtitle_url = url_or_none(flashvars.get('closedCaptionsFile'))
184 subtitles.setdefault('en', []).append({
188 thumbnail = flashvars.get('image_url')
189 duration = int_or_none(flashvars.get('video_duration'))
190 media_definitions = flashvars.get('mediaDefinitions')
191 if isinstance(media_definitions, list):
192 for definition in media_definitions:
193 if not isinstance(definition, dict):
195 video_url = definition.get('videoUrl')
196 if not video_url or not isinstance(video_url, compat_str):
198 if video_url in video_urls_set:
200 video_urls_set.add(video_url)
202 (video_url, int_or_none(definition.get('quality'))))
204 thumbnail, duration = [None] * 2
207 tv_webpage = dl_webpage('tv')
209 assignments = self._search_regex(
210 r'(var.+?mediastring.+?)</script>', tv_webpage,
211 'encoded url').split(';')
215 def parse_js_value(inp):
216 inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
218 inps = inp.split('+')
219 return functools.reduce(
220 operator.concat, map(parse_js_value, inps))
224 return remove_quotes(inp)
226 for assn in assignments:
230 assn = re.sub(r'var\s+', '', assn)
231 vname, value = assn.split('=', 1)
232 js_vars[vname] = parse_js_value(value)
234 video_url = js_vars['mediastring']
235 if video_url not in video_urls_set:
236 video_urls.append((video_url, None))
237 video_urls_set.add(video_url)
239 for mobj in re.finditer(
240 r'<a[^>]+\bclass=["\']downloadBtn
\b[^
>]+\bhref
=(["\'])(?P<url>(?:(?!\1).)+)\1',
242 video_url = mobj.group('url')
243 if video_url not in video_urls_set:
244 video_urls.append((video_url, None))
245 video_urls_set.add(video_url)
249 for video_url, height in video_urls:
251 upload_date = self._search_regex(
252 r'/(\d{6}/\d{2})/', video_url, 'upload data', default=None)
254 upload_date = upload_date.replace('/', '')
256 mobj = re.search(r'(?P<height>\d+)[pP]?_(?P<tbr>\d+)[kK]', video_url)
259 height = int(mobj.group('height'))
260 tbr = int(mobj.group('tbr'))
263 'format_id': '%dp' % height if height else None,
267 self._sort_formats(formats)
269 video_uploader = self._html_search_regex(
270 r'(?s)From: .+?<(?:a\b[^>]+\bhref=["\']/(?
:(?
:user|channel
)s|model|pornstar
)/|span
\b[^
>]+\bclass
=["\']username)[^>]+>(.+?)<',
271 webpage, 'uploader', fatal=False)
273 view_count = self._extract_count(
274 r'<span class="count
">([\d,\.]+)</span> views', webpage, 'view')
275 like_count = self._extract_count(
276 r'<span class="votesUp
">([\d,\.]+)</span>', webpage, 'like')
277 dislike_count = self._extract_count(
278 r'<span class="votesDown
">([\d,\.]+)</span>', webpage, 'dislike')
279 comment_count = self._extract_count(
280 r'All Comments\s*<span>\(([\d,.]+)\)', webpage, 'comment')
282 page_params = self._parse_json(self._search_regex(
283 r'page_params\.zoneDetails\[([\'"])[^
\'"]+\1\]\s*=\s*(?P<data>{[^}]+})',
284 webpage, 'page parameters', group='data', default='{}'),
285 video_id, transform_source=js_to_json, fatal=False)
286 tags = categories = None
288 tags = page_params.get('tags', '').split(',')
289 categories = page_params.get('categories', '').split(',')
293 'uploader': video_uploader,
294 'upload_date': upload_date,
296 'thumbnail': thumbnail,
297 'duration': duration,
298 'view_count': view_count,
299 'like_count': like_count,
300 'dislike_count': dislike_count,
301 'comment_count': comment_count,
305 'categories': categories,
306 'subtitles': subtitles,
310 class PornHubPlaylistBaseIE(InfoExtractor):
311 def _extract_entries(self, webpage, host):
312 # Only process container div with main playlist content skipping
313 # drop-down menu that uses similar pattern for videos (see
314 # https://github.com/rg3/youtube-dl/issues/11594).
315 container = self._search_regex(
316 r'(?s)(<div[^>]+class=["\']container
.+)', webpage,
317 'container
', default=webpage)
321 'http
://www
.%s/%s' % (host, video_url),
322 PornHubIE.ie_key(), video_title=title)
323 for video_url, title in orderedSet(re.findall(
324 r'href
="/?(view_video\.php\?.*\bviewkey=[\da-z]+[^"]*)"[^>]*\s+title="([^
"]+)"',
328 def _real_extract(self, url):
329 mobj = re.match(self._VALID_URL, url)
330 host = mobj.group('host
')
331 playlist_id = mobj.group('id')
333 webpage = self._download_webpage(url, playlist_id)
335 entries = self._extract_entries(webpage, host)
337 playlist = self._parse_json(
339 r'(?
:playlistObject|PLAYLIST_VIEW
)\s
*=\s
*({.+?
});', webpage,
340 'playlist
', default='{}'),
341 playlist_id, fatal=False)
342 title = playlist.get('title
') or self._search_regex(
343 r'>Videos\s
+in\s
+(.+?
)\s
+[Pp
]laylist
<', webpage, 'title
', fatal=False)
345 return self.playlist_result(
346 entries, playlist_id, title, playlist.get('description
'))
349 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
350 _VALID_URL = r'https?
://(?
:[^
/]+\
.)?
(?P
<host
>pornhub\
.(?
:com|net
))/playlist
/(?P
<id>\d
+)'
352 'url
': 'http
://www
.pornhub
.com
/playlist
/4667351',
355 'title
': 'Nataly Hot
',
357 'playlist_mincount
': 2,
359 'url
': 'https
://de
.pornhub
.com
/playlist
/4667351',
360 'only_matching
': True,
364 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
365 _VALID_URL = r'https?
://(?
:[^
/]+\
.)?
(?P
<host
>pornhub\
.(?
:com|net
))/(?
:(?
:user|channel
)s|model|pornstar
)/(?P
<id>[^
/]+)/videos
'
367 'url
': 'http
://www
.pornhub
.com
/users
/zoe_ph
/videos
/public
',
371 'playlist_mincount
': 171,
373 'url
': 'http
://www
.pornhub
.com
/users
/rushandlia
/videos
',
374 'only_matching
': True,
376 # default sorting as Top Rated Videos
377 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos
',
381 'playlist_mincount
': 293,
384 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos?o
=ra
',
385 'only_matching
': True,
388 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos?o
=da
',
389 'only_matching
': True,
392 'url
': 'https
://www
.pornhub
.com
/channels
/povd
/videos?o
=vi
',
393 'only_matching
': True,
395 'url
': 'http
://www
.pornhub
.com
/users
/zoe_ph
/videos
/public
',
396 'only_matching
': True,
398 'url
': 'https
://www
.pornhub
.com
/model
/jayndrea
/videos
/upload
',
399 'only_matching
': True,
401 'url
': 'https
://www
.pornhub
.com
/pornstar
/jenny
-blighe
/videos
/upload
',
402 'only_matching
': True,
405 def _real_extract(self, url):
406 mobj = re.match(self._VALID_URL, url)
407 host = mobj.group('host
')
408 user_id = mobj.group('id')
411 for page_num in itertools.count(1):
413 webpage = self._download_webpage(
414 url, user_id, 'Downloading page
%d' % page_num,
415 query={'page
': page_num})
416 except ExtractorError as e:
417 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
420 page_entries = self._extract_entries(webpage, host)
423 entries.extend(page_entries)
425 return self.playlist_result(entries, user_id)