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
,
11 compat_urllib_request
,
22 class PornHubIE(InfoExtractor
):
23 _VALID_URL
= r
'https?://(?:www\.)?pornhub\.com/(?:view_video\.php\?viewkey=|embed/)(?P<id>[0-9a-z]+)'
25 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
26 'md5': '882f488fa1f0026f023f33576004a2ed',
31 "title": "Seductive Indian beauty strips down and fingers her pink pussy",
35 'url': 'http://www.pornhub.com/view_video.php?viewkey=ph557bbb6676d2d',
36 'only_matching': True,
40 def _extract_url(cls
, webpage
):
42 r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?pornhub\
.com
/embed
/\d
+)\
1', webpage)
44 return mobj.group('url
')
46 def _extract_count(self, pattern, webpage, name):
47 return str_to_int(self._search_regex(
48 pattern, webpage, '%s count
' % name, fatal=False))
50 def _real_extract(self, url):
51 video_id = self._match_id(url)
53 req = compat_urllib_request.Request(
54 'http
://www
.pornhub
.com
/view_video
.php?viewkey
=%s' % video_id)
55 req.add_header('Cookie
', 'age_verified
=1')
56 webpage = self._download_webpage(req, video_id)
58 error_msg = self._html_search_regex(
59 r'(?s
)<div
class="userMessageSection[^"]*".*?>(.*?)</div>',
60 webpage, 'error message', default=None)
62 error_msg = re.sub(r'\s+', ' ', error_msg)
64 'PornHub said: %s' % error_msg,
65 expected=True, video_id=video_id)
67 video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
68 video_uploader = self._html_search_regex(
69 r'(?s)From: .+?<(?:a href="/users
/|a href
="/channels/|span class="username
)[^
>]+>(.+?
)<',
70 webpage, 'uploader
', fatal=False)
71 thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, 'thumbnail
', fatal=False)
73 thumbnail = compat_urllib_parse_unquote(thumbnail)
75 view_count = self._extract_count(
76 r'<span
class="count">([\d
,\
.]+)</span
> views
', webpage, 'view
')
77 like_count = self._extract_count(
78 r'<span
class="votesUp">([\d
,\
.]+)</span
>', webpage, 'like
')
79 dislike_count = self._extract_count(
80 r'<span
class="votesDown">([\d
,\
.]+)</span
>', webpage, 'dislike
')
81 comment_count = self._extract_count(
82 r'All Comments\s
*<span
>\
(([\d
,.]+)\
)', webpage, 'comment
')
84 video_urls = list(map(compat_urllib_parse_unquote, re.findall(r"player_quality_[0-9]{3}p\s*=\s*'([^
']+)'", webpage)))
85 if webpage.find('"encrypted
":true') != -1:
86 password = compat_urllib_parse_unquote_plus(
87 self._search_regex(r'"video_title
":"([^
"]+)', webpage, 'password'))
88 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
91 for video_url in video_urls:
92 path = compat_urllib_parse_urlparse(video_url).path
93 extension = os.path.splitext(path)[1][1:]
94 format = path.split('/')[5].split('_')[:2]
95 format = "-".join(format)
97 m = re.match(r'^(?P<height>[0-9]+)[pP]-(?P<tbr>[0-9]+)[kK]$', format)
102 height = int(m.group('height'))
103 tbr = int(m.group('tbr'))
113 self._sort_formats(formats)
117 'uploader': video_uploader,
118 'title': video_title,
119 'thumbnail': thumbnail,
120 'view_count': view_count,
121 'like_count': like_count,
122 'dislike_count': dislike_count,
123 'comment_count': comment_count,
129 class PornHubPlaylistIE(InfoExtractor):
130 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/playlist/(?P<id>\d+)'
132 'url': 'http://www.pornhub.com/playlist/6201671',
137 'playlist_mincount': 35,
140 def _real_extract(self, url):
141 playlist_id = self._match_id(url)
143 webpage = self._download_webpage(url, playlist_id)
146 self.url_result('http://www.pornhub.com/%s' % video_url, 'PornHub')
147 for video_url in set(re.findall('href="/?
(view_video\
.php
\?viewkey
=\d
+[^
"]*)"', webpage))
150 playlist = self._parse_json(
152 r'playlistObject\s
*=\s
*({.+?}
);', webpage, 'playlist
'),
155 return self.playlist_result(
156 entries, playlist_id, playlist.get('title
'), playlist.get('description
'))