]>
Commit | Line | Data |
---|---|---|
0143dc02 | 1 | import re |
0143dc02 PH |
2 | |
3 | from .common import InfoExtractor | |
1cc79574 | 4 | from ..utils import ( |
46358f64 | 5 | extract_attributes, |
589c33da | 6 | int_or_none, |
86f557b6 | 7 | merge_dicts, |
589c33da | 8 | str_to_int, |
0143dc02 | 9 | unified_strdate, |
3052a30d | 10 | url_or_none, |
0143dc02 | 11 | ) |
0143dc02 | 12 | |
bfe9de85 | 13 | |
0143dc02 | 14 | class YouPornIE(InfoExtractor): |
52c4c515 | 15 | _VALID_URL = r'https?://(?:www\.)?youporn\.com/(?:watch|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?' |
bfd973ec | 16 | _EMBED_REGEX = [r'<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)'] |
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, | |
86f557b6 | 68 | }, { |
69 | 'url': 'https://www.youporn.com/watch/16290308/tinderspecial-trailer1/', | |
70 | 'info_dict': { | |
71 | 'id': '16290308', | |
72 | 'age_limit': 18, | |
73 | 'categories': [], | |
74 | 'description': 'md5:00ea70f642f431c379763c17c2f396bc', | |
75 | 'display_id': 'tinderspecial-trailer1', | |
76 | 'duration': 298.0, | |
77 | 'ext': 'mp4', | |
78 | 'upload_date': '20201123', | |
79 | 'uploader': 'Ersties', | |
80 | 'tags': [], | |
81 | 'thumbnail': 'https://fi1.ypncdn.com/202011/23/16290308/original/8/tinderspecial-trailer1-8(m=eaAaaEPbaaaa).jpg', | |
82 | 'timestamp': 1606089600, | |
83 | 'title': 'Tinder In Real Life', | |
84 | 'view_count': int, | |
85 | } | |
4f13f8f7 | 86 | }] |
0143dc02 | 87 | |
0143dc02 | 88 | def _real_extract(self, url): |
5ad28e7f | 89 | mobj = self._match_valid_url(url) |
589c33da | 90 | video_id = mobj.group('id') |
52c4c515 | 91 | display_id = mobj.group('display_id') or video_id |
0143dc02 | 92 | |
46358f64 | 93 | definitions = self._download_json( |
94 | 'https://www.youporn.com/api/video/media_definitions/%s/' % video_id, | |
95 | display_id) | |
589c33da | 96 | |
0143dc02 | 97 | formats = [] |
46358f64 | 98 | for definition in definitions: |
99 | if not isinstance(definition, dict): | |
100 | continue | |
101 | video_url = url_or_none(definition.get('videoUrl')) | |
102 | if not video_url: | |
103 | continue | |
589c33da | 104 | f = { |
0143dc02 | 105 | 'url': video_url, |
46358f64 | 106 | 'filesize': int_or_none(definition.get('videoSize')), |
589c33da | 107 | } |
46358f64 | 108 | height = int_or_none(definition.get('quality')) |
589c33da S |
109 | # Video URL's path looks like this: |
110 | # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 | |
d627cec6 | 111 | # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 |
30a074c2 | 112 | # /videos/201703/11/109285532/1080P_4000K_109285532.mp4 |
589c33da | 113 | # We will benefit from it by extracting some metadata |
30a074c2 | 114 | mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url) |
589c33da | 115 | if mobj: |
46358f64 | 116 | if not height: |
117 | height = int(mobj.group('height')) | |
589c33da S |
118 | bitrate = int(mobj.group('bitrate')) |
119 | f.update({ | |
120 | 'format_id': '%dp-%dk' % (height, bitrate), | |
589c33da S |
121 | 'tbr': bitrate, |
122 | }) | |
46358f64 | 123 | f['height'] = height |
589c33da | 124 | formats.append(f) |
bfe9de85 | 125 | |
46358f64 | 126 | webpage = self._download_webpage( |
127 | 'http://www.youporn.com/watch/%s' % video_id, display_id, | |
128 | headers={'Cookie': 'age_verified=1'}) | |
129 | ||
130 | title = self._html_search_regex( | |
131 | r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>', | |
132 | webpage, 'title', default=None) or self._og_search_title( | |
133 | webpage, default=None) or self._html_search_meta( | |
134 | 'title', webpage, fatal=True) | |
135 | ||
6089ff40 S |
136 | description = self._html_search_regex( |
137 | r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>', | |
138 | webpage, 'description', | |
139 | default=None) or self._og_search_description( | |
140 | webpage, default=None) | |
589c33da S |
141 | thumbnail = self._search_regex( |
142 | r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1', | |
143 | webpage, 'thumbnail', fatal=False, group='thumbnail') | |
7c60c33e | 144 | duration = int_or_none(self._html_search_meta( |
145 | 'video:duration', webpage, 'duration', fatal=False)) | |
589c33da | 146 | |
4f13f8f7 | 147 | uploader = self._html_search_regex( |
2c3322e3 | 148 | r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>', |
589c33da S |
149 | webpage, 'uploader', fatal=False) |
150 | upload_date = unified_strdate(self._html_search_regex( | |
6d1b3489 | 151 | (r'UPLOADED:\s*<span>([^<]+)', |
8bdd16b4 | 152 | r'Date\s+[Aa]dded:\s*<span>([^<]+)', |
6d1b3489 | 153 | r'''(?s)<div[^>]+class=["']videoInfo(?:Date|Time)\b[^>]*>(.+?)</div>''', |
154 | r'(?s)<label\b[^>]*>Uploaded[^<]*</label>\s*<span\b[^>]*>(.+?)</span>'), | |
589c33da S |
155 | webpage, 'upload date', fatal=False)) |
156 | ||
157 | age_limit = self._rta_search(webpage) | |
158 | ||
46358f64 | 159 | view_count = None |
160 | views = self._search_regex( | |
161 | r'(<div[^>]+\bclass=["\']js_videoInfoViews["\']>)', webpage, | |
162 | 'views', default=None) | |
163 | if views: | |
164 | view_count = str_to_int(extract_attributes(views).get('data-value')) | |
755ff8d2 S |
165 | comment_count = str_to_int(self._search_regex( |
166 | r'>All [Cc]omments? \(([\d,.]+)\)', | |
8bdd16b4 | 167 | webpage, 'comment count', default=None)) |
589c33da | 168 | |
f6af0f88 S |
169 | def extract_tag_box(regex, title): |
170 | tag_box = self._search_regex(regex, webpage, title, default=None) | |
589c33da S |
171 | if not tag_box: |
172 | return [] | |
173 | return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box) | |
174 | ||
f6af0f88 S |
175 | categories = extract_tag_box( |
176 | r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories') | |
177 | tags = extract_tag_box( | |
178 | r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>', | |
179 | 'tags') | |
5f6a1245 | 180 | |
86f557b6 | 181 | data = self._search_json_ld(webpage, video_id, expected_type='VideoObject', fatal=False) |
182 | return merge_dicts(data, { | |
7df28654 | 183 | 'id': video_id, |
589c33da S |
184 | 'display_id': display_id, |
185 | 'title': title, | |
186 | 'description': description, | |
187 | 'thumbnail': thumbnail, | |
7c60c33e | 188 | 'duration': duration, |
589c33da S |
189 | 'uploader': uploader, |
190 | 'upload_date': upload_date, | |
589c33da | 191 | 'view_count': view_count, |
755ff8d2 | 192 | 'comment_count': comment_count, |
589c33da S |
193 | 'categories': categories, |
194 | 'tags': tags, | |
7df28654 | 195 | 'age_limit': age_limit, |
196 | 'formats': formats, | |
86f557b6 | 197 | }) |