]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tempo.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / tempo.py
CommitLineData
30031be9
H
1import re
2
67685a54 3from .common import InfoExtractor
30031be9
H
4from ..utils import (
5 int_or_none,
6 parse_iso8601,
7 traverse_obj,
e897bd82 8 try_call,
30031be9
H
9)
10
11
12class IVXPlayerIE(InfoExtractor):
13 _VALID_URL = r'ivxplayer:(?P<video_id>\d+):(?P<player_key>\w+)'
14 _TESTS = [{
15 'url': 'ivxplayer:2366065:4a89dfe6bc8f002596b1dfbd600730b1',
16 'info_dict': {
17 'id': '2366065',
18 'ext': 'mp4',
19 'duration': 112,
20 'upload_date': '20221204',
21 'title': 'Film Indonesia di Disney Content Showcase Asia Pacific 2022',
22 'timestamp': 1670151746,
23 'thumbnail': 'https://ivx-image.ivideosmart.com/serve/image/video/2366065?width=300'
24 }
25 }]
26 _WEBPAGE_TESTS = [{
27 'url': 'https://www.cantika.com/video/31737/film-indonesia-di-disney-content-showcase-asia-pacific-2022',
28 'info_dict': {
29 'id': '2374200',
30 'ext': 'mp4',
31 'duration': 110,
32 'title': 'Serial Indonesia di Disney Content Showcase Asia Pacific 2022',
33 'timestamp': 1670639416,
34 'upload_date': '20221210',
35 'thumbnail': 'https://ivx-image.ivideosmart.com/serve/image/video/2374200?width=300'
36 }
37 }, {
38 'url': 'https://www.gooto.com/video/11437/wuling-suv-ramai-dikunjungi-di-giias-2018',
39 'info_dict': {
40 'id': '892109',
41 'ext': 'mp4',
42 'title': 'Wuling SUV Ramai Dikunjungi di GIIAS 2018',
43 'upload_date': '20180811',
44 'description': 'md5:6d901483d0aacc664aecb4489719aafa',
45 'duration': 75,
46 'timestamp': 1534011263,
47 'thumbnail': 'https://ivx-image.ivideosmart.com/serve/image/video/892109?width=300'
48 }
49 }]
50
51 @classmethod
52 def _extract_embed_urls(cls, url, webpage):
53 # more info at https://player.ivideosmart.com/ivsplayer/v4/dist/js/loader.js
54 mobj = re.search(
55 r'<ivs-player\s*[^>]+data-ivs-key\s*=\s*"(?P<player_key>[\w]+)\s*[^>]+\bdata-ivs-vid="(?P<video_id>[\w-]+)',
56 webpage)
57 if mobj:
58 yield f'ivxplayer:{mobj.group("video_id")}:{mobj.group("player_key")}'
59 raise cls.StopExtraction()
60
61 def _real_extract(self, url):
62 video_id, player_key = self._match_valid_url(url).group('video_id', 'player_key')
63 json_data = self._download_json(
64 f'https://ivxplayer.ivideosmart.com/prod/video/{video_id}?key={player_key}', video_id)
65
66 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
67 json_data['player']['video_url'], video_id)
68
69 return {
70 'id': str(json_data['ivx']['id']),
71 'title': traverse_obj(json_data, ('ivx', 'name')),
72 'description': traverse_obj(json_data, ('ivx', 'description')),
73 'duration': int_or_none(traverse_obj(json_data, ('ivx', 'duration'))),
74 'timestamp': parse_iso8601(traverse_obj(json_data, ('ivx', 'published_at'))),
75 'formats': formats,
76 'subtitles': subtitles,
77 'thumbnail': traverse_obj(json_data, ('ivx', 'thumbnail_url'))
78 }
67685a54
H
79
80
81class TempoIE(InfoExtractor):
82 _VALID_URL = r'https?://video\.tempo\.co/\w+/\d+/(?P<id>[\w-]+)'
83 _TESTS = [{
84 'url': 'https://video.tempo.co/read/30058/anies-baswedan-ajukan-banding-putusan-ptun-batalkan-ump-dki',
85 'info_dict': {
30031be9
H
86 'id': '2144275',
87 'display_id': 'anies-baswedan-ajukan-banding-putusan-ptun-batalkan-ump-dki',
67685a54
H
88 'ext': 'mp4',
89 'title': 'Anies Baswedan Ajukan Banding Putusan PTUN Batalkan UMP DKI',
30031be9 90 'duration': 85,
67685a54
H
91 'description': 'md5:a6822b7c4c874fa7e5bd63e96a387b66',
92 'thumbnail': 'https://statik.tempo.co/data/2022/07/27/id_1128287/1128287_720.jpg',
30031be9 93 'timestamp': 1658907970,
67685a54
H
94 'upload_date': '20220727',
95 'tags': ['Anies Baswedan', ' PTUN', ' PTUN | Pengadilan Tata Usaha Negara', ' PTUN Batalkan UMP DKI', ' UMP DKI'],
96 }
97 }]
98
99 def _real_extract(self, url):
100 display_id = self._match_id(url)
101 webpage = self._download_webpage(url, display_id)
102
30031be9 103 _, video_id, player_key = next(IVXPlayerIE._extract_embed_urls(url, webpage)).split(':')
67685a54
H
104
105 json_ld_data = self._search_json_ld(webpage, display_id)
106
30031be9
H
107 return self.url_result(
108 f'ivxplayer:{video_id}:{player_key}', display_id=display_id,
109 thumbnail=self._html_search_meta('twitter:image:src', webpage) or self._og_search_thumbnail(webpage),
110 tags=try_call(lambda: self._html_search_meta('keywords', webpage).split(',')),
111 description=(json_ld_data.get('description')
112 or self._html_search_meta(('description', 'twitter:description'), webpage)
113 or self._og_search_description(webpage)),
114 url_transparent=True)