]>
Commit | Line | Data |
---|---|---|
1fb707ba | 1 | import json |
1fb707ba | 2 | import random |
e897bd82 | 3 | import re |
1fb707ba | 4 | import urllib.parse |
e897bd82 | 5 | import uuid |
e7b6caef | 6 | |
7 | from .common import InfoExtractor | |
8 | from ..utils import ( | |
9 | ExtractorError, | |
10 | int_or_none, | |
72671a21 | 11 | remove_end, |
e897bd82 | 12 | smuggle_url, |
1fb707ba | 13 | strip_or_none, |
72671a21 | 14 | traverse_obj, |
a7191c6f | 15 | try_get, |
72671a21 | 16 | unified_timestamp, |
baa58739 | 17 | unsmuggle_url, |
1fb707ba | 18 | url_or_none, |
e7b6caef | 19 | ) |
20 | ||
21 | ||
22 | class ViuBaseIE(InfoExtractor): | |
1fb707ba | 23 | def _call_api(self, path, *args, headers={}, **kwargs): |
72310315 | 24 | response = self._download_json( |
1fb707ba | 25 | f'https://www.viu.com/api/{path}', *args, **kwargs, |
26 | headers={**self.geo_verification_headers(), **headers})['response'] | |
72310315 | 27 | if response.get('status') != 'success': |
1fb707ba | 28 | raise ExtractorError(f'{self.IE_NAME} said: {response["message"]}', expected=True) |
72310315 | 29 | return response |
e7b6caef | 30 | |
31 | ||
32 | class ViuIE(ViuBaseIE): | |
c183e14f | 33 | _VALID_URL = r'(?:viu:|https?://[^/]+\.viu\.com/[a-z]{2}/media/)(?P<id>\d+)' |
e7b6caef | 34 | _TESTS = [{ |
e7b6caef | 35 | 'url': 'https://www.viu.com/en/media/1116705532?containerId=playlist-22168059', |
36 | 'info_dict': { | |
37 | 'id': '1116705532', | |
38 | 'ext': 'mp4', | |
72310315 | 39 | 'title': 'Citizen Khan - Ep 1', |
e7b6caef | 40 | 'description': 'md5:d7ea1604f49e5ba79c212c551ce2110e', |
41 | }, | |
42 | 'params': { | |
43 | 'skip_download': 'm3u8 download', | |
44 | }, | |
45 | 'skip': 'Geo-restricted to India', | |
46 | }, { | |
47 | 'url': 'https://www.viu.com/en/media/1130599965', | |
48 | 'info_dict': { | |
49 | 'id': '1130599965', | |
50 | 'ext': 'mp4', | |
51 | 'title': 'Jealousy Incarnate - Episode 1', | |
52 | 'description': 'md5:d3d82375cab969415d2720b6894361e9', | |
53 | }, | |
54 | 'params': { | |
55 | 'skip_download': 'm3u8 download', | |
56 | }, | |
57 | 'skip': 'Geo-restricted to Indonesia', | |
c183e14f S |
58 | }, { |
59 | 'url': 'https://india.viu.com/en/media/1126286865', | |
60 | 'only_matching': True, | |
e7b6caef | 61 | }] |
62 | ||
63 | def _real_extract(self, url): | |
64 | video_id = self._match_id(url) | |
65 | ||
72310315 RA |
66 | video_data = self._call_api( |
67 | 'clip/load', video_id, 'Downloading video data', query={ | |
68 | 'appid': 'viu_desktop', | |
69 | 'fmt': 'json', | |
add96eb9 | 70 | 'id': video_id, |
72310315 RA |
71 | })['item'][0] |
72 | ||
73 | title = video_data['title'] | |
74 | ||
75 | m3u8_url = None | |
76 | url_path = video_data.get('urlpathd') or video_data.get('urlpath') | |
77 | tdirforwhole = video_data.get('tdirforwhole') | |
ed7b333f RA |
78 | # #EXT-X-BYTERANGE is not supported by native hls downloader |
79 | # and ffmpeg (#10955) | |
1fb707ba | 80 | # FIXME: It is supported in yt-dlp |
ed7b333f RA |
81 | # hls_file = video_data.get('hlsfile') |
82 | hls_file = video_data.get('jwhlsfile') | |
72310315 | 83 | if url_path and tdirforwhole and hls_file: |
add96eb9 | 84 | m3u8_url = f'{url_path}/{tdirforwhole}/{hls_file}' |
72310315 | 85 | else: |
ed7b333f RA |
86 | # m3u8_url = re.sub( |
87 | # r'(/hlsc_)[a-z]+(\d+\.m3u8)', | |
88 | # r'\1whe\2', video_data['href']) | |
89 | m3u8_url = video_data['href'] | |
47b8bf20 | 90 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, 'mp4') |
e7b6caef | 91 | |
72310315 RA |
92 | for key, value in video_data.items(): |
93 | mobj = re.match(r'^subtitle_(?P<lang>[^_]+)_(?P<ext>(vtt|srt))', key) | |
94 | if not mobj: | |
95 | continue | |
96 | subtitles.setdefault(mobj.group('lang'), []).append({ | |
97 | 'url': value, | |
add96eb9 | 98 | 'ext': mobj.group('ext'), |
72310315 | 99 | }) |
e7b6caef | 100 | |
101 | return { | |
102 | 'id': video_id, | |
103 | 'title': title, | |
72310315 RA |
104 | 'description': video_data.get('description'), |
105 | 'series': video_data.get('moviealbumshowname'), | |
106 | 'episode': title, | |
107 | 'episode_number': int_or_none(video_data.get('episodeno')), | |
108 | 'duration': int_or_none(video_data.get('duration')), | |
e7b6caef | 109 | 'formats': formats, |
110 | 'subtitles': subtitles, | |
111 | } | |
112 | ||
113 | ||
114 | class ViuPlaylistIE(ViuBaseIE): | |
115 | IE_NAME = 'viu:playlist' | |
72310315 | 116 | _VALID_URL = r'https?://www\.viu\.com/[^/]+/listing/playlist-(?P<id>\d+)' |
e7b6caef | 117 | _TEST = { |
118 | 'url': 'https://www.viu.com/en/listing/playlist-22461380', | |
119 | 'info_dict': { | |
72310315 | 120 | 'id': '22461380', |
e7b6caef | 121 | 'title': 'The Good Wife', |
122 | }, | |
123 | 'playlist_count': 16, | |
124 | 'skip': 'Geo-restricted to Indonesia', | |
125 | } | |
126 | ||
127 | def _real_extract(self, url): | |
128 | playlist_id = self._match_id(url) | |
72310315 RA |
129 | playlist_data = self._call_api( |
130 | 'container/load', playlist_id, | |
131 | 'Downloading playlist info', query={ | |
132 | 'appid': 'viu_desktop', | |
133 | 'fmt': 'json', | |
add96eb9 | 134 | 'id': 'playlist-' + playlist_id, |
72310315 RA |
135 | })['container'] |
136 | ||
137 | entries = [] | |
138 | for item in playlist_data.get('item', []): | |
139 | item_id = item.get('id') | |
140 | if not item_id: | |
141 | continue | |
add96eb9 | 142 | item_id = str(item_id) |
72310315 RA |
143 | entries.append(self.url_result( |
144 | 'viu:' + item_id, 'Viu', item_id)) | |
145 | ||
146 | return self.playlist_result( | |
147 | entries, playlist_id, playlist_data.get('title')) | |
148 | ||
149 | ||
150 | class ViuOTTIE(InfoExtractor): | |
151 | IE_NAME = 'viu:ott' | |
baa58739 | 152 | _NETRC_MACHINE = 'viu' |
153 | _VALID_URL = r'https?://(?:www\.)?viu\.com/ott/(?P<country_code>[a-z]{2})/(?P<lang_code>[a-z]{2}-[a-z]{2})/vod/(?P<id>\d+)' | |
72310315 RA |
154 | _TESTS = [{ |
155 | 'url': 'http://www.viu.com/ott/sg/en-us/vod/3421/The%20Prime%20Minister%20and%20I', | |
156 | 'info_dict': { | |
157 | 'id': '3421', | |
158 | 'ext': 'mp4', | |
159 | 'title': 'A New Beginning', | |
160 | 'description': 'md5:1e7486a619b6399b25ba6a41c0fe5b2c', | |
161 | }, | |
162 | 'params': { | |
163 | 'skip_download': 'm3u8 download', | |
baa58739 | 164 | 'noplaylist': True, |
72310315 RA |
165 | }, |
166 | 'skip': 'Geo-restricted to Singapore', | |
167 | }, { | |
f324fe8c | 168 | 'url': 'https://www.viu.com/ott/hk/zh-hk/vod/430078/%E7%AC%AC%E5%85%AD%E6%84%9F-3', |
72310315 | 169 | 'info_dict': { |
f324fe8c | 170 | 'id': '430078', |
72310315 | 171 | 'ext': 'mp4', |
f324fe8c | 172 | 'title': '大韓民國的1%', |
173 | 'description': 'md5:74d6db47ddd9ddb9c89a05739103ccdb', | |
174 | 'episode_number': 1, | |
175 | 'duration': 6614, | |
176 | 'episode': '大韓民國的1%', | |
177 | 'series': '第六感 3', | |
178 | 'thumbnail': 'https://d2anahhhmp1ffz.cloudfront.net/1313295781/d2b14f48d008ef2f3a9200c98d8e9b63967b9cc2', | |
72310315 RA |
179 | }, |
180 | 'params': { | |
181 | 'skip_download': 'm3u8 download', | |
baa58739 | 182 | 'noplaylist': True, |
183 | }, | |
184 | 'skip': 'Geo-restricted to Hong Kong', | |
185 | }, { | |
f324fe8c | 186 | 'url': 'https://www.viu.com/ott/hk/zh-hk/vod/444666/%E6%88%91%E7%9A%84%E5%AE%A4%E5%8F%8B%E6%98%AF%E4%B9%9D%E5%B0%BE%E7%8B%90', |
187 | 'playlist_count': 16, | |
baa58739 | 188 | 'info_dict': { |
f324fe8c | 189 | 'id': '23807', |
190 | 'title': '我的室友是九尾狐', | |
191 | 'description': 'md5:b42c95f2b4a316cdd6ae14ca695f33b9', | |
baa58739 | 192 | }, |
193 | 'params': { | |
194 | 'skip_download': 'm3u8 download', | |
195 | 'noplaylist': False, | |
72310315 RA |
196 | }, |
197 | 'skip': 'Geo-restricted to Hong Kong', | |
198 | }] | |
199 | ||
ecb6b6ae S |
200 | _AREA_ID = { |
201 | 'HK': 1, | |
202 | 'SG': 2, | |
203 | 'TH': 4, | |
204 | 'PH': 5, | |
205 | } | |
baa58739 | 206 | _LANGUAGE_FLAG = { |
207 | 'zh-hk': 1, | |
208 | 'zh-cn': 2, | |
209 | 'en-us': 3, | |
210 | } | |
1fb707ba | 211 | |
212 | _user_token = None | |
213 | _auth_codes = {} | |
baa58739 | 214 | |
215 | def _detect_error(self, response): | |
1fb707ba | 216 | code = try_get(response, lambda x: x['status']['code']) |
217 | if code and code > 0: | |
baa58739 | 218 | message = try_get(response, lambda x: x['status']['message']) |
1fb707ba | 219 | raise ExtractorError(f'{self.IE_NAME} said: {message} ({code})', expected=True) |
220 | return response.get('data') or {} | |
baa58739 | 221 | |
222 | def _login(self, country_code, video_id): | |
1fb707ba | 223 | if self._user_token is None: |
baa58739 | 224 | username, password = self._get_login_info() |
1fb707ba | 225 | if username is None: |
baa58739 | 226 | return |
1fb707ba | 227 | headers = { |
228 | 'Authorization': f'Bearer {self._auth_codes[country_code]}', | |
add96eb9 | 229 | 'Content-Type': 'application/json', |
1fb707ba | 230 | } |
231 | data = self._download_json( | |
232 | 'https://api-gateway-global.viu.com/api/account/validate', | |
233 | video_id, 'Validating email address', headers=headers, | |
234 | data=json.dumps({ | |
235 | 'principal': username, | |
add96eb9 | 236 | 'provider': 'email', |
1fb707ba | 237 | }).encode()) |
238 | if not data.get('exists'): | |
239 | raise ExtractorError('Invalid email address') | |
baa58739 | 240 | |
241 | data = self._download_json( | |
1fb707ba | 242 | 'https://api-gateway-global.viu.com/api/auth/login', |
243 | video_id, 'Logging in', headers=headers, | |
baa58739 | 244 | data=json.dumps({ |
1fb707ba | 245 | 'email': username, |
baa58739 | 246 | 'password': password, |
1fb707ba | 247 | 'provider': 'email', |
baa58739 | 248 | }).encode()) |
1fb707ba | 249 | self._detect_error(data) |
250 | self._user_token = data.get('identity') | |
251 | # need to update with valid user's token else will throw an error again | |
252 | self._auth_codes[country_code] = data.get('token') | |
253 | return self._user_token | |
254 | ||
255 | def _get_token(self, country_code, video_id): | |
efa944f4 | 256 | rand = ''.join(random.choices('0123456789', k=10)) |
1fb707ba | 257 | return self._download_json( |
258 | f'https://api-gateway-global.viu.com/api/auth/token?v={rand}000', video_id, | |
259 | headers={'Content-Type': 'application/json'}, note='Getting bearer token', | |
260 | data=json.dumps({ | |
261 | 'countryCode': country_code.upper(), | |
262 | 'platform': 'browser', | |
263 | 'platformFlagLabel': 'web', | |
264 | 'language': 'en', | |
265 | 'uuid': str(uuid.uuid4()), | |
add96eb9 | 266 | 'carrierId': '0', |
267 | }).encode())['token'] | |
ecb6b6ae | 268 | |
72310315 | 269 | def _real_extract(self, url): |
baa58739 | 270 | url, idata = unsmuggle_url(url, {}) |
5ad28e7f | 271 | country_code, lang_code, video_id = self._match_valid_url(url).groups() |
72310315 | 272 | |
ecb6b6ae S |
273 | query = { |
274 | 'r': 'vod/ajax-detail', | |
275 | 'platform_flag_label': 'web', | |
276 | 'product_id': video_id, | |
277 | } | |
278 | ||
279 | area_id = self._AREA_ID.get(country_code.upper()) | |
280 | if area_id: | |
281 | query['area_id'] = area_id | |
282 | ||
72310315 | 283 | product_data = self._download_json( |
1fb707ba | 284 | f'http://www.viu.com/ott/{country_code}/index.php', video_id, |
ecb6b6ae | 285 | 'Downloading video info', query=query)['data'] |
72310315 RA |
286 | |
287 | video_data = product_data.get('current_product') | |
288 | if not video_data: | |
1fb707ba | 289 | self.raise_geo_restricted() |
72310315 | 290 | |
baa58739 | 291 | series_id = video_data.get('series_id') |
f40ee5e9 | 292 | if self._yes_playlist(series_id, video_id, idata): |
1fb707ba | 293 | series = product_data.get('series') or {} |
baa58739 | 294 | product = series.get('product') |
295 | if product: | |
296 | entries = [] | |
297 | for entry in sorted(product, key=lambda x: int_or_none(x.get('number', 0))): | |
298 | item_id = entry.get('product_id') | |
299 | if not item_id: | |
300 | continue | |
baa58739 | 301 | entries.append(self.url_result( |
1fb707ba | 302 | smuggle_url(f'http://www.viu.com/ott/{country_code}/{lang_code}/vod/{item_id}/', |
303 | {'force_noplaylist': True}), | |
304 | ViuOTTIE, str(item_id), entry.get('synopsis', '').strip())) | |
baa58739 | 305 | |
306 | return self.playlist_result(entries, series_id, series.get('name'), series.get('description')) | |
307 | ||
baa58739 | 308 | duration_limit = False |
309 | query = { | |
310 | 'ccs_product_id': video_data['ccs_product_id'], | |
311 | 'language_flag_id': self._LANGUAGE_FLAG.get(lang_code.lower()) or '3', | |
312 | } | |
1fb707ba | 313 | |
314 | def download_playback(): | |
baa58739 | 315 | stream_data = self._download_json( |
1fb707ba | 316 | 'https://api-gateway-global.viu.com/api/playback/distribute', |
317 | video_id=video_id, query=query, fatal=False, note='Downloading stream info', | |
318 | headers={ | |
319 | 'Authorization': f'Bearer {self._auth_codes[country_code]}', | |
320 | 'Referer': url, | |
add96eb9 | 321 | 'Origin': url, |
1fb707ba | 322 | }) |
323 | return self._detect_error(stream_data).get('stream') | |
324 | ||
325 | if not self._auth_codes.get(country_code): | |
326 | self._auth_codes[country_code] = self._get_token(country_code, video_id) | |
baa58739 | 327 | |
1fb707ba | 328 | stream_data = None |
329 | try: | |
330 | stream_data = download_playback() | |
331 | except (ExtractorError, KeyError): | |
332 | token = self._login(country_code, video_id) | |
333 | if token is not None: | |
334 | query['identity'] = token | |
335 | else: | |
c418e6b5 | 336 | # The content is Preview or for VIP only. |
337 | # We can try to bypass the duration which is limited to 3mins only | |
1fb707ba | 338 | duration_limit, query['duration'] = True, '180' |
339 | try: | |
340 | stream_data = download_playback() | |
341 | except (ExtractorError, KeyError): | |
342 | if token is not None: | |
343 | raise | |
344 | self.raise_login_required(method='password') | |
baa58739 | 345 | if not stream_data: |
346 | raise ExtractorError('Cannot get stream info', expected=True) | |
72310315 | 347 | |
72310315 | 348 | formats = [] |
1fb707ba | 349 | for vid_format, stream_url in (stream_data.get('url') or {}).items(): |
350 | height = int(self._search_regex(r's(\d+)p', vid_format, 'height', default=None)) | |
baa58739 | 351 | |
352 | # bypass preview duration limit | |
353 | if duration_limit: | |
c418e6b5 | 354 | old_stream_url = urllib.parse.urlparse(stream_url) |
355 | query = dict(urllib.parse.parse_qsl(old_stream_url.query, keep_blank_values=True)) | |
baa58739 | 356 | query.update({ |
1fb707ba | 357 | 'duration': video_data.get('time_duration') or '9999999', |
baa58739 | 358 | 'duration_start': '0', |
359 | }) | |
c418e6b5 | 360 | stream_url = old_stream_url._replace(query=urllib.parse.urlencode(query)).geturl() |
baa58739 | 361 | |
72310315 RA |
362 | formats.append({ |
363 | 'format_id': vid_format, | |
364 | 'url': stream_url, | |
365 | 'height': height, | |
366 | 'ext': 'mp4', | |
add96eb9 | 367 | 'filesize': try_get(stream_data, lambda x: x['size'][vid_format], int), |
72310315 | 368 | }) |
72310315 RA |
369 | |
370 | subtitles = {} | |
1fb707ba | 371 | for sub in video_data.get('subtitle') or []: |
f324fe8c | 372 | lang = sub.get('name') or 'und' |
373 | if sub.get('url'): | |
374 | subtitles.setdefault(lang, []).append({ | |
375 | 'url': sub['url'], | |
376 | 'ext': 'srt', | |
377 | 'name': f'Spoken text for {lang}', | |
378 | }) | |
379 | if sub.get('second_subtitle_url'): | |
380 | subtitles.setdefault(f'{lang}_ost', []).append({ | |
381 | 'url': sub['second_subtitle_url'], | |
382 | 'ext': 'srt', | |
383 | 'name': f'On-screen text for {lang}', | |
384 | }) | |
72310315 | 385 | |
1fb707ba | 386 | title = strip_or_none(video_data.get('synopsis')) |
72310315 RA |
387 | return { |
388 | 'id': video_id, | |
389 | 'title': title, | |
390 | 'description': video_data.get('description'), | |
1fb707ba | 391 | 'series': try_get(product_data, lambda x: x['series']['name']), |
72310315 RA |
392 | 'episode': title, |
393 | 'episode_number': int_or_none(video_data.get('number')), | |
394 | 'duration': int_or_none(stream_data.get('duration')), | |
1fb707ba | 395 | 'thumbnail': url_or_none(video_data.get('cover_image_url')), |
72310315 RA |
396 | 'formats': formats, |
397 | 'subtitles': subtitles, | |
398 | } | |
72671a21 H |
399 | |
400 | ||
401 | class ViuOTTIndonesiaBaseIE(InfoExtractor): | |
402 | _BASE_QUERY = { | |
403 | 'ver': 1.0, | |
404 | 'fmt': 'json', | |
405 | 'aver': 5.0, | |
406 | 'appver': 2.0, | |
407 | 'appid': 'viu_desktop', | |
408 | 'platform': 'desktop', | |
409 | } | |
410 | ||
411 | _DEVICE_ID = str(uuid.uuid4()) | |
412 | _SESSION_ID = str(uuid.uuid4()) | |
413 | _TOKEN = None | |
414 | ||
415 | _HEADERS = { | |
416 | 'x-session-id': _SESSION_ID, | |
add96eb9 | 417 | 'x-client': 'browser', |
72671a21 H |
418 | } |
419 | ||
420 | _AGE_RATINGS_MAPPER = { | |
421 | 'ADULTS': 18, | |
add96eb9 | 422 | 'teens': 13, |
72671a21 H |
423 | } |
424 | ||
425 | def _real_initialize(self): | |
426 | ViuOTTIndonesiaBaseIE._TOKEN = self._download_json( | |
427 | 'https://um.viuapi.io/user/identity', None, | |
428 | headers={'Content-type': 'application/json', **self._HEADERS}, | |
429 | query={**self._BASE_QUERY, 'iid': self._DEVICE_ID}, | |
430 | data=json.dumps({'deviceId': self._DEVICE_ID}).encode(), | |
431 | note='Downloading token information')['token'] | |
432 | ||
433 | ||
434 | class ViuOTTIndonesiaIE(ViuOTTIndonesiaBaseIE): | |
435 | _VALID_URL = r'https?://www\.viu\.com/ott/\w+/\w+/all/video-[\w-]+-(?P<id>\d+)' | |
436 | _TESTS = [{ | |
437 | 'url': 'https://www.viu.com/ott/id/id/all/video-japanese-drama-tv_shows-detective_conan_episode_793-1165863142?containerId=playlist-26271226', | |
438 | 'info_dict': { | |
439 | 'id': '1165863142', | |
440 | 'ext': 'mp4', | |
441 | 'episode_number': 793, | |
442 | 'episode': 'Episode 793', | |
443 | 'title': 'Detective Conan - Episode 793', | |
444 | 'duration': 1476, | |
445 | 'description': 'md5:b79d55345bc1e0217ece22616267c9a5', | |
446 | 'thumbnail': 'https://vuclipi-a.akamaihd.net/p/cloudinary/h_171,w_304,dpr_1.5,f_auto,c_thumb,q_auto:low/1165863189/d-1', | |
447 | 'upload_date': '20210101', | |
448 | 'timestamp': 1609459200, | |
add96eb9 | 449 | }, |
72671a21 H |
450 | }, { |
451 | 'url': 'https://www.viu.com/ott/id/id/all/video-korean-reality-tv_shows-entertainment_weekly_episode_1622-1118617054', | |
452 | 'info_dict': { | |
453 | 'id': '1118617054', | |
454 | 'ext': 'mp4', | |
455 | 'episode_number': 1622, | |
456 | 'episode': 'Episode 1622', | |
457 | 'description': 'md5:6d68ca450004020113e9bf27ad99f0f8', | |
458 | 'title': 'Entertainment Weekly - Episode 1622', | |
459 | 'duration': 4729, | |
460 | 'thumbnail': 'https://vuclipi-a.akamaihd.net/p/cloudinary/h_171,w_304,dpr_1.5,f_auto,c_thumb,q_auto:low/1120187848/d-1', | |
461 | 'timestamp': 1420070400, | |
462 | 'upload_date': '20150101', | |
add96eb9 | 463 | 'cast': ['Shin Hyun-joon', 'Lee Da-Hee'], |
464 | }, | |
72671a21 H |
465 | }, { |
466 | # age-limit test | |
467 | 'url': 'https://www.viu.com/ott/id/id/all/video-japanese-trailer-tv_shows-trailer_jujutsu_kaisen_ver_01-1166044219?containerId=playlist-26273140', | |
468 | 'info_dict': { | |
469 | 'id': '1166044219', | |
470 | 'ext': 'mp4', | |
471 | 'upload_date': '20200101', | |
472 | 'timestamp': 1577836800, | |
473 | 'title': 'Trailer \'Jujutsu Kaisen\' Ver.01', | |
474 | 'duration': 92, | |
475 | 'thumbnail': 'https://vuclipi-a.akamaihd.net/p/cloudinary/h_171,w_304,dpr_1.5,f_auto,c_thumb,q_auto:low/1166044240/d-1', | |
476 | 'description': 'Trailer \'Jujutsu Kaisen\' Ver.01', | |
477 | 'cast': ['Junya Enoki', ' Yûichi Nakamura', ' Yuma Uchida', 'Asami Seto'], | |
478 | 'age_limit': 13, | |
add96eb9 | 479 | }, |
72671a21 H |
480 | }, { |
481 | # json ld metadata type equal to Movie instead of TVEpisodes | |
482 | 'url': 'https://www.viu.com/ott/id/id/all/video-japanese-animation-movies-demon_slayer_kimetsu_no_yaiba_the_movie_mugen_train-1165892707?containerId=1675060691786', | |
483 | 'info_dict': { | |
484 | 'id': '1165892707', | |
485 | 'ext': 'mp4', | |
486 | 'timestamp': 1577836800, | |
487 | 'upload_date': '20200101', | |
488 | 'title': 'Demon Slayer - Kimetsu no Yaiba - The Movie: Mugen Train', | |
489 | 'age_limit': 13, | |
490 | 'cast': 'count:9', | |
491 | 'thumbnail': 'https://vuclipi-a.akamaihd.net/p/cloudinary/h_171,w_304,dpr_1.5,f_auto,c_thumb,q_auto:low/1165895279/d-1', | |
492 | 'description': 'md5:1ce9c35a3aeab384085533f746c87469', | |
493 | 'duration': 7021, | |
add96eb9 | 494 | }, |
72671a21 H |
495 | }] |
496 | ||
497 | def _real_extract(self, url): | |
498 | display_id = self._match_id(url) | |
499 | webpage = self._download_webpage(url, display_id) | |
500 | ||
501 | video_data = self._download_json( | |
502 | f'https://um.viuapi.io/drm/v1/content/{display_id}', display_id, data=b'', | |
503 | headers={'Authorization': ViuOTTIndonesiaBaseIE._TOKEN, **self._HEADERS, 'ccode': 'ID'}) | |
504 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_data['playUrl'], display_id) | |
505 | ||
506 | initial_state = self._search_json( | |
507 | r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', | |
508 | display_id)['content']['clipDetails'] | |
509 | for key, url in initial_state.items(): | |
510 | lang, ext = self._search_regex( | |
511 | r'^subtitle_(?P<lang>[\w-]+)_(?P<ext>\w+)$', key, 'subtitle metadata', | |
512 | default=(None, None), group=('lang', 'ext')) | |
513 | if lang and ext: | |
514 | subtitles.setdefault(lang, []).append({ | |
515 | 'ext': ext, | |
516 | 'url': url, | |
517 | }) | |
518 | ||
519 | if ext == 'vtt': | |
520 | subtitles[lang].append({ | |
521 | 'ext': 'srt', | |
522 | 'url': f'{remove_end(initial_state[key], "vtt")}srt', | |
523 | }) | |
524 | ||
525 | episode = traverse_obj(list(filter( | |
526 | lambda x: x.get('@type') in ('TVEpisode', 'Movie'), self._yield_json_ld(webpage, display_id))), 0) or {} | |
527 | return { | |
528 | 'id': display_id, | |
529 | 'title': (traverse_obj(initial_state, 'title', 'display_title') | |
530 | or episode.get('name')), | |
531 | 'description': initial_state.get('description') or episode.get('description'), | |
532 | 'duration': initial_state.get('duration'), | |
533 | 'thumbnail': traverse_obj(episode, ('image', 'url')), | |
534 | 'timestamp': unified_timestamp(episode.get('dateCreated')), | |
535 | 'formats': formats, | |
536 | 'subtitles': subtitles, | |
537 | 'episode_number': (traverse_obj(initial_state, 'episode_no', 'episodeno', expected_type=int_or_none) | |
538 | or int_or_none(episode.get('episodeNumber'))), | |
539 | 'cast': traverse_obj(episode, ('actor', ..., 'name'), default=None), | |
add96eb9 | 540 | 'age_limit': self._AGE_RATINGS_MAPPER.get(initial_state.get('internal_age_rating')), |
72671a21 | 541 | } |