]>
Commit | Line | Data |
---|---|---|
1 | import hashlib | |
2 | import hmac | |
3 | import itertools | |
4 | import json | |
5 | import urllib.parse | |
6 | ||
7 | from .common import InfoExtractor | |
8 | from ..utils import ( | |
9 | ExtractorError, | |
10 | int_or_none, | |
11 | join_nonempty, | |
12 | try_call, | |
13 | url_or_none, | |
14 | urljoin, | |
15 | ) | |
16 | from ..utils.traversal import traverse_obj | |
17 | ||
18 | ||
19 | class ZingMp3BaseIE(InfoExtractor): | |
20 | _VALID_URL_TMPL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?P<type>(?:%s))/[^/?#]+/(?P<id>\w+)(?:\.html|\?)' | |
21 | _GEO_COUNTRIES = ['VN'] | |
22 | _DOMAIN = 'https://zingmp3.vn' | |
23 | _PER_PAGE = 50 | |
24 | _API_SLUGS = { | |
25 | # Audio/video | |
26 | 'bai-hat': '/api/v2/page/get/song', | |
27 | 'embed': '/api/v2/page/get/song', | |
28 | 'video-clip': '/api/v2/page/get/video', | |
29 | 'lyric': '/api/v2/lyric/get/lyric', | |
30 | 'song-streaming': '/api/v2/song/get/streaming', | |
31 | 'liveradio': '/api/v2/livestream/get/info', | |
32 | 'eps': '/api/v2/page/get/podcast-episode', | |
33 | 'episode-streaming': '/api/v2/podcast/episode/get/streaming', | |
34 | # Playlist | |
35 | 'playlist': '/api/v2/page/get/playlist', | |
36 | 'album': '/api/v2/page/get/playlist', | |
37 | 'pgr': '/api/v2/page/get/podcast-program', | |
38 | 'pgr-list': '/api/v2/podcast/episode/get/list', | |
39 | 'cgr': '/api/v2/page/get/podcast-category', | |
40 | 'cgr-list': '/api/v2/podcast/program/get/list-by-cate', | |
41 | 'cgrs': '/api/v2/page/get/podcast-categories', | |
42 | # Chart | |
43 | 'zing-chart': '/api/v2/page/get/chart-home', | |
44 | 'zing-chart-tuan': '/api/v2/page/get/week-chart', | |
45 | 'moi-phat-hanh': '/api/v2/page/get/newrelease-chart', | |
46 | 'the-loai-video': '/api/v2/video/get/list', | |
47 | # User | |
48 | 'info-artist': '/api/v2/page/get/artist', | |
49 | 'user-list-song': '/api/v2/song/get/list', | |
50 | 'user-list-video': '/api/v2/video/get/list', | |
51 | 'hub': '/api/v2/page/get/hub-detail', | |
52 | 'new-release': '/api/v2/chart/get/new-release', | |
53 | 'top100': '/api/v2/page/get/top-100', | |
54 | 'podcast-new': '/api/v2/podcast/program/get/list-by-type', | |
55 | 'top-podcast': '/api/v2/podcast/program/get/top-episode', | |
56 | } | |
57 | ||
58 | def _api_url(self, url_type, params): | |
59 | api_slug = self._API_SLUGS[url_type] | |
60 | params.update({'ctime': '1'}) | |
61 | sha256 = hashlib.sha256( | |
62 | ''.join(f'{k}={v}' for k, v in sorted(params.items())).encode()).hexdigest() | |
63 | data = { | |
64 | **params, | |
65 | 'apiKey': 'X5BM3w8N7MKozC0B85o4KMlzLZKhV00y', | |
66 | 'sig': hmac.new(b'acOrvUS15XRW2o9JksiK1KgQ6Vbds8ZW', | |
67 | f'{api_slug}{sha256}'.encode(), hashlib.sha512).hexdigest(), | |
68 | } | |
69 | return f'{self._DOMAIN}{api_slug}?{urllib.parse.urlencode(data)}' | |
70 | ||
71 | def _call_api(self, url_type, params, display_id=None, **kwargs): | |
72 | resp = self._download_json( | |
73 | self._api_url(url_type, params), display_id or params.get('id'), | |
74 | note=f'Downloading {url_type} JSON metadata', **kwargs) | |
75 | return (resp or {}).get('data') or {} | |
76 | ||
77 | def _real_initialize(self): | |
78 | if not self._cookies_passed: | |
79 | self._request_webpage( | |
80 | self._api_url('bai-hat', {'id': ''}), None, note='Updating cookies') | |
81 | ||
82 | def _parse_items(self, items): | |
83 | for url in traverse_obj(items, (..., 'link')) or []: | |
84 | yield self.url_result(urljoin(self._DOMAIN, url)) | |
85 | ||
86 | def _fetch_page(self, id_, url_type, page): | |
87 | raise NotImplementedError('This method must be implemented by subclasses') | |
88 | ||
89 | def _paged_list(self, _id, url_type): | |
90 | count = 0 | |
91 | for page in itertools.count(1): | |
92 | data = self._fetch_page(_id, url_type, page) | |
93 | entries = list(self._parse_items(data.get('items'))) | |
94 | count += len(entries) | |
95 | yield from entries | |
96 | if not data.get('hasMore') or try_call(lambda: count > data['total']): | |
97 | break | |
98 | ||
99 | ||
100 | class ZingMp3IE(ZingMp3BaseIE): | |
101 | _VALID_URL = ZingMp3BaseIE._VALID_URL_TMPL % 'bai-hat|video-clip|embed|eps' | |
102 | IE_NAME = 'zingmp3' | |
103 | IE_DESC = 'zingmp3.vn' | |
104 | _TESTS = [{ | |
105 | 'url': 'https://mp3.zing.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html', | |
106 | 'md5': 'ead7ae13693b3205cbc89536a077daed', | |
107 | 'info_dict': { | |
108 | 'id': 'ZWZB9WAB', | |
109 | 'title': 'Xa Mãi Xa', | |
110 | 'ext': 'mp3', | |
111 | 'thumbnail': r're:^https?://.+\.jpg', | |
112 | 'subtitles': { | |
113 | 'origin': [{ | |
114 | 'ext': 'lrc', | |
115 | }], | |
116 | }, | |
117 | 'duration': 255, | |
118 | 'track': 'Xa Mãi Xa', | |
119 | 'artist': 'Bảo Thy', | |
120 | 'album': 'Special Album', | |
121 | 'album_artist': 'Bảo Thy', | |
122 | }, | |
123 | }, { | |
124 | 'url': 'https://zingmp3.vn/video-clip/Suong-Hoa-Dua-Loi-K-ICM-RYO/ZO8ZF7C7.html', | |
125 | 'md5': '92c6e7a019f06b4682a6c35ae5785fab', | |
126 | 'info_dict': { | |
127 | 'id': 'ZO8ZF7C7', | |
128 | 'title': 'Sương Hoa Đưa Lối', | |
129 | 'ext': 'mp4', | |
130 | 'thumbnail': r're:^https?://.+\.jpg', | |
131 | 'duration': 207, | |
132 | 'track': 'Sương Hoa Đưa Lối', | |
133 | 'artist': 'K-ICM, RYO', | |
134 | 'album': 'Sương Hoa Đưa Lối (Single)', | |
135 | 'album_artist': 'K-ICM, RYO', | |
136 | }, | |
137 | }, { | |
138 | 'url': 'https://zingmp3.vn/bai-hat/Nguoi-Yeu-Toi-Lanh-Lung-Sat-Da-Mr-Siro/ZZ6IW7OU.html', | |
139 | 'md5': '3e9f7a9bd0d965573dbff8d7c68b629d', | |
140 | 'info_dict': { | |
141 | 'id': 'ZZ6IW7OU', | |
142 | 'title': 'Người Yêu Tôi Lạnh Lùng Sắt Đá', | |
143 | 'ext': 'mp3', | |
144 | 'thumbnail': r're:^https?://.+\.jpg', | |
145 | 'duration': 303, | |
146 | 'track': 'Người Yêu Tôi Lạnh Lùng Sắt Đá', | |
147 | 'artist': 'Mr. Siro', | |
148 | 'album': 'Người Yêu Tôi Lạnh Lùng Sắt Đá (Single)', | |
149 | 'album_artist': 'Mr. Siro', | |
150 | }, | |
151 | }, { | |
152 | 'url': 'https://zingmp3.vn/eps/Cham-x-Ban-Noi-Goi-La-Nha/ZZD9ACWI.html', | |
153 | 'md5': 'd52f9f63e2631e004e4f15188eedcf80', | |
154 | 'info_dict': { | |
155 | 'id': 'ZZD9ACWI', | |
156 | 'title': 'Chạm x Bạn - Nơi Gọi Là Nhà', | |
157 | 'ext': 'mp3', | |
158 | 'duration': 3716, | |
159 | 'thumbnail': r're:^https?://.+\.jpg', | |
160 | 'track': 'Chạm x Bạn - Nơi Gọi Là Nhà', | |
161 | 'artist': 'On Air', | |
162 | 'album': 'Top Podcast', | |
163 | 'album_artist': 'On Air', | |
164 | }, | |
165 | }, { | |
166 | 'url': 'https://zingmp3.vn/embed/song/ZWZEI76B?start=false', | |
167 | 'only_matching': True, | |
168 | }, { | |
169 | 'url': 'https://zingmp3.vn/bai-hat/Xa-Mai-Xa-Bao-Thy/ZWZB9WAB.html', | |
170 | 'only_matching': True, | |
171 | }] | |
172 | ||
173 | def _real_extract(self, url): | |
174 | song_id, url_type = self._match_valid_url(url).group('id', 'type') | |
175 | item = self._call_api(url_type, {'id': song_id}) | |
176 | ||
177 | item_id = item.get('encodeId') or song_id | |
178 | if url_type == 'video-clip': | |
179 | source = item.get('streaming') | |
180 | source['mp4'] = self._download_json( | |
181 | 'http://api.mp3.zing.vn/api/mobile/video/getvideoinfo', item_id, | |
182 | query={'requestdata': json.dumps({'id': item_id})}, | |
183 | note='Downloading mp4 JSON metadata').get('source') | |
184 | elif url_type == 'eps': | |
185 | source = self._call_api('episode-streaming', {'id': item_id}) | |
186 | else: | |
187 | source = self._call_api('song-streaming', {'id': item_id}) | |
188 | ||
189 | formats = [] | |
190 | for k, v in (source or {}).items(): | |
191 | if not v or v == 'VIP': | |
192 | continue | |
193 | if k not in ('mp4', 'hls'): | |
194 | formats.append({ | |
195 | 'ext': 'mp3', | |
196 | 'format_id': k, | |
197 | 'tbr': int_or_none(k), | |
198 | 'url': self._proto_relative_url(v), | |
199 | 'vcodec': 'none', | |
200 | }) | |
201 | continue | |
202 | for res, video_url in v.items(): | |
203 | if not video_url: | |
204 | continue | |
205 | if k == 'hls': | |
206 | formats.extend(self._extract_m3u8_formats(video_url, item_id, 'mp4', m3u8_id=k, fatal=False)) | |
207 | continue | |
208 | formats.append({ | |
209 | 'format_id': f'mp4-{res}', | |
210 | 'url': video_url, | |
211 | 'height': int_or_none(res), | |
212 | }) | |
213 | ||
214 | if not formats: | |
215 | if item.get('msg') == 'Sorry, this content is not available in your country.': | |
216 | self.raise_geo_restricted(countries=self._GEO_COUNTRIES, metadata_available=True) | |
217 | else: | |
218 | self.raise_no_formats('The song is only for VIP accounts.') | |
219 | ||
220 | lyric = item.get('lyric') or self._call_api('lyric', {'id': item_id}, fatal=False).get('file') | |
221 | ||
222 | return { | |
223 | 'id': item_id, | |
224 | 'title': traverse_obj(item, 'title', 'alias'), | |
225 | 'thumbnail': traverse_obj(item, 'thumbnail', 'thumbnailM'), | |
226 | 'duration': int_or_none(item.get('duration')), | |
227 | 'track': traverse_obj(item, 'title', 'alias'), | |
228 | 'artist': traverse_obj(item, 'artistsNames', 'artists_names', ('artists', 0, 'name')), | |
229 | 'album': traverse_obj(item, ('album', ('name', 'title')), ('genres', 0, 'name'), get_all=False), | |
230 | 'album_artist': traverse_obj(item, ('album', ('artistsNames', 'artists_names')), | |
231 | ('artists', 0, 'name'), get_all=False), | |
232 | 'formats': formats, | |
233 | 'subtitles': {'origin': [{'url': lyric}]} if lyric else None, | |
234 | } | |
235 | ||
236 | ||
237 | class ZingMp3AlbumIE(ZingMp3BaseIE): | |
238 | _VALID_URL = ZingMp3BaseIE._VALID_URL_TMPL % 'album|playlist' | |
239 | _TESTS = [{ | |
240 | 'url': 'https://zingmp3.vn/album/Ca-Phe-Quan-Quen-Hoang-Dung-My-Anh-Da-LAB-Thinh-Suy/ZOC7WUZC.html', | |
241 | 'info_dict': { | |
242 | 'id': 'ZOC7WUZC', | |
243 | 'title': 'Cà Phê Quán Quen', | |
244 | }, | |
245 | 'playlist_mincount': 10, | |
246 | }, { | |
247 | 'url': 'https://zingmp3.vn/album/Nhung-Bai-Hat-Hay-Nhat-Cua-Mr-Siro-Mr-Siro/ZWZAEZZD.html', | |
248 | 'info_dict': { | |
249 | 'id': 'ZWZAEZZD', | |
250 | 'title': 'Những Bài Hát Hay Nhất Của Mr. Siro', | |
251 | }, | |
252 | 'playlist_mincount': 20, | |
253 | }, { | |
254 | 'url': 'http://mp3.zing.vn/playlist/Duong-Hong-Loan-apollobee/IWCAACCB.html', | |
255 | 'only_matching': True, | |
256 | }, { | |
257 | 'url': 'https://zingmp3.vn/album/Lau-Dai-Tinh-Ai-Bang-Kieu-Minh-Tuyet/ZWZBWDAF.html', | |
258 | 'only_matching': True, | |
259 | }] | |
260 | IE_NAME = 'zingmp3:album' | |
261 | ||
262 | def _real_extract(self, url): | |
263 | song_id, url_type = self._match_valid_url(url).group('id', 'type') | |
264 | data = self._call_api(url_type, {'id': song_id}) | |
265 | return self.playlist_result( | |
266 | self._parse_items(traverse_obj(data, ('song', 'items'))), | |
267 | traverse_obj(data, 'id', 'encodeId'), traverse_obj(data, 'name', 'title')) | |
268 | ||
269 | ||
270 | class ZingMp3ChartHomeIE(ZingMp3BaseIE): | |
271 | _VALID_URL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?P<id>(?:zing-chart|moi-phat-hanh|top100|podcast-discover))/?(?:[#?]|$)' | |
272 | _TESTS = [{ | |
273 | 'url': 'https://zingmp3.vn/zing-chart', | |
274 | 'info_dict': { | |
275 | 'id': 'zing-chart', | |
276 | }, | |
277 | 'playlist_mincount': 100, | |
278 | }, { | |
279 | 'url': 'https://zingmp3.vn/moi-phat-hanh', | |
280 | 'info_dict': { | |
281 | 'id': 'moi-phat-hanh', | |
282 | }, | |
283 | 'playlist_mincount': 100, | |
284 | }, { | |
285 | 'url': 'https://zingmp3.vn/top100', | |
286 | 'info_dict': { | |
287 | 'id': 'top100', | |
288 | }, | |
289 | 'playlist_mincount': 50, | |
290 | }, { | |
291 | 'url': 'https://zingmp3.vn/podcast-discover', | |
292 | 'info_dict': { | |
293 | 'id': 'podcast-discover', | |
294 | }, | |
295 | 'playlist_mincount': 4, | |
296 | }] | |
297 | IE_NAME = 'zingmp3:chart-home' | |
298 | ||
299 | def _real_extract(self, url): | |
300 | url_type = self._match_id(url) | |
301 | params = {'id': url_type} | |
302 | if url_type == 'podcast-discover': | |
303 | params['type'] = 'discover' | |
304 | data = self._call_api(url_type, params) | |
305 | items = [] | |
306 | if url_type == 'top100': | |
307 | items.extend(traverse_obj(data, (..., 'items', ..., {dict}))) | |
308 | elif url_type == 'zing-chart': | |
309 | items.extend(traverse_obj(data, ('RTChart', 'items', ..., {dict}))) | |
310 | else: | |
311 | items.extend(traverse_obj(data, ('items', ..., {dict}))) | |
312 | return self.playlist_result(self._parse_items(items), url_type) | |
313 | ||
314 | ||
315 | class ZingMp3WeekChartIE(ZingMp3BaseIE): | |
316 | _VALID_URL = ZingMp3BaseIE._VALID_URL_TMPL % 'zing-chart-tuan' | |
317 | IE_NAME = 'zingmp3:week-chart' | |
318 | _TESTS = [{ | |
319 | 'url': 'https://zingmp3.vn/zing-chart-tuan/Bai-hat-Viet-Nam/IWZ9Z08I.html', | |
320 | 'info_dict': { | |
321 | 'id': 'IWZ9Z08I', | |
322 | 'title': 'zing-chart-vn', | |
323 | }, | |
324 | 'playlist_mincount': 10, | |
325 | }, { | |
326 | 'url': 'https://zingmp3.vn/zing-chart-tuan/Bai-hat-US-UK/IWZ9Z0BW.html', | |
327 | 'info_dict': { | |
328 | 'id': 'IWZ9Z0BW', | |
329 | 'title': 'zing-chart-us', | |
330 | }, | |
331 | 'playlist_mincount': 10, | |
332 | }, { | |
333 | 'url': 'https://zingmp3.vn/zing-chart-tuan/Bai-hat-KPop/IWZ9Z0BO.html', | |
334 | 'info_dict': { | |
335 | 'id': 'IWZ9Z0BO', | |
336 | 'title': 'zing-chart-korea', | |
337 | }, | |
338 | 'playlist_mincount': 10, | |
339 | }] | |
340 | ||
341 | def _real_extract(self, url): | |
342 | song_id, url_type = self._match_valid_url(url).group('id', 'type') | |
343 | data = self._call_api(url_type, {'id': song_id}) | |
344 | return self.playlist_result( | |
345 | self._parse_items(data['items']), song_id, f'zing-chart-{data.get("country", "")}') | |
346 | ||
347 | ||
348 | class ZingMp3ChartMusicVideoIE(ZingMp3BaseIE): | |
349 | _VALID_URL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?P<type>the-loai-video)/(?P<regions>[^/]+)/(?P<id>[^\.]+)' | |
350 | IE_NAME = 'zingmp3:chart-music-video' | |
351 | _TESTS = [{ | |
352 | 'url': 'https://zingmp3.vn/the-loai-video/Viet-Nam/IWZ9Z08I.html', | |
353 | 'info_dict': { | |
354 | 'id': 'IWZ9Z08I', | |
355 | 'title': 'the-loai-video_Viet-Nam', | |
356 | }, | |
357 | 'playlist_mincount': 400, | |
358 | }, { | |
359 | 'url': 'https://zingmp3.vn/the-loai-video/Au-My/IWZ9Z08O.html', | |
360 | 'info_dict': { | |
361 | 'id': 'IWZ9Z08O', | |
362 | 'title': 'the-loai-video_Au-My', | |
363 | }, | |
364 | 'playlist_mincount': 40, | |
365 | }, { | |
366 | 'url': 'https://zingmp3.vn/the-loai-video/Han-Quoc/IWZ9Z08W.html', | |
367 | 'info_dict': { | |
368 | 'id': 'IWZ9Z08W', | |
369 | 'title': 'the-loai-video_Han-Quoc', | |
370 | }, | |
371 | 'playlist_mincount': 30, | |
372 | }, { | |
373 | 'url': 'https://zingmp3.vn/the-loai-video/Khong-Loi/IWZ9Z086.html', | |
374 | 'info_dict': { | |
375 | 'id': 'IWZ9Z086', | |
376 | 'title': 'the-loai-video_Khong-Loi', | |
377 | }, | |
378 | 'playlist_mincount': 1, | |
379 | }] | |
380 | ||
381 | def _fetch_page(self, song_id, url_type, page): | |
382 | return self._call_api(url_type, { | |
383 | 'id': song_id, | |
384 | 'type': 'genre', | |
385 | 'page': page, | |
386 | 'count': self._PER_PAGE, | |
387 | }) | |
388 | ||
389 | def _real_extract(self, url): | |
390 | song_id, regions, url_type = self._match_valid_url(url).group('id', 'regions', 'type') | |
391 | return self.playlist_result(self._paged_list(song_id, url_type), song_id, f'{url_type}_{regions}') | |
392 | ||
393 | ||
394 | class ZingMp3UserIE(ZingMp3BaseIE): | |
395 | _VALID_URL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?P<user>[^/]+)/(?P<type>bai-hat|single|album|video|song)/?(?:[?#]|$)' | |
396 | IE_NAME = 'zingmp3:user' | |
397 | _TESTS = [{ | |
398 | 'url': 'https://zingmp3.vn/Mr-Siro/bai-hat', | |
399 | 'info_dict': { | |
400 | 'id': 'IWZ98609', | |
401 | 'title': 'Mr. Siro - bai-hat', | |
402 | 'description': 'md5:5bdcf45e955dc1b8d7f518f322ffef36', | |
403 | }, | |
404 | 'playlist_mincount': 91, | |
405 | }, { | |
406 | 'url': 'https://zingmp3.vn/Mr-Siro/album', | |
407 | 'info_dict': { | |
408 | 'id': 'IWZ98609', | |
409 | 'title': 'Mr. Siro - album', | |
410 | 'description': 'md5:5bdcf45e955dc1b8d7f518f322ffef36', | |
411 | }, | |
412 | 'playlist_mincount': 3, | |
413 | }, { | |
414 | 'url': 'https://zingmp3.vn/Mr-Siro/single', | |
415 | 'info_dict': { | |
416 | 'id': 'IWZ98609', | |
417 | 'title': 'Mr. Siro - single', | |
418 | 'description': 'md5:5bdcf45e955dc1b8d7f518f322ffef36', | |
419 | }, | |
420 | 'playlist_mincount': 20, | |
421 | }, { | |
422 | 'url': 'https://zingmp3.vn/Mr-Siro/video', | |
423 | 'info_dict': { | |
424 | 'id': 'IWZ98609', | |
425 | 'title': 'Mr. Siro - video', | |
426 | 'description': 'md5:5bdcf45e955dc1b8d7f518f322ffef36', | |
427 | }, | |
428 | 'playlist_mincount': 15, | |
429 | }, { | |
430 | 'url': 'https://zingmp3.vn/new-release/song', | |
431 | 'info_dict': { | |
432 | 'id': 'new-release-song', | |
433 | }, | |
434 | 'playlist_mincount': 50, | |
435 | }, { | |
436 | 'url': 'https://zingmp3.vn/new-release/album', | |
437 | 'info_dict': { | |
438 | 'id': 'new-release-album', | |
439 | }, | |
440 | 'playlist_mincount': 20, | |
441 | }] | |
442 | ||
443 | def _fetch_page(self, user_id, url_type, page): | |
444 | url_type = 'user-list-song' if url_type == 'bai-hat' else 'user-list-video' | |
445 | return self._call_api(url_type, { | |
446 | 'id': user_id, | |
447 | 'type': 'artist', | |
448 | 'page': page, | |
449 | 'count': self._PER_PAGE, | |
450 | }) | |
451 | ||
452 | def _real_extract(self, url): | |
453 | alias, url_type = self._match_valid_url(url).group('user', 'type') | |
454 | if not url_type: | |
455 | url_type = 'bai-hat' | |
456 | ||
457 | user_info = self._call_api('info-artist', {}, alias, query={'alias': alias}) | |
458 | ||
459 | # Handle for new-release | |
460 | if alias == 'new-release' and url_type in ('song', 'album'): | |
461 | _id = f'{alias}-{url_type}' | |
462 | return self.playlist_result(self._parse_items( | |
463 | self._call_api('new-release', params={'type': url_type}, display_id=_id)), _id) | |
464 | else: | |
465 | # Handle for user/artist | |
466 | if url_type in ('bai-hat', 'video'): | |
467 | entries = self._paged_list(user_info['id'], url_type) | |
468 | else: | |
469 | section_id = 'aAlbum' if url_type == 'album' else 'aSingle' | |
470 | entries = self._parse_items(traverse_obj(user_info, ( | |
471 | 'sections', lambda _, v: v['sectionId'] == section_id, 'items', ...))) | |
472 | return self.playlist_result( | |
473 | entries, user_info['id'], join_nonempty(user_info.get('name'), url_type, delim=' - '), | |
474 | user_info.get('biography')) | |
475 | ||
476 | ||
477 | class ZingMp3HubIE(ZingMp3BaseIE): | |
478 | IE_NAME = 'zingmp3:hub' | |
479 | _VALID_URL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?P<type>hub)/(?P<regions>[^/]+)/(?P<id>[^\.]+)' | |
480 | _TESTS = [{ | |
481 | 'url': 'https://zingmp3.vn/hub/Nhac-Moi/IWZ9Z0CA.html', | |
482 | 'info_dict': { | |
483 | 'id': 'IWZ9Z0CA', | |
484 | 'title': 'BXH Nhạc Mới', | |
485 | 'description': 'md5:1cc31b68a6f746427b07b2756c22a558', | |
486 | }, | |
487 | 'playlist_mincount': 20, | |
488 | }, { | |
489 | 'url': 'https://zingmp3.vn/hub/Nhac-Viet/IWZ9Z087.html', | |
490 | 'info_dict': { | |
491 | 'id': 'IWZ9Z087', | |
492 | 'title': 'Nhạc Việt', | |
493 | 'description': 'md5:acc976c8bdde64d5c6ee4a92c39f7a77', | |
494 | }, | |
495 | 'playlist_mincount': 30, | |
496 | }] | |
497 | ||
498 | def _real_extract(self, url): | |
499 | song_id, regions, url_type = self._match_valid_url(url).group('id', 'regions', 'type') | |
500 | hub_detail = self._call_api(url_type, {'id': song_id}) | |
501 | entries = self._parse_items(traverse_obj(hub_detail, ( | |
502 | 'sections', lambda _, v: v['sectionId'] == 'hub', 'items', ...))) | |
503 | return self.playlist_result( | |
504 | entries, song_id, hub_detail.get('title'), hub_detail.get('description')) | |
505 | ||
506 | ||
507 | class ZingMp3LiveRadioIE(ZingMp3BaseIE): | |
508 | IE_NAME = 'zingmp3:liveradio' | |
509 | _VALID_URL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?P<type>(?:liveradio))/(?P<id>\w+)(?:\.html|\?)' | |
510 | _TESTS = [{ | |
511 | 'url': 'https://zingmp3.vn/liveradio/IWZ979UB.html', | |
512 | 'info_dict': { | |
513 | 'id': 'IWZ979UB', | |
514 | 'title': r're:^V\-POP', | |
515 | 'description': 'md5:aa857f8a91dc9ce69e862a809e4bdc10', | |
516 | 'ext': 'mp4', | |
517 | 'view_count': int, | |
518 | 'thumbnail': r're:^https?://.*\.jpg', | |
519 | 'like_count': int, | |
520 | 'live_status': 'is_live', | |
521 | }, | |
522 | 'params': { | |
523 | 'skip_download': True, | |
524 | }, | |
525 | }, { | |
526 | 'url': 'https://zingmp3.vn/liveradio/IWZ97CWB.html', | |
527 | 'info_dict': { | |
528 | 'id': 'IWZ97CWB', | |
529 | 'title': r're:^Live\s247', | |
530 | 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e', | |
531 | 'ext': 'm4a', | |
532 | 'view_count': int, | |
533 | 'thumbnail': r're:^https?://.*\.jpg', | |
534 | 'like_count': int, | |
535 | 'live_status': 'is_live', | |
536 | }, | |
537 | 'params': { | |
538 | 'skip_download': True, | |
539 | }, | |
540 | }] | |
541 | ||
542 | def _real_extract(self, url): | |
543 | url_type, live_radio_id = self._match_valid_url(url).group('type', 'id') | |
544 | info = self._call_api(url_type, {'id': live_radio_id}) | |
545 | manifest_url = info.get('streaming') | |
546 | if not manifest_url: | |
547 | raise ExtractorError('This radio is offline.', expected=True) | |
548 | fmts, subtitles = self._extract_m3u8_formats_and_subtitles(manifest_url, live_radio_id, fatal=False) | |
549 | return { | |
550 | 'id': live_radio_id, | |
551 | 'is_live': True, | |
552 | 'formats': fmts, | |
553 | 'subtitles': subtitles, | |
554 | **traverse_obj(info, { | |
555 | 'title': 'title', | |
556 | 'thumbnail': (('thumbnail', 'thumbnailM', 'thumbnailV', 'thumbnailH'), {url_or_none}), | |
557 | 'view_count': ('activeUsers', {int_or_none}), | |
558 | 'like_count': ('totalReaction', {int_or_none}), | |
559 | 'description': 'description', | |
560 | }, get_all=False), | |
561 | } | |
562 | ||
563 | ||
564 | class ZingMp3PodcastEpisodeIE(ZingMp3BaseIE): | |
565 | IE_NAME = 'zingmp3:podcast-episode' | |
566 | _VALID_URL = ZingMp3BaseIE._VALID_URL_TMPL % 'pgr|cgr' | |
567 | _TESTS = [{ | |
568 | 'url': 'https://zingmp3.vn/pgr/Nhac-Moi-Moi-Ngay/68Z9W66B.html', | |
569 | 'info_dict': { | |
570 | 'id': '68Z9W66B', | |
571 | 'title': 'Nhạc Mới Mỗi Ngày', | |
572 | 'description': 'md5:2875dfa951f8e5356742f1610cf20691', | |
573 | }, | |
574 | 'playlist_mincount': 20, | |
575 | }, { | |
576 | 'url': 'https://zingmp3.vn/cgr/Am-nhac/IWZ980AO.html', | |
577 | 'info_dict': { | |
578 | 'id': 'IWZ980AO', | |
579 | 'title': 'Âm nhạc', | |
580 | }, | |
581 | 'playlist_mincount': 2, | |
582 | }] | |
583 | ||
584 | def _fetch_page(self, eps_id, url_type, page): | |
585 | return self._call_api(url_type, { | |
586 | 'id': eps_id, | |
587 | 'page': page, | |
588 | 'count': self._PER_PAGE, | |
589 | }) | |
590 | ||
591 | def _real_extract(self, url): | |
592 | podcast_id, url_type = self._match_valid_url(url).group('id', 'type') | |
593 | podcast_info = self._call_api(url_type, {'id': podcast_id}) | |
594 | entries = self._paged_list(podcast_id, 'pgr-list' if url_type == 'pgr' else 'cgr-list') | |
595 | return self.playlist_result( | |
596 | entries, podcast_id, podcast_info.get('title'), podcast_info.get('description')) | |
597 | ||
598 | ||
599 | class ZingMp3PodcastIE(ZingMp3BaseIE): | |
600 | IE_NAME = 'zingmp3:podcast' | |
601 | _VALID_URL = r'https?://(?:mp3\.zing|zingmp3)\.vn/(?P<id>(?:cgr|top-podcast|podcast-new))/?(?:[#?]|$)' | |
602 | _TESTS = [{ | |
603 | 'url': 'https://zingmp3.vn/cgr', | |
604 | 'info_dict': { | |
605 | 'id': 'cgr', | |
606 | }, | |
607 | 'playlist_mincount': 5, | |
608 | }, { | |
609 | 'url': 'https://zingmp3.vn/top-podcast', | |
610 | 'info_dict': { | |
611 | 'id': 'top-podcast', | |
612 | }, | |
613 | 'playlist_mincount': 7, | |
614 | }, { | |
615 | 'url': 'https://zingmp3.vn/podcast-new', | |
616 | 'info_dict': { | |
617 | 'id': 'podcast-new', | |
618 | }, | |
619 | 'playlist_mincount': 4, | |
620 | }] | |
621 | ||
622 | def _real_extract(self, url): | |
623 | url_type = self._match_id(url) | |
624 | params = {'id': url_type} | |
625 | if url_type == 'podcast-new': | |
626 | params['type'] = 'new' | |
627 | items = self._call_api('cgrs' if url_type == 'cgr' else url_type, params)['items'] | |
628 | return self.playlist_result(self._parse_items(items), url_type) |