]>
Commit | Line | Data |
---|---|---|
96c23f3b | 1 | import json |
9d7fde89 | 2 | import time |
3 | import uuid | |
da6dcbad A |
4 | |
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
96c23f3b | 7 | ExtractorError, |
da6dcbad | 8 | int_or_none, |
9d7fde89 | 9 | jwt_decode_hs256, |
da6dcbad A |
10 | parse_age_limit, |
11 | str_or_none, | |
9d7fde89 | 12 | try_call, |
da6dcbad A |
13 | try_get, |
14 | unified_strdate, | |
15 | unified_timestamp, | |
16 | url_or_none, | |
17 | ) | |
18 | ||
19 | ||
20 | class Zee5IE(InfoExtractor): | |
d488e254 A |
21 | _VALID_URL = r'''(?x) |
22 | (?: | |
23 | zee5:| | |
73f035e1 | 24 | https?://(?:www\.)?zee5\.com/(?:[^#?]+/)? |
d488e254 | 25 | (?: |
4d4f9a02 | 26 | (?:tv-shows|kids|web-series|zee5originals)(?:/[^#/?]+){3} |
385adffc | 27 | |(?:movies|kids|videos|news|music-videos)/(?!kids-shows)[^#/?]+ |
d488e254 A |
28 | )/(?P<display_id>[^#/?]+)/ |
29 | ) | |
30 | (?P<id>[^#/?]+)/?(?:$|[?#]) | |
31 | ''' | |
da6dcbad | 32 | _TESTS = [{ |
0f7247f8 | 33 | 'url': 'https://www.zee5.com/movies/details/adavari-matalaku-ardhale-verule/0-0-movie_1143162669', |
da6dcbad | 34 | 'info_dict': { |
0f7247f8 | 35 | 'id': '0-0-movie_1143162669', |
d488e254 | 36 | 'ext': 'mp4', |
0f7247f8 | 37 | 'display_id': 'adavari-matalaku-ardhale-verule', |
38 | 'title': 'Adavari Matalaku Ardhale Verule', | |
39 | 'duration': 9360, | |
add96eb9 | 40 | 'description': str, |
0f7247f8 | 41 | 'alt_title': 'Adavari Matalaku Ardhale Verule', |
d488e254 | 42 | 'uploader': 'Zee Entertainment Enterprises Ltd', |
0f7247f8 | 43 | 'release_date': '20070427', |
44 | 'upload_date': '20070427', | |
45 | 'timestamp': 1177632000, | |
ee7b9bdf AG |
46 | 'thumbnail': r're:^https?://.*\.jpg$', |
47 | 'episode_number': 0, | |
48 | 'episode': 'Episode 0', | |
add96eb9 | 49 | 'tags': list, |
da6dcbad A |
50 | }, |
51 | 'params': { | |
52 | 'format': 'bv', | |
53 | }, | |
54 | }, { | |
ee7b9bdf | 55 | 'url': 'https://www.zee5.com/kids/kids-shows/bandbudh-aur-budbak/0-6-1899/yoga-se-hoga-bandbudh-aur-budbak/0-1-239839', |
da6dcbad | 56 | 'info_dict': { |
ee7b9bdf | 57 | 'id': '0-1-239839', |
d488e254 | 58 | 'ext': 'mp4', |
ee7b9bdf AG |
59 | 'display_id': 'yoga-se-hoga-bandbudh-aur-budbak', |
60 | 'title': 'Yoga Se Hoga-Bandbudh aur Budbak', | |
61 | 'duration': 659, | |
add96eb9 | 62 | 'description': str, |
ee7b9bdf | 63 | 'alt_title': 'Yoga Se Hoga-Bandbudh aur Budbak', |
96c23f3b | 64 | 'uploader': 'Zee Entertainment Enterprises Ltd', |
ee7b9bdf AG |
65 | 'release_date': '20150101', |
66 | 'upload_date': '20150101', | |
67 | 'timestamp': 1420070400, | |
68 | 'thumbnail': r're:^https?://.*\.jpg$', | |
69 | 'series': 'Bandbudh Aur Budbak', | |
d488e254 A |
70 | 'season_number': 1, |
71 | 'episode_number': 1, | |
ee7b9bdf AG |
72 | 'episode': 'Episode 1', |
73 | 'season': 'Season 1', | |
d488e254 | 74 | 'tags': list, |
da6dcbad A |
75 | }, |
76 | 'params': { | |
77 | 'format': 'bv', | |
78 | }, | |
54759df5 | 79 | }, { |
ee7b9bdf | 80 | 'url': 'https://www.zee5.com/hi/tv-shows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730?country=IN', |
add96eb9 | 81 | 'only_matching': True, |
d488e254 | 82 | }, { |
ee7b9bdf | 83 | 'url': 'https://www.zee5.com/global/hi/tv-shows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730', |
add96eb9 | 84 | 'only_matching': True, |
4d4f9a02 AJ |
85 | }, { |
86 | 'url': 'https://www.zee5.com/web-series/details/mithya/0-6-4z587408/maine-dekhi-hai-uski-mrityu/0-1-6z587412', | |
add96eb9 | 87 | 'only_matching': True, |
7244895b | 88 | }, { |
89 | 'url': 'https://www.zee5.com/kids/kids-movies/maya-bommalu/0-0-movie_1040370005', | |
add96eb9 | 90 | 'only_matching': True, |
385adffc | 91 | }, { |
92 | 'url': 'https://www.zee5.com/news/details/jana-sena-chief-pawan-kalyan-shows-slippers-to-ysrcp-leaders/0-0-newsauto_6ettj4242oo0', | |
add96eb9 | 93 | 'only_matching': True, |
385adffc | 94 | }, { |
95 | 'url': 'https://www.zee5.com/music-videos/details/adhento-gaani-vunnapaatuga-jersey-nani-shraddha-srinath/0-0-56973', | |
add96eb9 | 96 | 'only_matching': True, |
da6dcbad | 97 | }] |
9d7fde89 | 98 | _DEVICE_ID = str(uuid.uuid4()) |
96c23f3b A |
99 | _USER_TOKEN = None |
100 | _LOGIN_HINT = 'Use "--username <mobile_number>" to login using otp or "--username token" and "--password <user_token>" to login using user token.' | |
101 | _NETRC_MACHINE = 'zee5' | |
fdeab99e | 102 | _GEO_COUNTRIES = ['IN'] |
9d7fde89 | 103 | _USER_COUNTRY = None |
96c23f3b | 104 | |
52efa4b3 | 105 | def _perform_login(self, username, password): |
106 | if len(username) == 10 and username.isdigit() and self._USER_TOKEN is None: | |
107 | self.report_login() | |
86e5f3ed | 108 | otp_request_json = self._download_json(f'https://b2bapi.zee5.com/device/sendotp_v1.php?phoneno=91{username}', |
52efa4b3 | 109 | None, note='Sending OTP') |
110 | if otp_request_json['code'] == 0: | |
111 | self.to_screen(otp_request_json['message']) | |
9e907ebd | 112 | else: |
52efa4b3 | 113 | raise ExtractorError(otp_request_json['message'], expected=True) |
114 | otp_code = self._get_tfa_info('OTP') | |
86e5f3ed | 115 | otp_verify_json = self._download_json(f'https://b2bapi.zee5.com/device/verifyotp_v1.php?phoneno=91{username}&otp={otp_code}&guest_token={self._DEVICE_ID}&platform=web', |
52efa4b3 | 116 | None, note='Verifying OTP', fatal=False) |
117 | if not otp_verify_json: | |
118 | raise ExtractorError('Unable to verify OTP.', expected=True) | |
119 | self._USER_TOKEN = otp_verify_json.get('token') | |
120 | if not self._USER_TOKEN: | |
121 | raise ExtractorError(otp_request_json['message'], expected=True) | |
9d7fde89 | 122 | elif username.lower() == 'token' and try_call(lambda: jwt_decode_hs256(password)): |
52efa4b3 | 123 | self._USER_TOKEN = password |
124 | else: | |
125 | raise ExtractorError(self._LOGIN_HINT, expected=True) | |
da6dcbad | 126 | |
9d7fde89 | 127 | token = jwt_decode_hs256(self._USER_TOKEN) |
128 | if token.get('exp', 0) <= int(time.time()): | |
129 | raise ExtractorError('User token has expired', expected=True) | |
130 | self._USER_COUNTRY = token.get('current_country') | |
131 | ||
da6dcbad | 132 | def _real_extract(self, url): |
5ad28e7f | 133 | video_id, display_id = self._match_valid_url(url).group('id', 'display_id') |
da6dcbad | 134 | access_token_request = self._download_json( |
a0de8bb8 | 135 | 'https://launchapi.zee5.com/launch?platform_name=web_app', |
136 | video_id, note='Downloading access token')['platform_token'] | |
96c23f3b | 137 | data = { |
add96eb9 | 138 | 'x-access-token': access_token_request['token'], |
96c23f3b A |
139 | } |
140 | if self._USER_TOKEN: | |
add96eb9 | 141 | data['Authorization'] = f'bearer {self._USER_TOKEN}' |
96c23f3b A |
142 | else: |
143 | data['X-Z5-Guest-Token'] = self._DEVICE_ID | |
da6dcbad | 144 | |
96c23f3b | 145 | json_data = self._download_json( |
9d7fde89 | 146 | 'https://spapi.zee5.com/singlePlayback/getDetails/secure', video_id, query={ |
147 | 'content_id': video_id, | |
148 | 'device_id': self._DEVICE_ID, | |
149 | 'platform_name': 'desktop_web', | |
150 | 'country': self._USER_COUNTRY or self.get_param('geo_bypass_country') or 'IN', | |
151 | 'check_parental_control': False, | |
add96eb9 | 152 | }, headers={'content-type': 'application/json'}, data=json.dumps(data).encode()) |
96c23f3b A |
153 | asset_data = json_data['assetDetails'] |
154 | show_data = json_data.get('showDetails', {}) | |
155 | if 'premium' in asset_data['business_type']: | |
156 | raise ExtractorError('Premium content is DRM protected.', expected=True) | |
157 | if not asset_data.get('hls_url'): | |
158 | self.raise_login_required(self._LOGIN_HINT, metadata_available=True, method=None) | |
159 | formats, m3u8_subs = self._extract_m3u8_formats_and_subtitles(asset_data['hls_url'], video_id, 'mp4', fatal=False) | |
96c23f3b A |
160 | |
161 | subtitles = {} | |
162 | for sub in asset_data.get('subtitle_url', []): | |
163 | sub_url = sub.get('url') | |
164 | if not sub_url: | |
165 | continue | |
166 | subtitles.setdefault(sub.get('language', 'en'), []).append({ | |
167 | 'url': self._proto_relative_url(sub_url), | |
168 | }) | |
169 | subtitles = self._merge_subtitles(subtitles, m3u8_subs) | |
da6dcbad A |
170 | return { |
171 | 'id': video_id, | |
172 | 'display_id': display_id, | |
96c23f3b | 173 | 'title': asset_data['title'], |
da6dcbad | 174 | 'formats': formats, |
96c23f3b A |
175 | 'subtitles': subtitles, |
176 | 'duration': int_or_none(asset_data.get('duration')), | |
96c23f3b A |
177 | 'description': str_or_none(asset_data.get('description')), |
178 | 'alt_title': str_or_none(asset_data.get('original_title')), | |
179 | 'uploader': str_or_none(asset_data.get('content_owner')), | |
180 | 'age_limit': parse_age_limit(asset_data.get('age_rating')), | |
181 | 'release_date': unified_strdate(asset_data.get('release_date')), | |
182 | 'timestamp': unified_timestamp(asset_data.get('release_date')), | |
183 | 'thumbnail': url_or_none(asset_data.get('image_url')), | |
184 | 'series': str_or_none(asset_data.get('tvshow_name')), | |
185 | 'season': try_get(show_data, lambda x: x['seasons']['title'], str), | |
186 | 'season_number': int_or_none(try_get(show_data, lambda x: x['seasons'][0]['orderid'])), | |
187 | 'episode_number': int_or_none(try_get(asset_data, lambda x: x['orderid'])), | |
add96eb9 | 188 | 'tags': try_get(asset_data, lambda x: x['tags'], list), |
da6dcbad | 189 | } |
d488e254 A |
190 | |
191 | ||
192 | class Zee5SeriesIE(InfoExtractor): | |
193 | IE_NAME = 'zee5:series' | |
194 | _VALID_URL = r'''(?x) | |
195 | (?: | |
196 | zee5:series:| | |
73f035e1 | 197 | https?://(?:www\.)?zee5\.com/(?:[^#?]+/)? |
7244895b | 198 | (?:tv-shows|web-series|kids|zee5originals)/(?!kids-movies)(?:[^#/?]+/){2} |
d488e254 | 199 | ) |
b3a5115f | 200 | (?P<id>[^#/?]+)(?:/episodes)?/?(?:$|[?#]) |
d488e254 A |
201 | ''' |
202 | _TESTS = [{ | |
ee7b9bdf AG |
203 | 'url': 'https://www.zee5.com/kids/kids-shows/bandbudh-aur-budbak/0-6-1899', |
204 | 'playlist_mincount': 156, | |
d488e254 | 205 | 'info_dict': { |
ee7b9bdf | 206 | 'id': '0-6-1899', |
d488e254 A |
207 | }, |
208 | }, { | |
ee7b9bdf | 209 | 'url': 'https://www.zee5.com/tv-shows/details/bhabi-ji-ghar-par-hai/0-6-199', |
d488e254 A |
210 | 'playlist_mincount': 1500, |
211 | 'info_dict': { | |
212 | 'id': '0-6-199', | |
213 | }, | |
214 | }, { | |
ee7b9bdf | 215 | 'url': 'https://www.zee5.com/tv-shows/details/agent-raghav-crime-branch/0-6-965', |
96c23f3b | 216 | 'playlist_mincount': 24, |
d488e254 A |
217 | 'info_dict': { |
218 | 'id': '0-6-965', | |
219 | }, | |
220 | }, { | |
ee7b9bdf | 221 | 'url': 'https://www.zee5.com/ta/tv-shows/details/nagabhairavi/0-6-3201', |
d488e254 A |
222 | 'playlist_mincount': 3, |
223 | 'info_dict': { | |
224 | 'id': '0-6-3201', | |
225 | }, | |
226 | }, { | |
ee7b9bdf | 227 | 'url': 'https://www.zee5.com/global/hi/tv-shows/details/khwaabon-ki-zamin-par/0-6-270', |
d488e254 A |
228 | 'playlist_mincount': 150, |
229 | 'info_dict': { | |
230 | 'id': '0-6-270', | |
231 | }, | |
b3a5115f | 232 | }, { |
ee7b9bdf | 233 | 'url': 'https://www.zee5.com/tv-shows/details/chala-hawa-yeu-dya-ladies-zindabaad/0-6-2943/episodes', |
b3a5115f | 234 | 'only_matching': True, |
4d4f9a02 AJ |
235 | }, { |
236 | 'url': 'https://www.zee5.com/web-series/details/mithya/0-6-4z587408', | |
237 | 'only_matching': True, | |
b3a5115f | 238 | }] |
d488e254 A |
239 | |
240 | def _entries(self, show_id): | |
241 | access_token_request = self._download_json( | |
a0de8bb8 | 242 | 'https://launchapi.zee5.com/launch?platform_name=web_app', |
243 | show_id, note='Downloading access token')['platform_token'] | |
d488e254 A |
244 | headers = { |
245 | 'X-Access-Token': access_token_request['token'], | |
246 | 'Referer': 'https://www.zee5.com/', | |
247 | } | |
86e5f3ed | 248 | show_url = f'https://gwapi.zee5.com/content/tvshow/{show_id}?translation=en&country=IN' |
d488e254 A |
249 | |
250 | page_num = 0 | |
251 | show_json = self._download_json(show_url, video_id=show_id, headers=headers) | |
252 | for season in show_json.get('seasons') or []: | |
add96eb9 | 253 | season_id = try_get(season, lambda x: x['id'], str) |
86e5f3ed | 254 | next_url = f'https://gwapi.zee5.com/content/tvshow/?season_id={season_id}&type=episode&translation=en&country=IN&on_air=false&asset_subtype=tvshow&page=1&limit=100' |
d488e254 A |
255 | while next_url: |
256 | page_num += 1 | |
257 | episodes_json = self._download_json( | |
258 | next_url, video_id=show_id, headers=headers, | |
add96eb9 | 259 | note=f'Downloading JSON metadata page {page_num}') |
d488e254 A |
260 | for episode in try_get(episodes_json, lambda x: x['episode'], list) or []: |
261 | video_id = episode.get('id') | |
262 | yield self.url_result( | |
add96eb9 | 263 | f'zee5:{video_id}', |
d488e254 A |
264 | ie=Zee5IE.ie_key(), video_id=video_id) |
265 | next_url = url_or_none(episodes_json.get('next_episode_api')) | |
266 | ||
267 | def _real_extract(self, url): | |
268 | show_id = self._match_id(url) | |
269 | return self.playlist_result(self._entries(show_id), playlist_id=show_id) |