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=(?P<id>[0-9a-f]+)'
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",
35 def _extract_count(self
, pattern
, webpage
, name
):
36 count
= self
._html
_search
_regex
(pattern
, webpage
, '%s count' % name
, fatal
=False)
38 count
= str_to_int(count
)
41 def _real_extract(self
, url
):
42 video_id
= self
._match
_id
(url
)
44 req
= compat_urllib_request
.Request(url
)
45 req
.add_header('Cookie', 'age_verified=1')
46 webpage
= self
._download
_webpage
(req
, video_id
)
48 error_msg
= self
._html
_search
_regex
(
49 r
'(?s)<div class="userMessageSection[^"]*".*?>(.*?)</div>',
50 webpage
, 'error message', default
=None)
52 error_msg
= re
.sub(r
'\s+', ' ', error_msg
)
54 'PornHub said: %s' % error_msg
,
55 expected
=True, video_id
=video_id
)
57 video_title
= self
._html
_search
_regex
(r
'<h1 [^>]+>([^<]+)', webpage
, 'title')
58 video_uploader
= self
._html
_search
_regex
(
59 r
'(?s)From: .+?<(?:a href="/users/|a href="/channels/|<span class="username)[^>]+>(.+?)<',
60 webpage
, 'uploader', fatal
=False)
61 thumbnail
= self
._html
_search
_regex
(r
'"image_url":"([^"]+)', webpage
, 'thumbnail', fatal
=False)
63 thumbnail
= compat_urllib_parse
.unquote(thumbnail
)
65 view_count
= self
._extract
_count
(r
'<span class="count">([\d,\.]+)</span> views', webpage
, 'view')
66 like_count
= self
._extract
_count
(r
'<span class="votesUp">([\d,\.]+)</span>', webpage
, 'like')
67 dislike_count
= self
._extract
_count
(r
'<span class="votesDown">([\d,\.]+)</span>', webpage
, 'dislike')
68 comment_count
= self
._extract
_count
(
69 r
'All comments \(<var class="videoCommentCount">([\d,\.]+)</var>', webpage
, 'comment')
71 video_urls
= list(map(compat_urllib_parse
.unquote
, re
.findall(r
'"quality_[0-9]{3}p":"([^"]+)', webpage
)))
72 if webpage
.find('"encrypted":true') != -1:
73 password
= compat_urllib_parse
.unquote_plus(self
._html
_search
_regex
(r
'"video_title":"([^"]+)', webpage
, 'password'))
74 video_urls
= list(map(lambda s
: aes_decrypt_text(s
, password
, 32).decode('utf-8'), video_urls
))
77 for video_url
in video_urls
:
78 path
= compat_urllib_parse_urlparse(video_url
).path
79 extension
= os
.path
.splitext(path
)[1][1:]
80 format
= path
.split('/')[5].split('_')[:2]
81 format
= "-".join(format
)
83 m
= re
.match(r
'^(?P<height>[0-9]+)P-(?P<tbr>[0-9]+)K$', format
)
88 height
= int(m
.group('height'))
89 tbr
= int(m
.group('tbr'))
99 self
._sort
_formats
(formats
)
103 'uploader': video_uploader
,
104 'title': video_title
,
105 'thumbnail': thumbnail
,
106 'view_count': view_count
,
107 'like_count': like_count
,
108 'dislike_count': dislike_count
,
109 'comment_count': comment_count
,