]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/fourtube.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / fourtube.py
CommitLineData
03635e2a
MK
1import re
2
3from .common import InfoExtractor
15bf2ca0
S
4from ..compat import (
5 compat_b64decode,
6 compat_str,
7 compat_urllib_parse_unquote,
8 compat_urlparse,
9)
1cc79574 10from ..utils import (
15bf2ca0 11 int_or_none,
1cc79574 12 parse_duration,
9d22a7df 13 parse_iso8601,
127103b6 14 str_or_none,
1cc79574 15 str_to_int,
15bf2ca0
S
16 try_get,
17 unified_timestamp,
18 url_or_none,
ae6cae78 19)
ae6cae78 20
03635e2a 21
b3c65153 22class FourTubeBaseIE(InfoExtractor):
15bf2ca0
S
23 def _extract_formats(self, url, video_id, media_id, sources):
24 token_url = 'https://%s/%s/desktop/%s' % (
25 self._TKN_HOST, media_id, '+'.join(sources))
26
27 parsed_url = compat_urlparse.urlparse(url)
28 tokens = self._download_json(token_url, video_id, data=b'', headers={
29 'Origin': '%s://%s' % (parsed_url.scheme, parsed_url.hostname),
30 'Referer': url,
31 })
32 formats = [{
33 'url': tokens[format]['token'],
34 'format_id': format + 'p',
35 'resolution': format + 'p',
36 'quality': int(format),
37 } for format in sources]
15bf2ca0
S
38 return formats
39
b3c65153 40 def _real_extract(self, url):
5ad28e7f 41 mobj = self._match_valid_url(url)
b3c65153 42 kind, video_id, display_id = mobj.group('kind', 'id', 'display_id')
03635e2a 43
b3c65153
S
44 if kind == 'm' or not display_id:
45 url = self._URL_TEMPLATE % video_id
03635e2a 46
9d22a7df 47 webpage = self._download_webpage(url, video_id)
03635e2a 48
9d22a7df
PH
49 title = self._html_search_meta('name', webpage)
50 timestamp = parse_iso8601(self._html_search_meta(
51 'uploadDate', webpage))
52 thumbnail = self._html_search_meta('thumbnailUrl', webpage)
53 uploader_id = self._html_search_regex(
b3c65153 54 r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/([^/"]+)" title="Go to [^"]+ page">',
c677e49b 55 webpage, 'uploader id', fatal=False)
9d22a7df 56 uploader = self._html_search_regex(
b3c65153 57 r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/[^/"]+" title="Go to ([^"]+) page">',
c677e49b 58 webpage, 'uploader', fatal=False)
03635e2a 59
9d22a7df 60 categories_html = self._search_regex(
77afa008 61 r'(?s)><i class="icon icon-tag"></i>\s*Categories / Tags\s*.*?<ul class="[^"]*?list[^"]*?">(.*?)</ul>',
9d22a7df
PH
62 webpage, 'categories', fatal=False)
63 categories = None
64 if categories_html:
65 categories = [
66 c.strip() for c in re.findall(
67 r'(?s)<li><a.*?>(.*?)</a>', categories_html)]
ae6cae78 68
9d22a7df 69 view_count = str_to_int(self._search_regex(
77afa008 70 r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:([0-9,]+)">',
b3c65153 71 webpage, 'view count', default=None))
9d22a7df 72 like_count = str_to_int(self._search_regex(
77afa008 73 r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserLikes:([0-9,]+)">',
b3c65153 74 webpage, 'like count', default=None))
9d22a7df 75 duration = parse_duration(self._html_search_meta('duration', webpage))
ae6cae78 76
4356d907
S
77 media_id = self._search_regex(
78 r'<button[^>]+data-id=(["\'])(?P<id>\d+)\1[^>]+data-quality=', webpage,
79 'media id', default=None, group='id')
80 sources = [
81 quality
82 for _, quality in re.findall(r'<button[^>]+data-quality=(["\'])(.+?)\1', webpage)]
83 if not (media_id and sources):
84 player_js = self._download_webpage(
85 self._search_regex(
86 r'<script[^>]id=(["\'])playerembed\1[^>]+src=(["\'])(?P<url>.+?)\2',
87 webpage, 'player JS', group='url'),
88 video_id, 'Downloading player JS')
89 params_js = self._search_regex(
90 r'\$\.ajax\(url,\ opts\);\s*\}\s*\}\)\(([0-9,\[\] ]+)\)',
91 player_js, 'initialization parameters')
92 params = self._parse_json('[%s]' % params_js, video_id)
93 media_id = params[0]
94 sources = ['%s' % p for p in params[2]]
03635e2a 95
15bf2ca0 96 formats = self._extract_formats(url, video_id, media_id, sources)
ae6cae78
S
97
98 return {
03635e2a
MK
99 'id': video_id,
100 'title': title,
101 'formats': formats,
9d22a7df
PH
102 'categories': categories,
103 'thumbnail': thumbnail,
ae6cae78
S
104 'uploader': uploader,
105 'uploader_id': uploader_id,
9d22a7df
PH
106 'timestamp': timestamp,
107 'like_count': like_count,
ae6cae78
S
108 'view_count': view_count,
109 'duration': duration,
03635e2a 110 'age_limit': 18,
5f6a1245 111 }
b3c65153
S
112
113
114class FourTubeIE(FourTubeBaseIE):
115 IE_NAME = '4tube'
116 _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?4tube\.com/(?:videos|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
117 _URL_TEMPLATE = 'https://www.4tube.com/videos/%s/video'
c9856648 118 _TKN_HOST = 'token.4tube.com'
b3c65153
S
119 _TESTS = [{
120 'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
121 'md5': '6516c8ac63b03de06bc8eac14362db4f',
122 'info_dict': {
123 'id': '209733',
124 'ext': 'mp4',
125 'title': 'Hot Babe Holly Michaels gets her ass stuffed by black',
126 'uploader': 'WCP Club',
127 'uploader_id': 'wcp-club',
128 'upload_date': '20131031',
129 'timestamp': 1383263892,
130 'duration': 583,
131 'view_count': int,
132 'like_count': int,
133 'categories': list,
134 'age_limit': 18,
135 },
136 }, {
137 'url': 'http://www.4tube.com/embed/209733',
138 'only_matching': True,
139 }, {
140 'url': 'http://m.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
141 'only_matching': True,
142 }]
143
144
145class FuxIE(FourTubeBaseIE):
146 _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?fux\.com/(?:video|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
147 _URL_TEMPLATE = 'https://www.fux.com/video/%s/video'
c9856648 148 _TKN_HOST = 'token.fux.com'
b3c65153
S
149 _TESTS = [{
150 'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow',
151 'info_dict': {
152 'id': '195359',
153 'ext': 'mp4',
154 'title': 'Awesome fucking in the kitchen ends with cum swallow',
155 'uploader': 'alenci2342',
156 'uploader_id': 'alenci2342',
157 'upload_date': '20131230',
158 'timestamp': 1388361660,
159 'duration': 289,
160 'view_count': int,
161 'like_count': int,
162 'categories': list,
163 'age_limit': 18,
164 },
165 'params': {
166 'skip_download': True,
167 },
168 }, {
169 'url': 'https://www.fux.com/embed/195359',
170 'only_matching': True,
171 }, {
172 'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow',
173 'only_matching': True,
174 }]
175
176
177class PornTubeIE(FourTubeBaseIE):
178 _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?porntube\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)'
179 _URL_TEMPLATE = 'https://www.porntube.com/videos/video_%s'
15bf2ca0 180 _TKN_HOST = 'tkn.porntube.com'
b3c65153
S
181 _TESTS = [{
182 'url': 'https://www.porntube.com/videos/teen-couple-doing-anal_7089759',
183 'info_dict': {
184 'id': '7089759',
185 'ext': 'mp4',
186 'title': 'Teen couple doing anal',
187 'uploader': 'Alexy',
15bf2ca0 188 'uploader_id': '91488',
b3c65153
S
189 'upload_date': '20150606',
190 'timestamp': 1433595647,
191 'duration': 5052,
192 'view_count': int,
193 'like_count': int,
b3c65153
S
194 'age_limit': 18,
195 },
196 'params': {
197 'skip_download': True,
198 },
127103b6
S
199 }, {
200 'url': 'https://www.porntube.com/videos/squirting-teen-ballerina-ecg_1331406',
201 'info_dict': {
202 'id': '1331406',
203 'ext': 'mp4',
204 'title': 'Squirting Teen Ballerina on ECG',
205 'uploader': 'Exploited College Girls',
206 'uploader_id': '665',
207 'channel': 'Exploited College Girls',
208 'channel_id': '665',
209 'upload_date': '20130920',
210 'timestamp': 1379685485,
211 'duration': 851,
212 'view_count': int,
213 'like_count': int,
214 'age_limit': 18,
215 },
216 'params': {
217 'skip_download': True,
218 },
b3c65153
S
219 }, {
220 'url': 'https://www.porntube.com/embed/7089759',
221 'only_matching': True,
222 }, {
223 'url': 'https://m.porntube.com/videos/teen-couple-doing-anal_7089759',
224 'only_matching': True,
225 }]
226
15bf2ca0 227 def _real_extract(self, url):
5ad28e7f 228 mobj = self._match_valid_url(url)
15bf2ca0
S
229 video_id, display_id = mobj.group('id', 'display_id')
230
231 webpage = self._download_webpage(url, display_id)
232
233 video = self._parse_json(
234 self._search_regex(
235 r'INITIALSTATE\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
236 webpage, 'data', group='value'), video_id,
237 transform_source=lambda x: compat_urllib_parse_unquote(
238 compat_b64decode(x).decode('utf-8')))['page']['video']
239
240 title = video['title']
241 media_id = video['mediaId']
242 sources = [compat_str(e['height'])
243 for e in video['encodings'] if e.get('height')]
244 formats = self._extract_formats(url, video_id, media_id, sources)
245
246 thumbnail = url_or_none(video.get('masterThumb'))
247 uploader = try_get(video, lambda x: x['user']['username'], compat_str)
127103b6
S
248 uploader_id = str_or_none(try_get(
249 video, lambda x: x['user']['id'], int))
250 channel = try_get(video, lambda x: x['channel']['name'], compat_str)
251 channel_id = str_or_none(try_get(
252 video, lambda x: x['channel']['id'], int))
15bf2ca0
S
253 like_count = int_or_none(video.get('likes'))
254 dislike_count = int_or_none(video.get('dislikes'))
255 view_count = int_or_none(video.get('playsQty'))
256 duration = int_or_none(video.get('durationInSeconds'))
257 timestamp = unified_timestamp(video.get('publishedAt'))
258
259 return {
260 'id': video_id,
261 'title': title,
262 'formats': formats,
263 'thumbnail': thumbnail,
127103b6
S
264 'uploader': uploader or channel,
265 'uploader_id': uploader_id or channel_id,
266 'channel': channel,
267 'channel_id': channel_id,
15bf2ca0
S
268 'timestamp': timestamp,
269 'like_count': like_count,
270 'dislike_count': dislike_count,
271 'view_count': view_count,
272 'duration': duration,
273 'age_limit': 18,
274 }
275
b3c65153
S
276
277class PornerBrosIE(FourTubeBaseIE):
278 _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?pornerbros\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)'
279 _URL_TEMPLATE = 'https://www.pornerbros.com/videos/video_%s'
c9856648 280 _TKN_HOST = 'token.pornerbros.com'
b3c65153
S
281 _TESTS = [{
282 'url': 'https://www.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369',
283 'md5': '6516c8ac63b03de06bc8eac14362db4f',
284 'info_dict': {
285 'id': '181369',
286 'ext': 'mp4',
287 'title': 'Skinny brunette takes big cock down her anal hole',
288 'uploader': 'PornerBros HD',
289 'uploader_id': 'pornerbros-hd',
290 'upload_date': '20130130',
291 'timestamp': 1359527401,
292 'duration': 1224,
293 'view_count': int,
294 'categories': list,
295 'age_limit': 18,
296 },
297 'params': {
298 'skip_download': True,
299 },
300 }, {
301 'url': 'https://www.pornerbros.com/embed/181369',
302 'only_matching': True,
303 }, {
304 'url': 'https://m.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369',
305 'only_matching': True,
306 }]