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