aboutsummaryrefslogtreecommitdiffstats
path: root/hypervideo_dl/extractor/mzaalo.py
blob: 1996368cc14cc6038da27d470fd7ff20a182ee83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from .common import InfoExtractor
from ..utils import (
    parse_age_limit,
    parse_duration,
    traverse_obj,
    url_or_none,
)


class MzaaloIE(InfoExtractor):
    _VALID_URL = r'(?i)https?://(?:www\.)?mzaalo\.com/(?:play|watch)/(?P<type>movie|original|clip)/(?P<id>[a-f0-9-]+)/[\w-]+'
    _TESTS = [{
        # Movies
        'url': 'https://www.mzaalo.com/play/movie/c0958d9f-f90e-4503-a755-44358758921d/Jamun',
        'info_dict': {
            'id': 'c0958d9f-f90e-4503-a755-44358758921d',
            'title': 'Jamun',
            'ext': 'mp4',
            'description': 'md5:24fe9ebb9bbe5b36f7b54b90ab1e2f31',
            'thumbnails': 'count:15',
            'thumbnail': r're:^https?://.*\.jpg$',
            'duration': 5527.0,
            'language': 'hin',
            'categories': ['Drama'],
            'age_limit': 13,
        },
        'params': {'skip_download': 'm3u8'}
    }, {
        # Shows
        'url': 'https://www.mzaalo.com/play/original/93d42b2b-f373-4c2d-bca4-997412cb069d/Modi-Season-2-CM-TO-PM/Episode-1:Decision,-Not-Promises',
        'info_dict': {
            'id': '93d42b2b-f373-4c2d-bca4-997412cb069d',
            'title': 'Episode 1:Decision, Not Promises',
            'ext': 'mp4',
            'description': 'md5:16f76058432a54774fbb2561a1955652',
            'thumbnails': 'count:22',
            'thumbnail': r're:^https?://.*\.jpg$',
            'duration': 2040.0,
            'language': 'hin',
            'categories': ['Drama'],
            'age_limit': 13,
        },
        'params': {'skip_download': 'm3u8'}
    }, {
        # Streams/Clips
        'url': 'https://www.mzaalo.com/play/clip/83cdbcb5-400a-42f1-a1d2-459053cfbda5/Manto-Ki-Kahaaniya',
        'info_dict': {
            'id': '83cdbcb5-400a-42f1-a1d2-459053cfbda5',
            'title': 'Manto Ki Kahaaniya',
            'ext': 'mp4',
            'description': 'md5:c3c5f1d05f0fd1bfcb05b673d1cc9f2f',
            'thumbnails': 'count:3',
            'thumbnail': r're:^https?://.*\.jpg$',
            'duration': 1937.0,
            'language': 'hin',
        },
        'params': {'skip_download': 'm3u8'}
    }, {
        'url': 'https://mzaalo.com/watch/MOVIE/389c892d-0b65-4019-bf73-d4edcb1c014f/Chalo-Dilli',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id, type_ = self._match_valid_url(url).group('id', 'type')
        path = (f'partner/streamurl?&assetId={video_id}&getClipDetails=YES' if type_ == 'clip'
                else f'api/v2/player/details?assetType={type_.upper()}&assetId={video_id}')
        data = self._download_json(
            f'https://production.mzaalo.com/platform/{path}', video_id, headers={
                'Ocp-Apim-Subscription-Key': '1d0caac2702049b89a305929fdf4cbae',
            })['data']

        formats = self._extract_m3u8_formats(data['streamURL'], video_id)

        subtitles = {}
        for subs_lang, subs_url in traverse_obj(data, ('subtitles', {dict.items}, ...)):
            if url_or_none(subs_url):
                subtitles[subs_lang] = [{'url': subs_url, 'ext': 'vtt'}]

        lang = traverse_obj(data, ('language', {str.lower}))
        for f in formats:
            f['language'] = lang

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(data, {
                'title': ('title', {str}),
                'description': ('description', {str}),
                'duration': ('duration', {parse_duration}),
                'age_limit': ('maturity_rating', {parse_age_limit}),
                'thumbnails': ('images', ..., {'url': {url_or_none}}),
                'categories': ('genre', ..., {str}),
            }),
        }