[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / koo.py
blob6ec5b59f9a1fa27d9bff0af759bbea5082ad2c48
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_html,
4 try_get,
8 class KooIE(InfoExtractor):
9 _WORKING = False
10 _VALID_URL = r'https?://(?:www\.)?kooapp\.com/koo/[^/]+/(?P<id>[^/&#$?]+)'
11 _TESTS = [{ # Test for video in the comments
12 'url': 'https://www.kooapp.com/koo/ytdlpTestAccount/946c4189-bc2d-4524-b95b-43f641e2adde',
13 'info_dict': {
14 'id': '946c4189-bc2d-4524-b95b-43f641e2adde',
15 'ext': 'mp4',
16 'title': 'test for video in comment',
17 'description': 'md5:daa77dc214add4da8b6ea7d2226776e7',
18 'timestamp': 1632215195,
19 'uploader_id': 'ytdlpTestAccount',
20 'uploader': 'yt-dlpTestAccount',
21 'duration': 7000,
22 'upload_date': '20210921',
24 'params': {'skip_download': True},
25 }, { # Test for koo with long title
26 'url': 'https://www.kooapp.com/koo/laxman_kumarDBFEC/33decbf7-5e1e-4bb8-bfd7-04744a064361',
27 'info_dict': {
28 'id': '33decbf7-5e1e-4bb8-bfd7-04744a064361',
29 'ext': 'mp4',
30 'title': 'md5:47a71c2337295330c5a19a8af1bbf450',
31 'description': 'md5:06a6a84e9321499486dab541693d8425',
32 'timestamp': 1632106884,
33 'uploader_id': 'laxman_kumarDBFEC',
34 'uploader': 'Laxman Kumar 🇮🇳',
35 'duration': 46000,
36 'upload_date': '20210920',
38 'params': {'skip_download': True},
39 }, { # Test for audio
40 'url': 'https://www.kooapp.com/koo/ytdlpTestAccount/a2a9c88e-ce4b-4d2d-952f-d06361c5b602',
41 'info_dict': {
42 'id': 'a2a9c88e-ce4b-4d2d-952f-d06361c5b602',
43 'ext': 'mp4',
44 'title': 'Test for audio',
45 'description': 'md5:ecb9a2b6a5d34b736cecb53788cb11e8',
46 'timestamp': 1632211634,
47 'uploader_id': 'ytdlpTestAccount',
48 'uploader': 'yt-dlpTestAccount',
49 'duration': 214000,
50 'upload_date': '20210921',
52 'params': {'skip_download': True},
53 }, { # Test for video
54 'url': 'https://www.kooapp.com/koo/ytdlpTestAccount/a3e56c53-c1ed-4ac9-ac02-ed1630e6b1d1',
55 'info_dict': {
56 'id': 'a3e56c53-c1ed-4ac9-ac02-ed1630e6b1d1',
57 'ext': 'mp4',
58 'title': 'Test for video',
59 'description': 'md5:7afc4eb839074ddeb2beea5dd6fe9500',
60 'timestamp': 1632211468,
61 'uploader_id': 'ytdlpTestAccount',
62 'uploader': 'yt-dlpTestAccount',
63 'duration': 14000,
64 'upload_date': '20210921',
66 'params': {'skip_download': True},
67 }, { # Test for link
68 'url': 'https://www.kooapp.com/koo/ytdlpTestAccount/01bf5b94-81a5-4d8e-a387-5f732022e15a',
69 'skip': 'No video/audio found at the provided url.',
70 'info_dict': {
71 'id': '01bf5b94-81a5-4d8e-a387-5f732022e15a',
72 'title': 'Test for link',
73 'ext': 'none',
75 }, { # Test for images
76 'url': 'https://www.kooapp.com/koo/ytdlpTestAccount/dc05d9cd-a61d-45fd-bb07-e8019d8ca8cb',
77 'skip': 'No video/audio found at the provided url.',
78 'info_dict': {
79 'id': 'dc05d9cd-a61d-45fd-bb07-e8019d8ca8cb',
80 'title': 'Test for images',
81 'ext': 'none',
85 def _real_extract(self, url):
86 video_id = self._match_id(url)
87 data_json = self._download_json(
88 f'https://www.kooapp.com/apiV1/ku/{video_id}?limit=20&offset=0&showSimilarKoos=true', video_id)['parentContent']
89 item_json = next(content['items'][0] for content in data_json
90 if try_get(content, lambda x: x['items'][0]['id']) == video_id)
91 media_json = item_json['mediaMap']
92 formats = []
94 mp4_url = media_json.get('videoMp4')
95 video_m3u8_url = media_json.get('videoHls')
96 if mp4_url:
97 formats.append({
98 'url': mp4_url,
99 'ext': 'mp4',
101 if video_m3u8_url:
102 formats.extend(self._extract_m3u8_formats(video_m3u8_url, video_id, fatal=False, ext='mp4'))
103 if not formats:
104 self.raise_no_formats('No video/audio found at the provided url.', expected=True)
106 return {
107 'id': video_id,
108 'title': clean_html(item_json.get('title')),
109 'description': f'{clean_html(item_json.get("title"))}\n\n{clean_html(item_json.get("enTransliteration"))}',
110 'timestamp': item_json.get('createdAt'),
111 'uploader_id': item_json.get('handle'),
112 'uploader': item_json.get('name'),
113 'duration': media_json.get('duration'),
114 'formats': formats,