]>
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 ( |
46358f64 | 7 | extract_attributes, |
589c33da S |
8 | int_or_none, |
9 | str_to_int, | |
0143dc02 | 10 | unified_strdate, |
3052a30d | 11 | url_or_none, |
0143dc02 | 12 | ) |
0143dc02 | 13 | |
bfe9de85 | 14 | |
0143dc02 | 15 | class YouPornIE(InfoExtractor): |
52c4c515 | 16 | _VALID_URL = r'https?://(?:www\.)?youporn\.com/(?:watch|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?' |
4f13f8f7 | 17 | _TESTS = [{ |
f24e9833 | 18 | 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/', |
2c3322e3 | 19 | 'md5': '3744d24c50438cf5b6f6d59feb5055c2', |
f24e9833 PH |
20 | 'info_dict': { |
21 | 'id': '505835', | |
589c33da | 22 | 'display_id': 'sex-ed-is-it-safe-to-masturbate-daily', |
f24e9833 | 23 | 'ext': 'mp4', |
f24e9833 | 24 | 'title': 'Sex Ed: Is It Safe To Masturbate Daily?', |
589c33da | 25 | 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?', |
ec85ded8 | 26 | 'thumbnail': r're:^https?://.*\.jpg$', |
7c60c33e | 27 | 'duration': 210, |
e572a101 | 28 | 'uploader': 'Ask Dan And Jennifer', |
18166bb8 | 29 | 'upload_date': '20101217', |
589c33da S |
30 | 'average_rating': int, |
31 | 'view_count': int, | |
32 | 'categories': list, | |
33 | 'tags': list, | |
f24e9833 | 34 | 'age_limit': 18, |
4f13f8f7 | 35 | }, |
46358f64 | 36 | 'skip': 'This video has been disabled', |
4f13f8f7 | 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, | |
51 | 'categories': list, | |
52 | 'tags': list, | |
53 | 'age_limit': 18, | |
54 | }, | |
55 | 'params': { | |
56 | 'skip_download': True, | |
57 | }, | |
7c60c33e | 58 | 'skip': '404', |
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, | |
30a074c2 | 65 | }, { |
66 | 'url': 'https://www.youporn.com/watch/13922959/femdom-principal/', | |
67 | 'only_matching': True, | |
4f13f8f7 | 68 | }] |
0143dc02 | 69 | |
52c4c515 S |
70 | @staticmethod |
71 | def _extract_urls(webpage): | |
72 | return re.findall( | |
73 | r'<iframe[^>]+\bsrc=["\']((?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)', | |
74 | webpage) | |
75 | ||
0143dc02 PH |
76 | def _real_extract(self, url): |
77 | mobj = re.match(self._VALID_URL, url) | |
589c33da | 78 | video_id = mobj.group('id') |
52c4c515 | 79 | display_id = mobj.group('display_id') or video_id |
0143dc02 | 80 | |
46358f64 | 81 | definitions = self._download_json( |
82 | 'https://www.youporn.com/api/video/media_definitions/%s/' % video_id, | |
83 | display_id) | |
589c33da | 84 | |
0143dc02 | 85 | formats = [] |
46358f64 | 86 | for definition in definitions: |
87 | if not isinstance(definition, dict): | |
88 | continue | |
89 | video_url = url_or_none(definition.get('videoUrl')) | |
90 | if not video_url: | |
91 | continue | |
589c33da | 92 | f = { |
0143dc02 | 93 | 'url': video_url, |
46358f64 | 94 | 'filesize': int_or_none(definition.get('videoSize')), |
589c33da | 95 | } |
46358f64 | 96 | height = int_or_none(definition.get('quality')) |
589c33da S |
97 | # Video URL's path looks like this: |
98 | # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 | |
d627cec6 | 99 | # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 |
30a074c2 | 100 | # /videos/201703/11/109285532/1080P_4000K_109285532.mp4 |
589c33da | 101 | # We will benefit from it by extracting some metadata |
30a074c2 | 102 | mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url) |
589c33da | 103 | if mobj: |
46358f64 | 104 | if not height: |
105 | height = int(mobj.group('height')) | |
589c33da S |
106 | bitrate = int(mobj.group('bitrate')) |
107 | f.update({ | |
108 | 'format_id': '%dp-%dk' % (height, bitrate), | |
589c33da S |
109 | 'tbr': bitrate, |
110 | }) | |
46358f64 | 111 | f['height'] = height |
589c33da | 112 | formats.append(f) |
bfe9de85 PH |
113 | self._sort_formats(formats) |
114 | ||
46358f64 | 115 | webpage = self._download_webpage( |
116 | 'http://www.youporn.com/watch/%s' % video_id, display_id, | |
117 | headers={'Cookie': 'age_verified=1'}) | |
118 | ||
119 | title = self._html_search_regex( | |
120 | r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>', | |
121 | webpage, 'title', default=None) or self._og_search_title( | |
122 | webpage, default=None) or self._html_search_meta( | |
123 | 'title', webpage, fatal=True) | |
124 | ||
6089ff40 S |
125 | description = self._html_search_regex( |
126 | r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>', | |
127 | webpage, 'description', | |
128 | default=None) or self._og_search_description( | |
129 | webpage, default=None) | |
589c33da S |
130 | thumbnail = self._search_regex( |
131 | r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1', | |
132 | webpage, 'thumbnail', fatal=False, group='thumbnail') | |
7c60c33e | 133 | duration = int_or_none(self._html_search_meta( |
134 | 'video:duration', webpage, 'duration', fatal=False)) | |
589c33da | 135 | |
4f13f8f7 | 136 | uploader = self._html_search_regex( |
2c3322e3 | 137 | r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>', |
589c33da S |
138 | webpage, 'uploader', fatal=False) |
139 | upload_date = unified_strdate(self._html_search_regex( | |
8bdd16b4 | 140 | [r'UPLOADED:\s*<span>([^<]+)', |
141 | r'Date\s+[Aa]dded:\s*<span>([^<]+)', | |
18166bb8 | 142 | r'(?s)<div[^>]+class=["\']videoInfo(?:Date|Time)["\'][^>]*>(.+?)</div>'], |
589c33da S |
143 | webpage, 'upload date', fatal=False)) |
144 | ||
145 | age_limit = self._rta_search(webpage) | |
146 | ||
46358f64 | 147 | view_count = None |
148 | views = self._search_regex( | |
149 | r'(<div[^>]+\bclass=["\']js_videoInfoViews["\']>)', webpage, | |
150 | 'views', default=None) | |
151 | if views: | |
152 | view_count = str_to_int(extract_attributes(views).get('data-value')) | |
755ff8d2 S |
153 | comment_count = str_to_int(self._search_regex( |
154 | r'>All [Cc]omments? \(([\d,.]+)\)', | |
8bdd16b4 | 155 | webpage, 'comment count', default=None)) |
589c33da | 156 | |
f6af0f88 S |
157 | def extract_tag_box(regex, title): |
158 | tag_box = self._search_regex(regex, webpage, title, default=None) | |
589c33da S |
159 | if not tag_box: |
160 | return [] | |
161 | return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box) | |
162 | ||
f6af0f88 S |
163 | categories = extract_tag_box( |
164 | r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories') | |
165 | tags = extract_tag_box( | |
166 | r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>', | |
167 | 'tags') | |
5f6a1245 | 168 | |
7df28654 | 169 | return { |
170 | 'id': video_id, | |
589c33da S |
171 | 'display_id': display_id, |
172 | 'title': title, | |
173 | 'description': description, | |
174 | 'thumbnail': thumbnail, | |
7c60c33e | 175 | 'duration': duration, |
589c33da S |
176 | 'uploader': uploader, |
177 | 'upload_date': upload_date, | |
589c33da | 178 | 'view_count': view_count, |
755ff8d2 | 179 | 'comment_count': comment_count, |
589c33da S |
180 | 'categories': categories, |
181 | 'tags': tags, | |
7df28654 | 182 | 'age_limit': age_limit, |
183 | 'formats': formats, | |
184 | } |