[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / detik.py
blobf1480542469659a46d041f9c1507f39ce761cfbb
1 from .common import InfoExtractor
2 from ..utils import int_or_none, merge_dicts, try_call, url_basename
5 class DetikEmbedIE(InfoExtractor):
6 _VALID_URL = False
7 _WEBPAGE_TESTS = [{
8 # cnn embed
9 'url': 'https://www.cnnindonesia.com/embed/video/846189',
10 'info_dict': {
11 'id': '846189',
12 'ext': 'mp4',
13 'description': 'md5:ece7b003b3ee7d81c6a5cfede7d5397d',
14 'thumbnail': r're:https?://akcdn\.detik\.net\.id/visual/2022/09/11/thumbnail-video-1_169.jpeg',
15 'title': 'Video CNN Indonesia - VIDEO: Momen Charles Disambut Meriah usai Dilantik jadi Raja Inggris',
16 'age_limit': 0,
17 'tags': ['raja charles', ' raja charles iii', ' ratu elizabeth', ' ratu elizabeth meninggal dunia', ' raja inggris', ' inggris'],
18 'release_timestamp': 1662869995,
19 'release_date': '20220911',
20 'uploader': 'REUTERS'
22 }, {
23 # 20.detik
24 'url': 'https://20.detik.com/otobuzz/20220704-220704093/mulai-rp-10-jutaan-ini-skema-kredit-mitsubishi-pajero-sport',
25 'info_dict': {
26 'display_id': 'mulai-rp-10-jutaan-ini-skema-kredit-mitsubishi-pajero-sport',
27 'id': '220704093',
28 'ext': 'mp4',
29 'description': 'md5:9b2257341b6f375cdcf90106146d5ffb',
30 'thumbnail': r're:https?://cdnv\.detik\.com/videoservice/AdminTV/2022/07/04/5d6187e402ec4a91877755a5886ff5b6-20220704161859-0s.jpg',
31 'title': 'Mulai Rp 10 Jutaan! Ini Skema Kredit Mitsubishi Pajero Sport',
32 'timestamp': 1656951521,
33 'upload_date': '20220704',
34 'duration': 83.0,
35 'tags': ['cicilan mobil', 'mitsubishi pajero sport', 'mitsubishi', 'pajero sport'],
36 'release_timestamp': 1656926321,
37 'release_date': '20220704',
38 'age_limit': 0,
39 'uploader': 'Ridwan Arifin ' # TODO: strip trailling whitespace at uploader
41 }, {
42 # pasangmata.detik
43 'url': 'https://pasangmata.detik.com/contribution/366649',
44 'info_dict': {
45 'id': '366649',
46 'ext': 'mp4',
47 'title': 'Saling Dorong Aparat dan Pendemo di Aksi Tolak Kenaikan BBM',
48 'description': 'md5:7a6580876c8381c454679e028620bea7',
49 'age_limit': 0,
50 'tags': 'count:17',
51 'thumbnail': 'https://akcdn.detik.net.id/community/data/media/thumbs-pasangmata/2022/09/08/366649-16626229351533009620.mp4-03.jpg',
53 }, {
54 # insertlive embed
55 'url': 'https://www.insertlive.com/embed/video/290482',
56 'info_dict': {
57 'id': '290482',
58 'ext': 'mp4',
59 'release_timestamp': 1663063704,
60 'thumbnail': 'https://akcdn.detik.net.id/visual/2022/09/13/leonardo-dicaprio_169.png?w=600&q=90',
61 'age_limit': 0,
62 'description': 'Aktor Leonardo DiCaprio memang baru saja putus dari kekasihnya yang bernama Camilla Morrone.',
63 'release_date': '20220913',
64 'title': 'Diincar Leonardo DiCaprio, Gigi Hadid Ngaku Tertarik Tapi Belum Cinta',
65 'tags': ['leonardo dicaprio', ' gigi hadid', ' hollywood'],
66 'uploader': '!nsertlive',
68 }, {
69 # beautynesia embed
70 'url': 'https://www.beautynesia.id/embed/video/261636',
71 'info_dict': {
72 'id': '261636',
73 'ext': 'mp4',
74 'age_limit': 0,
75 'release_timestamp': 1662375600,
76 'description': 'Menurut ramalan astrologi, tiga zodiak ini bakal hoki sepanjang September 2022.',
77 'title': '3 Zodiak Paling Beruntung Selama September 2022',
78 'release_date': '20220905',
79 'tags': ['zodiac update', ' zodiak', ' ramalan bintang', ' zodiak beruntung 2022', ' zodiak hoki september 2022', ' zodiak beruntung september 2022'],
80 'thumbnail': 'https://akcdn.detik.net.id/visual/2022/09/05/3-zodiak-paling-beruntung-selama-september-2022_169.jpeg?w=600&q=90',
81 'uploader': 'amh',
83 }, {
84 # cnbcindonesia embed
85 'url': 'https://www.cnbcindonesia.com/embed/video/371839',
86 'info_dict': {
87 'id': '371839',
88 'ext': 'mp4',
89 'title': 'Puluhan Pejabat Rusia Tuntut Putin Mundur',
90 'tags': ['putin'],
91 'age_limit': 0,
92 'thumbnail': 'https://awsimages.detik.net.id/visual/2022/09/13/cnbc-indonesia-tv-3_169.png?w=600&q=80',
93 'description': 'md5:8b9111e37555fcd95fe549a9b4ae6fdc',
95 }, {
96 # detik shortlink (we can get it from https://dtk.id/?<url>)
97 'url': 'https://dtk.id/NkISKr',
98 'info_dict': {
99 'id': '220914049',
100 'ext': 'mp4',
101 'release_timestamp': 1663114488,
102 'uploader': 'Tim 20Detik',
103 'title': 'Pakar Bicara soal Tim Khusus Jokowi dan Mereka yang Pro ke Bjorka',
104 'age_limit': 0,
105 'thumbnail': 'https://cdnv.detik.com/videoservice/AdminTV/2022/09/14/f15cae71d7b640c58e75b254ecbb1ce1-20220914071613-0s.jpg?w=400&q=80',
106 'display_id': 'pakar-bicara-soal-tim-khusus-jokowi-dan-mereka-yang-pro-ke-bjorka',
107 'upload_date': '20220914',
108 'release_date': '20220914',
109 'description': 'md5:5eb03225f7ee40207dd3a1e18a73f1ff',
110 'timestamp': 1663139688,
111 'duration': 213.0,
112 'tags': ['hacker bjorka', 'bjorka', 'hacker bjorka bocorkan data rahasia presiden jokowi', 'jokowi'],
116 def _extract_from_webpage(self, url, webpage):
117 player_type, video_data = self._search_regex(
118 r'<script\s*[^>]+src="https?://(aws)?cdn\.detik\.net\.id/(?P<type>flowplayer|detikVideo)[^>]+>\s*(?P<video_data>{[^}]+})',
119 webpage, 'playerjs', group=('type', 'video_data'), default=(None, ''))
120 if not player_type:
121 return
123 display_id, extra_info_dict = url_basename(url), {}
125 if player_type == 'flowplayer':
126 video_json_data = self._parse_json(video_data.replace('\'', '"'), display_id)
127 video_url = video_json_data['videoUrl']
129 extra_info_dict = {
130 'id': self._search_regex(r'identifier\s*:\s*\'([^\']+)', webpage, 'identifier'),
131 'thumbnail': video_json_data.get('imageUrl'),
134 elif player_type == 'detikVideo':
135 video_url = self._search_regex(
136 r'videoUrl\s*:\s*[\'"]?([^"\']+)', video_data, 'videoUrl')
137 extra_info_dict = {
138 'id': self._html_search_meta(['video_id', 'dtk:video_id'], webpage),
139 'thumbnail': self._search_regex(r'imageUrl\s*:\s*[\'"]?([^"\']+)', video_data, 'videoUrl'),
140 'duration': int_or_none(self._html_search_meta('duration', webpage, fatal=False, default=None)),
141 'release_timestamp': int_or_none(self._html_search_meta('dtk:publishdateunix', webpage, fatal=False, default=None), 1000),
142 'timestamp': int_or_none(self._html_search_meta('dtk:createdateunix', webpage, fatal=False, default=None), 1000),
143 'uploader': self._search_regex(
144 r'([^-]+)', self._html_search_meta('dtk:author', webpage, default='').strip(), 'uploader',
145 default=None)
148 formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_url, display_id)
150 json_ld_data = self._search_json_ld(webpage, display_id, default={})
151 yield merge_dicts(json_ld_data, extra_info_dict, {
152 'display_id': display_id,
153 'title': self._html_search_meta(['og:title', 'originalTitle'], webpage) or self._html_extract_title(webpage),
154 'description': self._html_search_meta(['og:description', 'twitter:description', 'description'], webpage),
155 'formats': formats,
156 'subtitles': subtitles,
157 'tags': try_call(lambda: self._html_search_meta(
158 ['keywords', 'keyword', 'dtk:keywords'], webpage).split(',')),