Release 2024.12.03
[yt-dlp3.git] / yt_dlp / extractor / jixie.py
blob4830e61c1bdb5e5d20e6cd7d1e9067b89a3416f4
1 from .common import InfoExtractor
2 from ..utils import clean_html, float_or_none, traverse_obj, try_call
5 class JixieBaseIE(InfoExtractor):
6 """
7 API Reference:
8 https://jixie.atlassian.net/servicedesk/customer/portal/2/article/1339654214?src=-1456335525,
9 https://scripts.jixie.media/jxvideo.3.1.min.js
10 """
12 def _extract_data_from_jixie_id(self, display_id, video_id, webpage):
13 json_data = self._download_json(
14 'https://apidam.jixie.io/api/public/stream', display_id,
15 query={'metadata': 'full', 'video_id': video_id})['data']
17 formats, subtitles = [], {}
18 for stream in json_data['streams']:
19 if stream.get('type') == 'HLS':
20 fmt, sub = self._extract_m3u8_formats_and_subtitles(stream.get('url'), display_id, ext='mp4')
21 if json_data.get('drm'):
22 for f in fmt:
23 f['has_drm'] = True
24 formats.extend(fmt)
25 self._merge_subtitles(sub, target=subtitles)
26 else:
27 formats.append({
28 'url': stream.get('url'),
29 'width': stream.get('width'),
30 'height': stream.get('height'),
31 'ext': 'mp4',
34 return {
35 'id': video_id,
36 'display_id': display_id,
37 'formats': formats,
38 'subtitles': subtitles,
39 'title': json_data.get('title') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
40 'description': (clean_html(traverse_obj(json_data, ('metadata', 'description')))
41 or self._html_search_meta(['description', 'og:description', 'twitter:description'], webpage)),
42 'thumbnails': traverse_obj(json_data, ('metadata', 'thumbnails')),
43 'duration': float_or_none(traverse_obj(json_data, ('metadata', 'duration'))),
44 'tags': try_call(lambda: (json_data['metadata']['keywords'] or None).split(',')),
45 'categories': try_call(lambda: (json_data['metadata']['categories'] or None).split(',')),
46 'uploader_id': json_data.get('owner_id'),