]>
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, |
ddae3375 | 9 | traverse_obj, |
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>[^/?#&]+))?' |
bfd973ec | 17 | _EMBED_REGEX = [r'<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)'] |
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$', |
7c60c33e | 28 | 'duration': 210, |
e572a101 | 29 | 'uploader': 'Ask Dan And Jennifer', |
18166bb8 | 30 | 'upload_date': '20101217', |
589c33da S |
31 | 'average_rating': int, |
32 | 'view_count': int, | |
33 | 'categories': list, | |
34 | 'tags': list, | |
f24e9833 | 35 | 'age_limit': 18, |
4f13f8f7 | 36 | }, |
46358f64 | 37 | 'skip': 'This video has been disabled', |
4f13f8f7 | 38 | }, { |
f6af0f88 | 39 | # Unknown uploader |
4f13f8f7 S |
40 | 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4', |
41 | 'info_dict': { | |
42 | 'id': '561726', | |
43 | 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show', | |
44 | 'ext': 'mp4', | |
45 | 'title': 'Big Tits Awesome Brunette On amazing webcam show', | |
46 | 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4', | |
ec85ded8 | 47 | 'thumbnail': r're:^https?://.*\.jpg$', |
f6af0f88 | 48 | 'uploader': 'Unknown', |
18166bb8 | 49 | 'upload_date': '20110418', |
4f13f8f7 S |
50 | 'average_rating': int, |
51 | 'view_count': int, | |
52 | 'categories': list, | |
53 | 'tags': list, | |
54 | 'age_limit': 18, | |
55 | }, | |
56 | 'params': { | |
57 | 'skip_download': True, | |
58 | }, | |
7c60c33e | 59 | 'skip': '404', |
52c4c515 S |
60 | }, { |
61 | 'url': 'https://www.youporn.com/embed/505835/sex-ed-is-it-safe-to-masturbate-daily/', | |
62 | 'only_matching': True, | |
63 | }, { | |
64 | 'url': 'http://www.youporn.com/watch/505835', | |
65 | 'only_matching': True, | |
30a074c2 | 66 | }, { |
67 | 'url': 'https://www.youporn.com/watch/13922959/femdom-principal/', | |
68 | 'only_matching': True, | |
86f557b6 | 69 | }, { |
70 | 'url': 'https://www.youporn.com/watch/16290308/tinderspecial-trailer1/', | |
71 | 'info_dict': { | |
72 | 'id': '16290308', | |
73 | 'age_limit': 18, | |
74 | 'categories': [], | |
351368cb | 75 | 'description': str, # TODO: detect/remove SEO spam description in ytdl backport |
86f557b6 | 76 | 'display_id': 'tinderspecial-trailer1', |
77 | 'duration': 298.0, | |
78 | 'ext': 'mp4', | |
79 | 'upload_date': '20201123', | |
80 | 'uploader': 'Ersties', | |
81 | 'tags': [], | |
351368cb TM |
82 | 'thumbnail': r're:https://.+\.jpg', |
83 | 'timestamp': 1606147564, | |
86f557b6 | 84 | 'title': 'Tinder In Real Life', |
85 | 'view_count': int, | |
86 | } | |
4f13f8f7 | 87 | }] |
0143dc02 | 88 | |
0143dc02 | 89 | def _real_extract(self, url): |
ddae3375 | 90 | video_id, display_id = self._match_valid_url(url).group('id', 'display_id') |
351368cb TM |
91 | self._set_cookie('.youporn.com', 'age_verified', '1') |
92 | webpage = self._download_webpage(f'https://www.youporn.com/watch/{video_id}', video_id) | |
93 | definitions = self._search_json(r'\bplayervars\s*:', webpage, 'player vars', video_id)['mediaDefinitions'] | |
ddae3375 | 94 | |
351368cb TM |
95 | def get_format_data(data, stream_type): |
96 | info_url = traverse_obj(data, (lambda _, v: v['format'] == stream_type, 'videoUrl', {url_or_none}, any)) | |
97 | if not info_url: | |
98 | return [] | |
99 | return traverse_obj( | |
100 | self._download_json(info_url, video_id, f'Downloading {stream_type} info JSON', fatal=False), | |
101 | lambda _, v: v['format'] == stream_type and url_or_none(v['videoUrl'])) | |
589c33da | 102 | |
0143dc02 | 103 | formats = [] |
ddae3375 | 104 | # Try to extract only the actual master m3u8 first, avoiding the duplicate single resolution "master" m3u8s |
105 | for hls_url in traverse_obj(get_format_data(definitions, 'hls'), ( | |
106 | lambda _, v: not isinstance(v['defaultQuality'], bool), 'videoUrl'), (..., 'videoUrl')): | |
107 | formats.extend(self._extract_m3u8_formats(hls_url, video_id, 'mp4', fatal=False, m3u8_id='hls')) | |
108 | ||
109 | for definition in get_format_data(definitions, 'mp4'): | |
110 | f = traverse_obj(definition, { | |
111 | 'url': 'videoUrl', | |
112 | 'filesize': ('videoSize', {int_or_none}) | |
113 | }) | |
46358f64 | 114 | height = int_or_none(definition.get('quality')) |
589c33da S |
115 | # Video URL's path looks like this: |
116 | # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 | |
d627cec6 | 117 | # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 |
30a074c2 | 118 | # /videos/201703/11/109285532/1080P_4000K_109285532.mp4 |
589c33da | 119 | # We will benefit from it by extracting some metadata |
ddae3375 | 120 | mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', definition['videoUrl']) |
589c33da | 121 | if mobj: |
46358f64 | 122 | if not height: |
123 | height = int(mobj.group('height')) | |
589c33da S |
124 | bitrate = int(mobj.group('bitrate')) |
125 | f.update({ | |
126 | 'format_id': '%dp-%dk' % (height, bitrate), | |
589c33da S |
127 | 'tbr': bitrate, |
128 | }) | |
46358f64 | 129 | f['height'] = height |
589c33da | 130 | formats.append(f) |
bfe9de85 | 131 | |
46358f64 | 132 | title = self._html_search_regex( |
133 | r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>', | |
134 | webpage, 'title', default=None) or self._og_search_title( | |
135 | webpage, default=None) or self._html_search_meta( | |
136 | 'title', webpage, fatal=True) | |
137 | ||
6089ff40 S |
138 | description = self._html_search_regex( |
139 | r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>', | |
140 | webpage, 'description', | |
141 | default=None) or self._og_search_description( | |
142 | webpage, default=None) | |
589c33da S |
143 | thumbnail = self._search_regex( |
144 | r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1', | |
145 | webpage, 'thumbnail', fatal=False, group='thumbnail') | |
7c60c33e | 146 | duration = int_or_none(self._html_search_meta( |
147 | 'video:duration', webpage, 'duration', fatal=False)) | |
589c33da | 148 | |
4f13f8f7 | 149 | uploader = self._html_search_regex( |
2c3322e3 | 150 | r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>', |
589c33da S |
151 | webpage, 'uploader', fatal=False) |
152 | upload_date = unified_strdate(self._html_search_regex( | |
6d1b3489 | 153 | (r'UPLOADED:\s*<span>([^<]+)', |
8bdd16b4 | 154 | r'Date\s+[Aa]dded:\s*<span>([^<]+)', |
6d1b3489 | 155 | r'''(?s)<div[^>]+class=["']videoInfo(?:Date|Time)\b[^>]*>(.+?)</div>''', |
156 | r'(?s)<label\b[^>]*>Uploaded[^<]*</label>\s*<span\b[^>]*>(.+?)</span>'), | |
589c33da S |
157 | webpage, 'upload date', fatal=False)) |
158 | ||
159 | age_limit = self._rta_search(webpage) | |
160 | ||
46358f64 | 161 | view_count = None |
162 | views = self._search_regex( | |
163 | r'(<div[^>]+\bclass=["\']js_videoInfoViews["\']>)', webpage, | |
164 | 'views', default=None) | |
165 | if views: | |
166 | view_count = str_to_int(extract_attributes(views).get('data-value')) | |
755ff8d2 S |
167 | comment_count = str_to_int(self._search_regex( |
168 | r'>All [Cc]omments? \(([\d,.]+)\)', | |
8bdd16b4 | 169 | webpage, 'comment count', default=None)) |
589c33da | 170 | |
f6af0f88 S |
171 | def extract_tag_box(regex, title): |
172 | tag_box = self._search_regex(regex, webpage, title, default=None) | |
589c33da S |
173 | if not tag_box: |
174 | return [] | |
175 | return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box) | |
176 | ||
f6af0f88 S |
177 | categories = extract_tag_box( |
178 | r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories') | |
179 | tags = extract_tag_box( | |
180 | r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>', | |
181 | 'tags') | |
5f6a1245 | 182 | |
86f557b6 | 183 | data = self._search_json_ld(webpage, video_id, expected_type='VideoObject', fatal=False) |
ddae3375 | 184 | data.pop('url', None) |
86f557b6 | 185 | return merge_dicts(data, { |
7df28654 | 186 | 'id': video_id, |
589c33da S |
187 | 'display_id': display_id, |
188 | 'title': title, | |
189 | 'description': description, | |
190 | 'thumbnail': thumbnail, | |
7c60c33e | 191 | 'duration': duration, |
589c33da S |
192 | 'uploader': uploader, |
193 | 'upload_date': upload_date, | |
589c33da | 194 | 'view_count': view_count, |
755ff8d2 | 195 | 'comment_count': comment_count, |
589c33da S |
196 | 'categories': categories, |
197 | 'tags': tags, | |
7df28654 | 198 | 'age_limit': age_limit, |
199 | 'formats': formats, | |
86f557b6 | 200 | }) |