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
,
27 class PornHubIE(InfoExtractor
):
28 IE_DESC
= 'PornHub and Thumbzilla'
32 (?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)|
33 (?:www\.)?thumbzilla\.com/video/
38 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
39 'md5': '1e19b41231a02eba417839222ac9d58e',
43 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
54 'url': 'http://www.pornhub.com/view_video.php?viewkey=1331683002',
59 'uploader': 'cj397186295',
68 'skip_download': True,
71 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
72 'only_matching': True,
74 # removed at the request of cam4.com
75 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
76 'only_matching': True,
78 # removed at the request of the copyright owner
79 'url': 'http://www.pornhub.com/view_video.php?viewkey=788152859',
80 'only_matching': True,
83 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph572716d15a111',
84 'only_matching': True,
86 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
87 'only_matching': True,
91 def _extract_url(cls
, webpage
):
93 r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.com
/embed
/\d
+)\
1', webpage)
95 return mobj.group('url
')
97 def _extract_count(self, pattern, webpage, name):
98 return str_to_int(self._search_regex(
99 pattern, webpage, '%s count
' % name, fatal=False))
101 def _real_extract(self, url):
102 video_id = self._match_id(url)
104 req = sanitized_Request(
105 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=%s' % video_id)
106 req.add_header('Cookie
', 'age_verified
=1')
107 webpage = self._download_webpage(req, video_id)
109 error_msg = self._html_search_regex(
110 r'(?s
)<div
[^
>]+class=(["\']).*?\bremoved\b.*?\1[^>]*>(?P<error>.+?)</div>',
111 webpage, 'error message', default=None, group='error')
113 error_msg = re.sub(r'\s+', ' ', error_msg)
114 raise ExtractorError(
115 'PornHub said: %s' % error_msg,
116 expected=True, video_id=video_id)
118 # video_title from flashvars contains whitespace instead of non-ASCII (see
119 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
121 title = self._html_search_meta(
122 'twitter:title', webpage, default=None) or self._search_regex(
123 (r'<h1[^>]+class=["\']title
["\'][^>]*>(?P<title>[^<]+)',
124 r'<div[^>]+data-video-title=(["\'])(?P
<title
>.+?
)\
1',
125 r'shareTitle\s
*=\s
*(["\'])(?P<title>.+?)\1'),
126 webpage, 'title', group='title')
128 flashvars = self._parse_json(
130 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
133 thumbnail = flashvars.get('image_url')
134 duration = int_or_none(flashvars.get('video_duration'))
136 title, thumbnail, duration = [None] * 3
138 video_uploader = self._html_search_regex(
139 r'(?s)From: .+?<(?:a href="/users
/|a href
="/channels/|span class="username
)[^
>]+>(.+?
)<',
140 webpage, 'uploader
', fatal=False)
142 view_count = self._extract_count(
143 r'<span
class="count">([\d
,\
.]+)</span
> views
', webpage, 'view
')
144 like_count = self._extract_count(
145 r'<span
class="votesUp">([\d
,\
.]+)</span
>', webpage, 'like
')
146 dislike_count = self._extract_count(
147 r'<span
class="votesDown">([\d
,\
.]+)</span
>', webpage, 'dislike
')
148 comment_count = self._extract_count(
149 r'All Comments\s
*<span
>\
(([\d
,.]+)\
)', webpage, 'comment
')
151 video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^
']+)'", webpage)))
152 if webpage.find('"encrypted
":true') != -1:
153 password = compat_urllib_parse_unquote_plus(
154 self._search_regex(r'"video_title
":"([^
"]+)', webpage, 'password'))
155 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
158 for video_url in video_urls:
159 path = compat_urllib_parse_urlparse(video_url).path
160 extension = os.path.splitext(path)[1][1:]
161 format = path.split('/')[5].split('_')[:2]
162 format = '-'.join(format)
164 m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
169 height = int(m.group('height'))
170 tbr = int(m.group('tbr'))
180 self._sort_formats(formats)
184 'uploader': video_uploader,
186 'thumbnail': thumbnail,
187 'duration': duration,
188 'view_count': view_count,
189 'like_count': like_count,
190 'dislike_count': dislike_count,
191 'comment_count': comment_count,
197 class PornHubPlaylistBaseIE(InfoExtractor):
198 def _extract_entries(self, webpage):
201 'http://www.pornhub.com/%s' % video_url,
202 PornHubIE.ie_key(), video_title=title)
203 for video_url, title in orderedSet(re.findall(
204 r'href="/?
(view_video\
.php
\?.*\bviewkey
=[\da
-z
]+[^
"]*)"[^
>]*\s
+title
="([^"]+)"',
208 def _real_extract(self, url):
209 playlist_id = self._match_id(url)
211 webpage = self._download_webpage(url, playlist_id)
213 entries = self._extract_entries(webpage)
215 playlist = self._parse_json(
217 r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
220 return self.playlist_result(
221 entries, playlist_id, playlist.get('title'), playlist.get('description'))
224 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
225 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
227 'url': 'http://www.pornhub.com/playlist/6201671',
232 'playlist_mincount': 35,
236 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
237 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
239 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
243 'playlist_mincount': 171,
245 'url': 'http://www.pornhub.com/users/rushandlia/videos',
246 'only_matching': True,
249 def _real_extract(self, url):
250 user_id = self._match_id(url)
253 for page_num in itertools.count(1):
255 webpage = self._download_webpage(
256 url, user_id, 'Downloading page %d' % page_num,
257 query={'page': page_num})
258 except ExtractorError as e:
259 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
261 page_entries = self._extract_entries(webpage)
264 entries.extend(page_entries)
266 return self.playlist_result(entries, user_id)