]>
Commit | Line | Data |
---|---|---|
0143dc02 | 1 | import json |
0143dc02 PH |
2 | import re |
3 | import sys | |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
7 | compat_urllib_parse_urlparse, | |
8 | compat_urllib_request, | |
9 | ||
10 | ExtractorError, | |
11 | unescapeHTML, | |
12 | unified_strdate, | |
13 | ) | |
97b3656c | 14 | from ..aes import ( |
15 | aes_decrypt_text | |
16 | ) | |
0143dc02 | 17 | |
bfe9de85 | 18 | |
0143dc02 | 19 | class YouPornIE(InfoExtractor): |
6e76104d | 20 | _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+))' |
6f5ac90c PH |
21 | _TEST = { |
22 | u'url': u'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/', | |
23 | u'file': u'505835.mp4', | |
97b3656c | 24 | u'md5': u'71ec5fcfddacf80f495efa8b6a8d9a89', |
6f5ac90c | 25 | u'info_dict': { |
bfe9de85 PH |
26 | u"upload_date": u"20101221", |
27 | u"description": u"Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?", | |
28 | u"uploader": u"Ask Dan And Jennifer", | |
8ed6b344 RB |
29 | u"title": u"Sex Ed: Is It Safe To Masturbate Daily?", |
30 | u"age_limit": 18, | |
6f5ac90c PH |
31 | } |
32 | } | |
0143dc02 | 33 | |
0143dc02 PH |
34 | def _real_extract(self, url): |
35 | mobj = re.match(self._VALID_URL, url) | |
36 | video_id = mobj.group('videoid') | |
6e76104d | 37 | url = 'http://www.' + mobj.group('url') |
0143dc02 PH |
38 | |
39 | req = compat_urllib_request.Request(url) | |
40 | req.add_header('Cookie', 'age_verified=1') | |
41 | webpage = self._download_webpage(req, video_id) | |
8dbe9899 | 42 | age_limit = self._rta_search(webpage) |
0143dc02 PH |
43 | |
44 | # Get JSON parameters | |
45 | json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters') | |
46 | try: | |
47 | params = json.loads(json_params) | |
48 | except: | |
49 | raise ExtractorError(u'Invalid JSON') | |
50 | ||
51 | self.report_extraction(video_id) | |
52 | try: | |
53 | video_title = params['title'] | |
54 | upload_date = unified_strdate(params['release_date_f']) | |
55 | video_description = params['description'] | |
56 | video_uploader = params['submitted_by'] | |
57 | thumbnail = params['thumbnails'][0]['image'] | |
58 | except KeyError: | |
59 | raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1]) | |
60 | ||
7df28654 | 61 | # Get all of the links from the page |
0143dc02 PH |
62 | DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>' |
63 | download_list_html = self._search_regex(DOWNLOAD_LIST_RE, | |
64 | webpage, u'download list').strip() | |
7df28654 | 65 | LINK_RE = r'<a href="([^"]+)">' |
0143dc02 | 66 | links = re.findall(LINK_RE, download_list_html) |
7df28654 | 67 | |
68 | # Get all encrypted links | |
69 | encrypted_links = re.findall(r'var encryptedQuality[0-9]{3}URL = \'([a-zA-Z0-9+/]+={0,2})\';', webpage) | |
70 | for encrypted_link in encrypted_links: | |
71 | link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8') | |
72 | links.append(link) | |
97b3656c | 73 | |
0143dc02 PH |
74 | formats = [] |
75 | for link in links: | |
0143dc02 PH |
76 | # A link looks like this: |
77 | # http://cdn1.download.youporn.phncdn.com/201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4?nvb=20121113051249&nva=20121114051249&ir=1200&sr=1200&hash=014b882080310e95fb6a0 | |
78 | # A path looks like this: | |
79 | # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4 | |
a56f9de1 JMF |
80 | video_url = unescapeHTML(link) |
81 | path = compat_urllib_parse_urlparse(video_url).path | |
bfe9de85 | 82 | format_parts = path.split('/')[4].split('_')[:2] |
7df28654 | 83 | |
bfe9de85 PH |
84 | dn = compat_urllib_parse_urlparse(video_url).netloc.partition('.')[0] |
85 | ||
86 | resolution = format_parts[0] | |
87 | height = int(resolution[:-len('p')]) | |
88 | bitrate = int(format_parts[1][:-len('k')]) | |
89 | format = u'-'.join(format_parts) + u'-' + dn | |
0143dc02 PH |
90 | |
91 | formats.append({ | |
0143dc02 | 92 | 'url': video_url, |
0143dc02 | 93 | 'format': format, |
7df28654 | 94 | 'format_id': format, |
bfe9de85 PH |
95 | 'height': height, |
96 | 'tbr': bitrate, | |
97 | 'resolution': resolution, | |
0143dc02 PH |
98 | }) |
99 | ||
bfe9de85 PH |
100 | self._sort_formats(formats) |
101 | ||
102 | if not formats: | |
103 | raise ExtractorError(u'ERROR: no known formats available for video') | |
7df28654 | 104 | |
105 | return { | |
106 | 'id': video_id, | |
107 | 'uploader': video_uploader, | |
108 | 'upload_date': upload_date, | |
109 | 'title': video_title, | |
110 | 'thumbnail': thumbnail, | |
111 | 'description': video_description, | |
112 | 'age_limit': age_limit, | |
113 | 'formats': formats, | |
114 | } |