]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/mzaalo.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / mzaalo.py
CommitLineData
dc3c44f3
MAM
1from .common import InfoExtractor
2from ..utils import (
3 parse_age_limit,
4 parse_duration,
5 traverse_obj,
6 url_or_none,
7)
8
9
10class MzaaloIE(InfoExtractor):
d7aee8e3 11 _VALID_URL = r'(?i)https?://(?:www\.)?mzaalo\.com/(?:play|watch)/(?P<type>movie|original|clip)/(?P<id>[a-f0-9-]+)/[\w-]+'
dc3c44f3
MAM
12 _TESTS = [{
13 # Movies
14 'url': 'https://www.mzaalo.com/play/movie/c0958d9f-f90e-4503-a755-44358758921d/Jamun',
15 'info_dict': {
16 'id': 'c0958d9f-f90e-4503-a755-44358758921d',
17 'title': 'Jamun',
18 'ext': 'mp4',
19 'description': 'md5:24fe9ebb9bbe5b36f7b54b90ab1e2f31',
20 'thumbnails': 'count:15',
21 'thumbnail': r're:^https?://.*\.jpg$',
22 'duration': 5527.0,
23 'language': 'hin',
24 'categories': ['Drama'],
25 'age_limit': 13,
26 },
add96eb9 27 'params': {'skip_download': 'm3u8'},
dc3c44f3
MAM
28 }, {
29 # Shows
30 'url': 'https://www.mzaalo.com/play/original/93d42b2b-f373-4c2d-bca4-997412cb069d/Modi-Season-2-CM-TO-PM/Episode-1:Decision,-Not-Promises',
31 'info_dict': {
32 'id': '93d42b2b-f373-4c2d-bca4-997412cb069d',
33 'title': 'Episode 1:Decision, Not Promises',
34 'ext': 'mp4',
35 'description': 'md5:16f76058432a54774fbb2561a1955652',
36 'thumbnails': 'count:22',
37 'thumbnail': r're:^https?://.*\.jpg$',
38 'duration': 2040.0,
39 'language': 'hin',
40 'categories': ['Drama'],
41 'age_limit': 13,
42 },
add96eb9 43 'params': {'skip_download': 'm3u8'},
dc3c44f3
MAM
44 }, {
45 # Streams/Clips
46 'url': 'https://www.mzaalo.com/play/clip/83cdbcb5-400a-42f1-a1d2-459053cfbda5/Manto-Ki-Kahaaniya',
47 'info_dict': {
48 'id': '83cdbcb5-400a-42f1-a1d2-459053cfbda5',
49 'title': 'Manto Ki Kahaaniya',
50 'ext': 'mp4',
51 'description': 'md5:c3c5f1d05f0fd1bfcb05b673d1cc9f2f',
52 'thumbnails': 'count:3',
53 'thumbnail': r're:^https?://.*\.jpg$',
54 'duration': 1937.0,
55 'language': 'hin',
56 },
add96eb9 57 'params': {'skip_download': 'm3u8'},
d7aee8e3 58 }, {
59 'url': 'https://mzaalo.com/watch/MOVIE/389c892d-0b65-4019-bf73-d4edcb1c014f/Chalo-Dilli',
60 'only_matching': True,
dc3c44f3
MAM
61 }]
62
63 def _real_extract(self, url):
64 video_id, type_ = self._match_valid_url(url).group('id', 'type')
65 path = (f'partner/streamurl?&assetId={video_id}&getClipDetails=YES' if type_ == 'clip'
66 else f'api/v2/player/details?assetType={type_.upper()}&assetId={video_id}')
67 data = self._download_json(
68 f'https://production.mzaalo.com/platform/{path}', video_id, headers={
69 'Ocp-Apim-Subscription-Key': '1d0caac2702049b89a305929fdf4cbae',
70 })['data']
71
72 formats = self._extract_m3u8_formats(data['streamURL'], video_id)
73
74 subtitles = {}
75 for subs_lang, subs_url in traverse_obj(data, ('subtitles', {dict.items}, ...)):
76 if url_or_none(subs_url):
77 subtitles[subs_lang] = [{'url': subs_url, 'ext': 'vtt'}]
78
79 lang = traverse_obj(data, ('language', {str.lower}))
80 for f in formats:
81 f['language'] = lang
82
83 return {
84 'id': video_id,
85 'formats': formats,
86 'subtitles': subtitles,
87 **traverse_obj(data, {
88 'title': ('title', {str}),
89 'description': ('description', {str}),
90 'duration': ('duration', {parse_duration}),
91 'age_limit': ('maturity_rating', {parse_age_limit}),
92 'thumbnails': ('images', ..., {'url': {url_or_none}}),
93 'categories': ('genre', ..., {str}),
94 }),
95 }