1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
8 compat_urllib_parse_unquote
,
9 compat_urllib_parse_unquote_plus
,
10 compat_urllib_parse_urlparse
,
23 class PornHubIE(InfoExtractor
):
24 _VALID_URL
= r
'https?://(?:[a-z]+\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)(?P<id>[0-9a-z]+)'
26 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
27 'md5': '1e19b41231a02eba417839222ac9d58e',
31 'title': 'Seductive Indian beauty strips down and fingers her pink pussy',
41 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
42 'only_matching': True,
44 'url': 'http://fr.pornhub.com/view_video.php?viewkey=ph55ca2f9760862',
45 'only_matching': True,
49 def _extract_url(cls
, webpage
):
51 r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.com
/embed
/\d
+)\
1', webpage)
53 return mobj.group('url
')
55 def _extract_count(self, pattern, webpage, name):
56 return str_to_int(self._search_regex(
57 pattern, webpage, '%s count
' % name, fatal=False))
59 def _real_extract(self, url):
60 video_id = self._match_id(url)
62 req = sanitized_Request(
63 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=%s' % video_id)
64 req.add_header('Cookie
', 'age_verified
=1')
65 webpage = self._download_webpage(req, video_id)
67 error_msg = self._html_search_regex(
68 r'(?s
)<div
class="userMessageSection[^"]*".*?>(.*?)</div>',
69 webpage, 'error message', default=None)
71 error_msg = re.sub(r'\s+', ' ', error_msg)
73 'PornHub said: %s' % error_msg,
74 expected=True, video_id=video_id)
76 flashvars = self._parse_json(
78 r'var\s+flashv1ars_\d+\s*=\s*({.+?});', webpage, 'flashvars', default='{}'),
81 video_title = flashvars.get('video_title')
82 thumbnail = flashvars.get('image_url')
83 duration = int_or_none(flashvars.get('video_duration'))
85 video_title, thumbnail, duration = [None] * 3
88 video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
90 video_uploader = self._html_search_regex(
91 r'(?s)From: .+?<(?:a href="/users
/|a href
="/channels/|span class="username
)[^
>]+>(.+?
)<',
92 webpage, 'uploader
', fatal=False)
94 view_count = self._extract_count(
95 r'<span
class="count">([\d
,\
.]+)</span
> views
', webpage, 'view
')
96 like_count = self._extract_count(
97 r'<span
class="votesUp">([\d
,\
.]+)</span
>', webpage, 'like
')
98 dislike_count = self._extract_count(
99 r'<span
class="votesDown">([\d
,\
.]+)</span
>', webpage, 'dislike
')
100 comment_count = self._extract_count(
101 r'All Comments\s
*<span
>\
(([\d
,.]+)\
)', webpage, 'comment
')
103 video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^
']+)'", webpage)))
104 if webpage.find('"encrypted
":true') != -1:
105 password = compat_urllib_parse_unquote_plus(
106 self._search_regex(r'"video_title
":"([^
"]+)', webpage, 'password'))
107 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
110 for video_url in video_urls:
111 path = compat_urllib_parse_urlparse(video_url).path
112 extension = os.path.splitext(path)[1][1:]
113 format = path.split('/')[5].split('_')[:2]
114 format = '-'.join(format)
116 m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
121 height = int(m.group('height'))
122 tbr = int(m.group('tbr'))
132 self._sort_formats(formats)
136 'uploader': video_uploader,
137 'title': video_title,
138 'thumbnail': thumbnail,
139 'duration': duration,
140 'view_count': view_count,
141 'like_count': like_count,
142 'dislike_count': dislike_count,
143 'comment_count': comment_count,
149 class PornHubPlaylistBaseIE(InfoExtractor):
150 def _extract_entries(self, webpage):
152 self.url_result('http://www.pornhub.com/%s' % video_url, PornHubIE.ie_key())
153 for video_url in set(re.findall(
154 r'href="/?
(view_video\
.php
\?.*\bviewkey
=[\da
-z
]+[^
"]*)"', webpage))
157 def _real_extract(self, url):
158 playlist_id = self._match_id(url)
160 webpage = self._download_webpage(url, playlist_id)
162 entries = self._extract_entries(webpage)
164 playlist = self._parse_json(
166 r'playlistObject\s
*=\s
*({.+?
});', webpage, 'playlist
'),
169 return self.playlist_result(
170 entries, playlist_id, playlist.get('title
'), playlist.get('description
'))
173 class PornHubPlaylistIE(PornHubPlaylistBaseIE):
174 _VALID_URL = r'https?
://(?
:www\
.)?pornhub\
.com
/playlist
/(?P
<id>\d
+)'
176 'url
': 'http
://www
.pornhub
.com
/playlist
/6201671',
181 'playlist_mincount
': 35,
185 class PornHubUserVideosIE(PornHubPlaylistBaseIE):
186 _VALID_URL = r'https?
://(?
:www\
.)?pornhub\
.com
/users
/(?P
<id>[^
/]+)/videos
'
188 'url
': 'http
://www
.pornhub
.com
/users
/rushandlia
/videos
',
192 'playlist_mincount
': 13,
195 def _real_extract(self, url):
196 user_id = self._match_id(url)
198 webpage = self._download_webpage(url, user_id)
200 return self.playlist_result(self._extract_entries(webpage), user_id)