]>
Commit | Line | Data |
---|---|---|
125cfd78 | 1 | import os |
2 | import re | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | compat_urllib_parse_urlparse, | |
7 | compat_urllib_request, | |
8 | compat_urllib_parse, | |
125cfd78 | 9 | ) |
10 | from ..aes import ( | |
11 | aes_decrypt_text | |
12 | ) | |
13 | ||
14 | class PornHubIE(InfoExtractor): | |
00381b4c | 15 | _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>pornhub\.com/view_video\.php\?viewkey=(?P<videoid>[0-9a-f]+))' |
125cfd78 | 16 | _TEST = { |
17 | u'url': u'http://www.pornhub.com/view_video.php?viewkey=648719015', | |
18 | u'file': u'648719015.mp4', | |
19 | u'md5': u'882f488fa1f0026f023f33576004a2ed', | |
20 | u'info_dict': { | |
21 | u"uploader": u"BABES-COM", | |
22 | u"title": u"Seductive Indian beauty strips down and fingers her pink pussy", | |
750e9833 | 23 | u"age_limit": 18 |
125cfd78 | 24 | } |
25 | } | |
26 | ||
27 | def _real_extract(self, url): | |
28 | mobj = re.match(self._VALID_URL, url) | |
29 | video_id = mobj.group('videoid') | |
30 | url = 'http://www.' + mobj.group('url') | |
31 | ||
32 | req = compat_urllib_request.Request(url) | |
33 | req.add_header('Cookie', 'age_verified=1') | |
34 | webpage = self._download_webpage(req, video_id) | |
35 | ||
36 | video_title = self._html_search_regex(r'<h1 [^>]+>([^<]+)', webpage, u'title') | |
37 | video_uploader = self._html_search_regex(r'<b>From: </b>(?:\s|<[^>]*>)*(.+?)<', webpage, u'uploader', fatal=False) | |
38 | thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, u'thumbnail', fatal=False) | |
39 | if thumbnail: | |
40 | thumbnail = compat_urllib_parse.unquote(thumbnail) | |
41 | ||
42 | video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'"quality_[0-9]{3}p":"([^"]+)', webpage))) | |
43 | if webpage.find('"encrypted":true') != -1: | |
44 | password = self._html_search_regex(r'"video_title":"([^"]+)', webpage, u'password').replace('+', ' ') | |
45 | video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls)) | |
46 | ||
47 | formats = [] | |
48 | for video_url in video_urls: | |
a56f9de1 JMF |
49 | path = compat_urllib_parse_urlparse(video_url).path |
50 | extension = os.path.splitext(path)[1][1:] | |
125cfd78 | 51 | format = path.split('/')[5].split('_')[:2] |
a56f9de1 | 52 | format = "-".join(format) |
125cfd78 | 53 | formats.append({ |
54 | 'url': video_url, | |
55 | 'ext': extension, | |
56 | 'format': format, | |
57 | 'format_id': format, | |
58 | }) | |
59 | formats.sort(key=lambda format: list(map(lambda s: s.zfill(6), format['format'].split('-')))) | |
60 | ||
61 | return { | |
62 | 'id': video_id, | |
63 | 'uploader': video_uploader, | |
64 | 'title': video_title, | |
65 | 'thumbnail': thumbnail, | |
66 | 'formats': formats, | |
750e9833 | 67 | 'age_limit': 18, |
125cfd78 | 68 | } |