]>
Commit | Line | Data |
---|---|---|
f24e9833 PH |
1 | from __future__ import unicode_literals |
2 | ||
0143dc02 | 3 | import re |
0143dc02 PH |
4 | |
5 | from .common import InfoExtractor | |
1cc79574 | 6 | from ..utils import ( |
589c33da S |
7 | int_or_none, |
8 | str_to_int, | |
0143dc02 PH |
9 | unescapeHTML, |
10 | unified_strdate, | |
3052a30d | 11 | url_or_none, |
0143dc02 | 12 | ) |
589c33da | 13 | from ..aes import aes_decrypt_text |
0143dc02 | 14 | |
bfe9de85 | 15 | |
0143dc02 | 16 | class YouPornIE(InfoExtractor): |
52c4c515 | 17 | _VALID_URL = r'https?://(?:www\.)?youporn\.com/(?:watch|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?' |
4f13f8f7 | 18 | _TESTS = [{ |
f24e9833 | 19 | 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/', |
2c3322e3 | 20 | 'md5': '3744d24c50438cf5b6f6d59feb5055c2', |
f24e9833 PH |
21 | 'info_dict': { |
22 | 'id': '505835', | |
589c33da | 23 | 'display_id': 'sex-ed-is-it-safe-to-masturbate-daily', |
f24e9833 | 24 | 'ext': 'mp4', |
f24e9833 | 25 | 'title': 'Sex Ed: Is It Safe To Masturbate Daily?', |
589c33da | 26 | 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?', |
ec85ded8 | 27 | 'thumbnail': r're:^https?://.*\.jpg$', |
e572a101 | 28 | 'uploader': 'Ask Dan And Jennifer', |
18166bb8 | 29 | 'upload_date': '20101217', |
589c33da S |
30 | 'average_rating': int, |
31 | 'view_count': int, | |
755ff8d2 | 32 | 'comment_count': int, |
589c33da S |
33 | 'categories': list, |
34 | 'tags': list, | |
f24e9833 | 35 | 'age_limit': 18, |
4f13f8f7 S |
36 | }, |
37 | }, { | |
f6af0f88 | 38 | # Unknown uploader |
4f13f8f7 S |
39 | 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4', |
40 | 'info_dict': { | |
41 | 'id': '561726', | |
42 | 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'Big Tits Awesome Brunette On amazing webcam show', | |
45 | 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4', | |
ec85ded8 | 46 | 'thumbnail': r're:^https?://.*\.jpg$', |
f6af0f88 | 47 | 'uploader': 'Unknown', |
18166bb8 | 48 | 'upload_date': '20110418', |
4f13f8f7 S |
49 | 'average_rating': int, |
50 | 'view_count': int, | |
755ff8d2 | 51 | 'comment_count': int, |
4f13f8f7 S |
52 | 'categories': list, |
53 | 'tags': list, | |
54 | 'age_limit': 18, | |
55 | }, | |
56 | 'params': { | |
57 | 'skip_download': True, | |
58 | }, | |
52c4c515 S |
59 | }, { |
60 | 'url': 'https://www.youporn.com/embed/505835/sex-ed-is-it-safe-to-masturbate-daily/', | |
61 | 'only_matching': True, | |
62 | }, { | |
63 | 'url': 'http://www.youporn.com/watch/505835', | |
64 | 'only_matching': True, | |
4f13f8f7 | 65 | }] |
0143dc02 | 66 | |
52c4c515 S |
67 | @staticmethod |
68 | def _extract_urls(webpage): | |
69 | return re.findall( | |
70 | r'<iframe[^>]+\bsrc=["\']((?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)', | |
71 | webpage) | |
72 | ||
0143dc02 PH |
73 | def _real_extract(self, url): |
74 | mobj = re.match(self._VALID_URL, url) | |
589c33da | 75 | video_id = mobj.group('id') |
52c4c515 | 76 | display_id = mobj.group('display_id') or video_id |
0143dc02 | 77 | |
52c4c515 S |
78 | webpage = self._download_webpage( |
79 | 'http://www.youporn.com/watch/%s' % video_id, display_id, | |
80 | headers={'Cookie': 'age_verified=1'}) | |
589c33da | 81 | |
6089ff40 S |
82 | title = self._html_search_regex( |
83 | r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>', | |
84 | webpage, 'title', default=None) or self._og_search_title( | |
97b6e301 S |
85 | webpage, default=None) or self._html_search_meta( |
86 | 'title', webpage, fatal=True) | |
0143dc02 | 87 | |
589c33da S |
88 | links = [] |
89 | ||
d4893e76 S |
90 | # Main source |
91 | definitions = self._parse_json( | |
92 | self._search_regex( | |
93 | r'mediaDefinition\s*=\s*(\[.+?\]);', webpage, | |
94 | 'media definitions', default='[]'), | |
95 | video_id, fatal=False) | |
96 | if definitions: | |
97 | for definition in definitions: | |
98 | if not isinstance(definition, dict): | |
99 | continue | |
3052a30d S |
100 | video_url = url_or_none(definition.get('videoUrl')) |
101 | if video_url: | |
d4893e76 S |
102 | links.append(video_url) |
103 | ||
104 | # Fallback #1, this also contains extra low quality 180p format | |
105 | for _, link in re.findall(r'<a[^>]+href=(["\'])(http.+?)\1[^>]+title=["\']Download [Vv]ideo', webpage): | |
106 | links.append(link) | |
107 | ||
108 | # Fallback #2 (unavailable as at 22.06.2017) | |
589c33da | 109 | sources = self._search_regex( |
002c7552 | 110 | r'(?s)sources\s*:\s*({.+?})', webpage, 'sources', default=None) |
589c33da S |
111 | if sources: |
112 | for _, link in re.findall(r'[^:]+\s*:\s*(["\'])(http.+?)\1', sources): | |
e572a101 | 113 | links.append(link) |
5f6a1245 | 114 | |
d4893e76 | 115 | # Fallback #3 (unavailable as at 22.06.2017) |
589c33da | 116 | for _, link in re.findall( |
d4893e76 | 117 | r'(?:videoSrc|videoIpadUrl|html5PlayerSrc)\s*[:=]\s*(["\'])(http.+?)\1', webpage): |
589c33da S |
118 | links.append(link) |
119 | ||
d4893e76 | 120 | # Fallback #4, encrypted links (unavailable as at 22.06.2017) |
589c33da S |
121 | for _, encrypted_link in re.findall( |
122 | r'encryptedQuality\d{3,4}URL\s*=\s*(["\'])([\da-zA-Z+/=]+)\1', webpage): | |
123 | links.append(aes_decrypt_text(encrypted_link, title, 32).decode('utf-8')) | |
124 | ||
0143dc02 | 125 | formats = [] |
589c33da S |
126 | for video_url in set(unescapeHTML(link) for link in links): |
127 | f = { | |
0143dc02 | 128 | 'url': video_url, |
589c33da S |
129 | } |
130 | # Video URL's path looks like this: | |
131 | # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 | |
d627cec6 | 132 | # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 |
589c33da | 133 | # We will benefit from it by extracting some metadata |
d627cec6 | 134 | mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+/', video_url) |
589c33da S |
135 | if mobj: |
136 | height = int(mobj.group('height')) | |
137 | bitrate = int(mobj.group('bitrate')) | |
138 | f.update({ | |
139 | 'format_id': '%dp-%dk' % (height, bitrate), | |
140 | 'height': height, | |
141 | 'tbr': bitrate, | |
142 | }) | |
143 | formats.append(f) | |
bfe9de85 PH |
144 | self._sort_formats(formats) |
145 | ||
6089ff40 S |
146 | description = self._html_search_regex( |
147 | r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>', | |
148 | webpage, 'description', | |
149 | default=None) or self._og_search_description( | |
150 | webpage, default=None) | |
589c33da S |
151 | thumbnail = self._search_regex( |
152 | r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1', | |
153 | webpage, 'thumbnail', fatal=False, group='thumbnail') | |
154 | ||
4f13f8f7 | 155 | uploader = self._html_search_regex( |
2c3322e3 | 156 | r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>', |
589c33da S |
157 | webpage, 'uploader', fatal=False) |
158 | upload_date = unified_strdate(self._html_search_regex( | |
18166bb8 S |
159 | [r'Date\s+[Aa]dded:\s*<span>([^<]+)', |
160 | r'(?s)<div[^>]+class=["\']videoInfo(?:Date|Time)["\'][^>]*>(.+?)</div>'], | |
589c33da S |
161 | webpage, 'upload date', fatal=False)) |
162 | ||
163 | age_limit = self._rta_search(webpage) | |
164 | ||
165 | average_rating = int_or_none(self._search_regex( | |
2c3322e3 | 166 | r'<div[^>]+class=["\']videoRatingPercentage["\'][^>]*>(\d+)%</div>', |
589c33da S |
167 | webpage, 'average rating', fatal=False)) |
168 | ||
169 | view_count = str_to_int(self._search_regex( | |
2c3322e3 S |
170 | r'(?s)<div[^>]+class=(["\']).*?\bvideoInfoViews\b.*?\1[^>]*>.*?(?P<count>[\d,.]+)<', |
171 | webpage, 'view count', fatal=False, group='count')) | |
755ff8d2 S |
172 | comment_count = str_to_int(self._search_regex( |
173 | r'>All [Cc]omments? \(([\d,.]+)\)', | |
174 | webpage, 'comment count', fatal=False)) | |
589c33da | 175 | |
f6af0f88 S |
176 | def extract_tag_box(regex, title): |
177 | tag_box = self._search_regex(regex, webpage, title, default=None) | |
589c33da S |
178 | if not tag_box: |
179 | return [] | |
180 | return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box) | |
181 | ||
f6af0f88 S |
182 | categories = extract_tag_box( |
183 | r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories') | |
184 | tags = extract_tag_box( | |
185 | r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>', | |
186 | 'tags') | |
5f6a1245 | 187 | |
7df28654 | 188 | return { |
189 | 'id': video_id, | |
589c33da S |
190 | 'display_id': display_id, |
191 | 'title': title, | |
192 | 'description': description, | |
193 | 'thumbnail': thumbnail, | |
194 | 'uploader': uploader, | |
195 | 'upload_date': upload_date, | |
196 | 'average_rating': average_rating, | |
197 | 'view_count': view_count, | |
755ff8d2 | 198 | 'comment_count': comment_count, |
589c33da S |
199 | 'categories': categories, |
200 | 'tags': tags, | |
7df28654 | 201 | 'age_limit': age_limit, |
202 | 'formats': formats, | |
203 | } |