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,
87 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph56fd731fce6b7',
88 'only_matching': True,
90 'url': 'https://www.thumbzilla.com/video/ph56c6114abd99a/horny-girlfriend-sex',
91 'only_matching': True,
95 def _extract_url(cls
, webpage
):
97 r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.com
/embed
/\d
+)\
1', webpage)
99 return mobj.group('url
')
101 def _extract_count(self, pattern, webpage, name):
102 return str_to_int(self._search_regex(
103 pattern, webpage, '%s count
' % name, fatal=False))
105 def _real_extract(self, url):
106 video_id = self._match_id(url)
108 req = sanitized_Request(
109 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=%s' % video_id)
110 req.add_header('Cookie
', 'age_verified
=1')
111 webpage = self._download_webpage(req, video_id)
113 error_msg = self._html_search_regex(
114 r'(?s
)<div
[^
>]+class=(["\'])(?:(?!\1).)*\b(?:removed|userMessageSection)\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</div>',
115 webpage, 'error message', default=None, group='error')
117 error_msg = re.sub(r'\s+', ' ', error_msg)
118 raise ExtractorError(
119 'PornHub said: %s' % error_msg,
120 expected=True, video_id=video_id)
122 # video_title from flashvars contains whitespace instead of non-ASCII (see
123 # http://www.pornhub.com/view_video.php?viewkey=1331683002), not relying
125 title = self._html_search_meta(
126 'twitter:title', webpage, default=None) or self._search_regex(
127 (r'<h1[^>]+class=["\']title
["\'][^>]*>(?P<title>[^<]+)',
128 r'<div[^>]+data-video-title=(["\'])(?P
<title
>.+?
)\
1',
129 r'shareTitle\s
*=\s
*(["\'])(?P<title>.+?)\1'),
130 webpage, 'title', group='title')
132 flashvars = self._parse_json(
134 r'var\s+flashvars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
137 thumbnail = flashvars.get('image_url')
138 duration = int_or_none(flashvars.get('video_duration'))
140 title, thumbnail, duration = [None] * 3
142 video_uploader = self._html_search_regex(
143 r'(?s)From: .+?<(?:a href="/users
/|a href
="/channels/|span class="username
)[^
>]+>(.+?
)<',
144 webpage, 'uploader
', fatal=False)
146 view_count = self._extract_count(
147 r'<span
class="count">([\d
,\
.]+)</span
> views
', webpage, 'view
')
148 like_count = self._extract_count(
149 r'<span
class="votesUp">([\d
,\
.]+)</span
>', webpage, 'like
')
150 dislike_count = self._extract_count(
151 r'<span
class="votesDown">([\d
,\
.]+)</span
>', webpage, 'dislike
')
152 comment_count = self._extract_count(
153 r'All Comments\s
*<span
>\
(([\d
,.]+)\
)', webpage, 'comment
')
155 video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^
']+)'", webpage)))
156 if webpage.find('"encrypted
":true') != -1:
157 password = compat_urllib_parse_unquote_plus(
158 self._search_regex(r'"video_title
":"([^
"]+)', webpage, 'password'))
159 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
162 for video_url in video_urls:
163 path = compat_urllib_parse_urlparse(video_url).path
164 extension = os.path.splitext(path)[1][1:]
165 format = path.split('/')[5].split('_')[:2]
166 format = '-'.join(format)
168 m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
173 height = int(m.group('height'))
174 tbr = int(m.group('tbr'))
184 self._sort_formats(formats)
188 'uploader': video_uploader,
190 'thumbnail': thumbnail,
191 'duration': duration,
192 'view_count': view_count,
193 'like_count': like_count,
194 'dislike_count': dislike_count,
195 'comment_count': comment_count,
201 class PornHubPlaylistBaseIE(InfoExtractor):
202 def _extract_entries(self, webpage):
205 'http://www.pornhub.com/%s' % video_url,
206 PornHubIE.ie_key(), video_title=title)
207 for video_url, title in orderedSet(re.findall(
208 r'href="/?
(view_video\
.php
\?.*\bviewkey
=[\da
-z
]+[^
"]*)"[^
>]*\s
+title
="([^"]+)"',
212 def _real_extract(self, url):
213 playlist_id = self._match_id(url)
215 webpage = self._download_webpage(url, playlist_id)
217 entries = self._extract_entries(webpage)
219 playlist = self._parse_json(
221 r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
224 return self.playlist_result(
225 entries, playlist_id, playlist.get('title'), playlist.get('description'))
228 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
229 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
231 'url': 'http://www.pornhub.com/playlist/6201671',
236 'playlist_mincount': 35,
240 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
241 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/users/(?P<id>[^/]+)/videos'
243 'url': 'http://www.pornhub.com/users/zoe_ph/videos/public',
247 'playlist_mincount': 171,
249 'url': 'http://www.pornhub.com/users/rushandlia/videos',
250 'only_matching': True,
253 def _real_extract(self, url):
254 user_id = self._match_id(url)
257 for page_num in itertools.count(1):
259 webpage = self._download_webpage(
260 url, user_id, 'Downloading page %d' % page_num,
261 query={'page': page_num})
262 except ExtractorError as e:
263 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
265 page_entries = self._extract_entries(webpage)
268 entries.extend(page_entries)
270 return self.playlist_result(entries, user_id)