]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/kompas.py
[cleanup] Misc
[yt-dlp.git] / yt_dlp / extractor / kompas.py
index d400c42f371d5f1c6962d7d105cfab7e84d2fde4..8bad9619061643dcbd816f0fe73ae41f630af833 100644 (file)
@@ -1,17 +1,7 @@
-from .common import InfoExtractor
-from ..utils import (
-    clean_html,
-    float_or_none,
-    traverse_obj,
-    try_call,
-)
+from .jixie import JixieBaseIE
 
-# Video from www.kompas.tv and video.kompas.com seems use jixie player
-# see [1] https://jixie.atlassian.net/servicedesk/customer/portal/2/article/1339654214?src=-1456335525,
-# [2] https://scripts.jixie.media/jxvideo.3.1.min.js for more info
 
-
-class KompasVideoIE(InfoExtractor):
+class KompasVideoIE(JixieBaseIE):
     _VALID_URL = r'https?://video\.kompas\.com/\w+/(?P<id>\d+)/(?P<slug>[\w-]+)'
     _TESTS = [{
         'url': 'https://video.kompas.com/watch/164474/kim-jong-un-siap-kirim-nuklir-lawan-as-dan-korsel',
@@ -33,36 +23,4 @@ def _real_extract(self, url):
         video_id, display_id = self._match_valid_url(url).group('id', 'slug')
         webpage = self._download_webpage(url, display_id)
 
-        json_data = self._download_json(
-            'https://apidam.jixie.io/api/public/stream', display_id,
-            query={'metadata': 'full', 'video_id': video_id})['data']
-
-        formats, subtitles = [], {}
-        for stream in json_data['streams']:
-            if stream.get('type') == 'HLS':
-                fmt, sub = self._extract_m3u8_formats_and_subtitles(stream.get('url'), display_id, ext='mp4')
-                formats.extend(fmt)
-                self._merge_subtitles(sub, target=subtitles)
-            else:
-                formats.append({
-                    'url': stream.get('url'),
-                    'width': stream.get('width'),
-                    'height': stream.get('height'),
-                    'ext': 'mp4',
-                })
-
-        self._sort_formats(formats)
-        return {
-            'id': video_id,
-            'display_id': display_id,
-            'formats': formats,
-            'subtitles': subtitles,
-            'title': json_data.get('title') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
-            'description': (clean_html(traverse_obj(json_data, ('metadata', 'description')))
-                            or self._html_search_meta(['description', 'og:description', 'twitter:description'], webpage)),
-            'thumbnails': traverse_obj(json_data, ('metadata', 'thumbnails')),
-            'duration': float_or_none(traverse_obj(json_data, ('metadata', 'duration'))),
-            'tags': try_call(lambda: json_data['metadata']['keywords'].split(',')),
-            'categories': try_call(lambda: json_data['metadata']['categories'].split(',')),
-            'uploader_id': json_data.get('owner_id'),
-        }
+        return self._extract_data_from_jixie_id(display_id, video_id, webpage)