1 from __future__ import unicode_literals
6 from .common import InfoExtractor
9 compat_urllib_parse_urlparse,
10 compat_urllib_request,
20 class PornHubIE(InfoExtractor):
21 _VALID_URL = r'https?://(?:www\.)?pornhub\.com/view_video\.php\?viewkey=(?P<id>[0-9a-f]+)'
23 'url': 'http://www.pornhub.com/view_video.php?viewkey=648719015',
24 'md5': '882f488fa1f0026f023f33576004a2ed',
29 "title": "Seductive Indian beauty strips down and fingers her pink pussy",
34 def _extract_count(self, pattern, webpage, name):
35 count = self._html_search_regex(pattern, webpage, '%s count' % name, fatal=False)
37 count = str_to_int(count)
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
43 req = compat_urllib_request.Request(url)
44 req.add_header('Cookie', 'age_verified=1')
45 webpage = self._download_webpage(req, video_id)
47 video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, 'title')
48 video_uploader = self._html_search_regex(
49 r'(?s)From: .+?<(?:a href="/users/|a href="/channels/|<span class="username)[^>]+>(.+?)<',
50 webpage, 'uploader', fatal=False)
51 thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, 'thumbnail', fatal=False)
53 thumbnail = compat_urllib_parse.unquote(thumbnail)
55 view_count = self._extract_count(r'<span class="count">([\d,\.]+)</span> views', webpage, 'view')
56 like_count = self._extract_count(r'<span class="votesUp">([\d,\.]+)</span>', webpage, 'like')
57 dislike_count = self._extract_count(r'<span class="votesDown">([\d,\.]+)</span>', webpage, 'dislike')
58 comment_count = self._extract_count(
59 r'All comments \(<var class="videoCommentCount">([\d,\.]+)</var>', webpage, 'comment')
61 video_urls = list(map(compat_urllib_parse.unquote, re.findall(r'"quality_[0-9]{3}p":"([^"]+)', webpage)))
62 if webpage.find('"encrypted":true') != -1:
63 password = compat_urllib_parse.unquote_plus(self._html_search_regex(r'"video_title":"([^"]+)', webpage, 'password'))
64 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
67 for video_url in video_urls:
68 path = compat_urllib_parse_urlparse(video_url).path
69 extension = os.path.splitext(path)[1][1:]
70 format = path.split('/')[5].split('_')[:2]
71 format = "-".join(format)
73 m = re.match(r'^(?P<height>[0-9]+)P-(?P<tbr>[0-9]+)K$', format)
78 height = int(m.group('height'))
79 tbr = int(m.group('tbr'))
89 self._sort_formats(formats)
93 'uploader': video_uploader,
95 'thumbnail': thumbnail,
96 'view_count': view_count,
97 'like_count': like_count,
98 'dislike_count': dislike_count,
99 'comment_count': comment_count,