]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/zee5.py
[downloaders] Fix API access
[yt-dlp.git] / yt_dlp / extractor / zee5.py
CommitLineData
da6dcbad
A
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
d488e254 7from ..compat import compat_str
da6dcbad
A
8from ..utils import (
9 int_or_none,
10 parse_age_limit,
11 str_or_none,
12 try_get,
13 unified_strdate,
14 unified_timestamp,
15 url_or_none,
16)
17
18
19class Zee5IE(InfoExtractor):
d488e254
A
20 _VALID_URL = r'''(?x)
21 (?:
22 zee5:|
23 (?:https?://)(?:www\.)?zee5\.com/(?:[^#?]+/)?
24 (?:
5b8917fb 25 (?:tvshows|kids|zee5originals)(?:/[^#/?]+){3}
d488e254
A
26 |movies/[^#/?]+
27 )/(?P<display_id>[^#/?]+)/
28 )
29 (?P<id>[^#/?]+)/?(?:$|[?#])
30 '''
da6dcbad
A
31 _TESTS = [{
32 'url': 'https://www.zee5.com/movies/details/krishna-the-birth/0-0-63098',
33 'info_dict': {
d488e254
A
34 'id': '0-0-63098',
35 'ext': 'mp4',
36 'display_id': 'krishna-the-birth',
37 'title': 'Krishna - The Birth',
38 'duration': 4368,
39 'average_rating': 4,
40 'description': str,
41 'alt_title': 'Krishna - The Birth',
42 'uploader': 'Zee Entertainment Enterprises Ltd',
43 'release_date': '20060101',
44 'upload_date': '20060101',
45 'timestamp': 1136073600,
46 'thumbnail': 'https://akamaividz.zee5.com/resources/0-0-63098/list/270x152/0063098_list_80888170.jpg',
47 'tags': list
da6dcbad
A
48 },
49 'params': {
50 'format': 'bv',
51 },
52 }, {
53 'url': 'https://zee5.com/tvshows/details/krishna-balram/0-6-1871/episode-1-the-test-of-bramha/0-1-233402',
54 'info_dict': {
d488e254
A
55 'id': '0-1-233402',
56 'ext': 'mp4',
57 'display_id': 'episode-1-the-test-of-bramha',
58 'title': 'Episode 1 - The Test Of Bramha',
59 'duration': 1336,
60 'average_rating': 4,
61 'description': str,
62 'alt_title': 'Episode 1 - The Test Of Bramha',
63 'uploader': 'Green Gold',
64 'release_date': '20090101',
65 'upload_date': '20090101',
66 'timestamp': 1230768000,
67 'thumbnail': 'https://akamaividz.zee5.com/resources/0-1-233402/list/270x152/01233402_list.jpg',
68 'series': 'Krishna Balram',
69 'season_number': 1,
70 'episode_number': 1,
71 'tags': list,
da6dcbad
A
72 },
73 'params': {
74 'format': 'bv',
75 },
54759df5 76 }, {
77 'url': 'https://www.zee5.com/hi/tvshows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730?country=IN',
78 'only_matching': True
d488e254
A
79 }, {
80 'url': 'https://www.zee5.com/global/hi/tvshows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730',
81 'only_matching': True
da6dcbad
A
82 }]
83
84 def _real_extract(self, url):
85 video_id, display_id = re.match(self._VALID_URL, url).group('id', 'display_id')
86 access_token_request = self._download_json(
87 'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app',
d488e254 88 video_id, note='Downloading access token')
da6dcbad
A
89 token_request = self._download_json(
90 'https://useraction.zee5.com/tokennd',
d488e254 91 video_id, note='Downloading video token')
da6dcbad
A
92 json_data = self._download_json(
93 'https://gwapi.zee5.com/content/details/{}?translation=en&country=IN'.format(video_id),
94 video_id, headers={'X-Access-Token': access_token_request['token']})
95 m3u8_url = try_get(
96 json_data,
97 (lambda x: x['hls'][0], lambda x: x['video_details']['hls_url']),
98 str)
99 formats = self._extract_m3u8_formats(
100 'https://zee5vodnd.akamaized.net' + m3u8_url.replace('/drm1/', '/hls1/') + token_request['video_token'],
101 video_id, fatal=False)
102 mpd_url = try_get(
103 json_data,
104 (lambda x: x['video'][0], lambda x: x['video_details']['url']),
105 str)
106 formats += self._extract_mpd_formats(
107 'https://zee5vodnd.akamaized.net' + mpd_url + token_request['video_token'],
108 video_id, fatal=False)
109
110 self._sort_formats(formats)
111 return {
112 'id': video_id,
113 'display_id': display_id,
114 'title': json_data['title'],
115 'formats': formats,
116 'duration': int_or_none(json_data.get('duration')),
117 'average_rating': int_or_none(json_data.get('rating')),
118 'description': str_or_none(json_data.get('description')),
119 'alt_title': str_or_none(json_data.get('original_title')),
120 'uploader': str_or_none(json_data.get('content_owner')),
121 'age_limit': parse_age_limit(json_data.get('age_rating')),
122 'release_date': unified_strdate(json_data.get('release_date')),
123 'timestamp': unified_timestamp(json_data.get('release_date')),
124 'thumbnail': url_or_none(json_data.get('image_url')),
125 'series': try_get(json_data, lambda x: x['tvshow_details']['title'], str),
126 'season': try_get(json_data, lambda x: x['season_details']['title'], str),
127 'season_number': int_or_none(try_get(json_data, lambda x: x['season_details']['index'])),
128 'episode_number': int_or_none(try_get(json_data, lambda x: x['index'])),
129 'tags': try_get(json_data, lambda x: x['tags'], list)
130 }
d488e254
A
131
132
133class Zee5SeriesIE(InfoExtractor):
134 IE_NAME = 'zee5:series'
135 _VALID_URL = r'''(?x)
136 (?:
137 zee5:series:|
138 (?:https?://)(?:www\.)?zee5\.com/(?:[^#?]+/)?
5b8917fb 139 (?:tvshows|kids|zee5originals)(?:/[^#/?]+){2}/
d488e254
A
140 )
141 (?P<id>[^#/?]+)/?(?:$|[?#])
142 '''
143 _TESTS = [{
144 'url': 'https://www.zee5.com/kids/kids-shows/krishna-balram/0-6-1871',
145 'playlist_mincount': 43,
146 'info_dict': {
147 'id': '0-6-1871',
148 },
149 }, {
150 'url': 'https://www.zee5.com/tvshows/details/bhabi-ji-ghar-par-hai/0-6-199',
151 'playlist_mincount': 1500,
152 'info_dict': {
153 'id': '0-6-199',
154 },
155 }, {
156 'url': 'https://www.zee5.com/tvshows/details/agent-raghav-crime-branch/0-6-965',
157 'playlist_mincount': 25,
158 'info_dict': {
159 'id': '0-6-965',
160 },
161 }, {
162 'url': 'https://www.zee5.com/ta/tvshows/details/nagabhairavi/0-6-3201',
163 'playlist_mincount': 3,
164 'info_dict': {
165 'id': '0-6-3201',
166 },
167 }, {
168 'url': 'https://www.zee5.com/global/hi/tvshows/details/khwaabon-ki-zamin-par/0-6-270',
169 'playlist_mincount': 150,
170 'info_dict': {
171 'id': '0-6-270',
172 },
173 }
174 ]
175
176 def _entries(self, show_id):
177 access_token_request = self._download_json(
178 'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app',
179 show_id, note='Downloading access token')
180 headers = {
181 'X-Access-Token': access_token_request['token'],
182 'Referer': 'https://www.zee5.com/',
183 }
184 show_url = 'https://gwapi.zee5.com/content/tvshow/{}?translation=en&country=IN'.format(show_id)
185
186 page_num = 0
187 show_json = self._download_json(show_url, video_id=show_id, headers=headers)
188 for season in show_json.get('seasons') or []:
189 season_id = try_get(season, lambda x: x['id'], compat_str)
190 next_url = 'https://gwapi.zee5.com/content/tvshow/?season_id={}&type=episode&translation=en&country=IN&on_air=false&asset_subtype=tvshow&page=1&limit=100'.format(season_id)
191 while next_url:
192 page_num += 1
193 episodes_json = self._download_json(
194 next_url, video_id=show_id, headers=headers,
195 note='Downloading JSON metadata page %d' % page_num)
196 for episode in try_get(episodes_json, lambda x: x['episode'], list) or []:
197 video_id = episode.get('id')
198 yield self.url_result(
199 'zee5:%s' % video_id,
200 ie=Zee5IE.ie_key(), video_id=video_id)
201 next_url = url_or_none(episodes_json.get('next_episode_api'))
202
203 def _real_extract(self, url):
204 show_id = self._match_id(url)
205 return self.playlist_result(self._entries(show_id), playlist_id=show_id)