1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 compat_urllib_parse_urlparse
,
10 compat_urllib_request
,
21 class PornHubIE(InfoExtractor
):
22 _VALID_URL
= r
'https?://(?:www\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)(?P<id>[0-9a-z]+)'
24 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
25 'md5': '882f488fa1f0026f023f33576004a2ed',
30 "title": "Seductive Indian beauty strips down and fingers her pink pussy",
34 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
35 'only_matching': True,
39 def _extract_url(cls
, webpage
):
41 r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.com
/embed
/\d
+)\
1', webpage)
43 return mobj.group('url
')
45 def _extract_count(self, pattern, webpage, name):
46 return str_to_int(self._search_regex(
47 pattern, webpage, '%s count
' % name, fatal=False))
49 def _real_extract(self, url):
50 video_id = self._match_id(url)
52 req = compat_urllib_request.Request(
53 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=%s' % video_id)
54 req.add_header('Cookie
', 'age_verified
=1')
55 webpage = self._download_webpage(req, video_id)
57 error_msg = self._html_search_regex(
58 r'(?s
)<div
class="userMessageSection[^"]*".*?>(.*?)</div>',
59 webpage, 'error message', default=None)
61 error_msg = re.sub(r'\s+', ' ', error_msg)
63 'PornHub said: %s' % error_msg,
64 expected=True, video_id=video_id)
66 video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
67 video_uploader = self._html_search_regex(
68 r'(?s)From: .+?<(?:a href="/users
/|a href
="/channels/|span class="username
)[^
>]+>(.+?
)<',
69 webpage, 'uploader
', fatal=False)
70 thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, 'thumbnail
', fatal=False)
72 thumbnail = compat_urllib_parse.unquote(thumbnail)
74 view_count = self._extract_count(
75 r'<span
class="count">([\d
,\
.]+)</span
> views
', webpage, 'view
')
76 like_count = self._extract_count(
77 r'<span
class="votesUp">([\d
,\
.]+)</span
>', webpage, 'like
')
78 dislike_count = self._extract_count(
79 r'<span
class="votesDown">([\d
,\
.]+)</span
>', webpage, 'dislike
')
80 comment_count = self._extract_count(
81 r'All Comments\s
*<span
>\
(([\d
,.]+)\
)', webpage, 'comment
')
83 video_urls = list(map(compat_urllib_parse.unquote, re.findall(r'"quality_[0-9]{3}p":"([^"]+)', webpage)))
84 if webpage.find('"encrypted":true
') != -1:
85 password = compat_urllib_parse.unquote_plus(
86 self._search_regex(r'"video_title":"([^"]+)', webpage, 'password
'))
87 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf
-8'), video_urls))
90 for video_url in video_urls:
91 path = compat_urllib_parse_urlparse(video_url).path
92 extension = os.path.splitext(path)[1][1:]
93 format = path.split('/')[5].split('_
')[:2]
94 format = "-".join(format)
96 m = re.match(r'^
(?P
<height
>[0-9]+)P
-(?P
<tbr
>[0-9]+)K$
', format)
101 height = int(m.group('height
'))
102 tbr = int(m.group('tbr
'))
112 self._sort_formats(formats)
116 'uploader
': video_uploader,
117 'title
': video_title,
118 'thumbnail
': thumbnail,
119 'view_count
': view_count,
120 'like_count
': like_count,
121 'dislike_count
': dislike_count,
122 'comment_count
': comment_count,
128 class PornHubPlaylistIE(InfoExtractor):
129 _VALID_URL = r'https?
://(?
:www\
.)?pornhub\
.com
/playlist
/(?P
<id>\d
+)'
131 'url
': 'http
://www
.pornhub
.com
/playlist
/6201671',
136 'playlist_mincount
': 35,
139 def _real_extract(self, url):
140 playlist_id = self._match_id(url)
142 webpage = self._download_webpage(url, playlist_id)
145 self.url_result('http
://www
.pornhub
.com
/%s' % video_url, 'PornHub
')
146 for video_url in set(re.findall('href
="/?(view_video\.php\?viewkey=\d+[^"]*)"', webpage))
149 playlist = self._parse_json(
151 r'playlistObject\s*=\s*({.+?});', webpage, 'playlist'),
154 return self.playlist_result(
155 entries, playlist_id, playlist.get('title'), playlist.get('description'))