]>
Commit | Line | Data |
---|---|---|
da6dcbad A |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
96c23f3b | 4 | import json |
da6dcbad A |
5 | |
6 | from .common import InfoExtractor | |
d488e254 | 7 | from ..compat import compat_str |
da6dcbad | 8 | from ..utils import ( |
96c23f3b | 9 | ExtractorError, |
da6dcbad A |
10 | int_or_none, |
11 | parse_age_limit, | |
12 | str_or_none, | |
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 | (?: |
ee7b9bdf | 26 | (?:tv-shows|kids|zee5originals)(?:/[^#/?]+){3} |
d488e254 A |
27 | |movies/[^#/?]+ |
28 | )/(?P<display_id>[^#/?]+)/ | |
29 | ) | |
30 | (?P<id>[^#/?]+)/?(?:$|[?#]) | |
31 | ''' | |
da6dcbad A |
32 | _TESTS = [{ |
33 | 'url': 'https://www.zee5.com/movies/details/krishna-the-birth/0-0-63098', | |
34 | 'info_dict': { | |
d488e254 A |
35 | 'id': '0-0-63098', |
36 | 'ext': 'mp4', | |
37 | 'display_id': 'krishna-the-birth', | |
38 | 'title': 'Krishna - The Birth', | |
39 | 'duration': 4368, | |
1815d102 | 40 | 'description': compat_str, |
d488e254 A |
41 | 'alt_title': 'Krishna - The Birth', |
42 | 'uploader': 'Zee Entertainment Enterprises Ltd', | |
43 | 'release_date': '20060101', | |
44 | 'upload_date': '20060101', | |
45 | 'timestamp': 1136073600, | |
ee7b9bdf AG |
46 | 'thumbnail': r're:^https?://.*\.jpg$', |
47 | 'episode_number': 0, | |
48 | 'episode': 'Episode 0', | |
d488e254 | 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, | |
1815d102 | 62 | 'description': compat_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', |
54759df5 | 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', |
d488e254 | 84 | 'only_matching': True |
da6dcbad | 85 | }] |
96c23f3b A |
86 | _DETAIL_API_URL = 'https://spapi.zee5.com/singlePlayback/getDetails?content_id={}&device_id={}&platform_name=desktop_web&country=IN&check_parental_control=false' |
87 | _DEVICE_ID = 'iIxsxYf40cqO3koIkwzKHZhnJzHN13zb' | |
88 | _USER_TOKEN = None | |
89 | _LOGIN_HINT = 'Use "--username <mobile_number>" to login using otp or "--username token" and "--password <user_token>" to login using user token.' | |
90 | _NETRC_MACHINE = 'zee5' | |
fdeab99e | 91 | _GEO_COUNTRIES = ['IN'] |
96c23f3b A |
92 | |
93 | def _login(self): | |
94 | username, password = self._get_login_info() | |
95 | if username: | |
96 | if len(username) == 10 and username.isdigit() and self._USER_TOKEN is None: | |
97 | self.report_login() | |
98 | otp_request_json = self._download_json('https://b2bapi.zee5.com/device/sendotp_v1.php?phoneno=91{}'.format(username), | |
99 | None, note='Sending OTP') | |
100 | if otp_request_json['code'] == 0: | |
101 | self.to_screen(otp_request_json['message']) | |
102 | else: | |
103 | raise ExtractorError(otp_request_json['message'], expected=True) | |
104 | otp_code = self._get_tfa_info('OTP') | |
105 | otp_verify_json = self._download_json('https://b2bapi.zee5.com/device/verifyotp_v1.php?phoneno=91{}&otp={}&guest_token={}&platform=web'.format(username, otp_code, self._DEVICE_ID), | |
106 | None, note='Verifying OTP', fatal=False) | |
107 | if not otp_verify_json: | |
108 | raise ExtractorError('Unable to verify OTP.', expected=True) | |
109 | self._USER_TOKEN = otp_verify_json.get('token') | |
110 | if not self._USER_TOKEN: | |
111 | raise ExtractorError(otp_request_json['message'], expected=True) | |
112 | elif username.lower() == 'token' and len(password) > 1198: | |
113 | self._USER_TOKEN = password | |
9e907ebd | 114 | else: |
115 | raise ExtractorError(self._LOGIN_HINT, expected=True) | |
96c23f3b A |
116 | |
117 | def _real_initialize(self): | |
118 | self._login() | |
da6dcbad A |
119 | |
120 | def _real_extract(self, url): | |
5ad28e7f | 121 | video_id, display_id = self._match_valid_url(url).group('id', 'display_id') |
da6dcbad A |
122 | access_token_request = self._download_json( |
123 | 'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app', | |
d488e254 | 124 | video_id, note='Downloading access token') |
96c23f3b A |
125 | data = { |
126 | 'x-access-token': access_token_request['token'] | |
127 | } | |
128 | if self._USER_TOKEN: | |
129 | data['Authorization'] = 'bearer %s' % self._USER_TOKEN | |
130 | else: | |
131 | data['X-Z5-Guest-Token'] = self._DEVICE_ID | |
da6dcbad | 132 | |
96c23f3b A |
133 | json_data = self._download_json( |
134 | self._DETAIL_API_URL.format(video_id, self._DEVICE_ID), | |
135 | video_id, headers={'content-type': 'application/json'}, data=json.dumps(data).encode('utf-8')) | |
136 | asset_data = json_data['assetDetails'] | |
137 | show_data = json_data.get('showDetails', {}) | |
138 | if 'premium' in asset_data['business_type']: | |
139 | raise ExtractorError('Premium content is DRM protected.', expected=True) | |
140 | if not asset_data.get('hls_url'): | |
141 | self.raise_login_required(self._LOGIN_HINT, metadata_available=True, method=None) | |
142 | formats, m3u8_subs = self._extract_m3u8_formats_and_subtitles(asset_data['hls_url'], video_id, 'mp4', fatal=False) | |
da6dcbad | 143 | self._sort_formats(formats) |
96c23f3b A |
144 | |
145 | subtitles = {} | |
146 | for sub in asset_data.get('subtitle_url', []): | |
147 | sub_url = sub.get('url') | |
148 | if not sub_url: | |
149 | continue | |
150 | subtitles.setdefault(sub.get('language', 'en'), []).append({ | |
151 | 'url': self._proto_relative_url(sub_url), | |
152 | }) | |
153 | subtitles = self._merge_subtitles(subtitles, m3u8_subs) | |
da6dcbad A |
154 | return { |
155 | 'id': video_id, | |
156 | 'display_id': display_id, | |
96c23f3b | 157 | 'title': asset_data['title'], |
da6dcbad | 158 | 'formats': formats, |
96c23f3b A |
159 | 'subtitles': subtitles, |
160 | 'duration': int_or_none(asset_data.get('duration')), | |
96c23f3b A |
161 | 'description': str_or_none(asset_data.get('description')), |
162 | 'alt_title': str_or_none(asset_data.get('original_title')), | |
163 | 'uploader': str_or_none(asset_data.get('content_owner')), | |
164 | 'age_limit': parse_age_limit(asset_data.get('age_rating')), | |
165 | 'release_date': unified_strdate(asset_data.get('release_date')), | |
166 | 'timestamp': unified_timestamp(asset_data.get('release_date')), | |
167 | 'thumbnail': url_or_none(asset_data.get('image_url')), | |
168 | 'series': str_or_none(asset_data.get('tvshow_name')), | |
169 | 'season': try_get(show_data, lambda x: x['seasons']['title'], str), | |
170 | 'season_number': int_or_none(try_get(show_data, lambda x: x['seasons'][0]['orderid'])), | |
171 | 'episode_number': int_or_none(try_get(asset_data, lambda x: x['orderid'])), | |
172 | 'tags': try_get(asset_data, lambda x: x['tags'], list) | |
da6dcbad | 173 | } |
d488e254 A |
174 | |
175 | ||
176 | class Zee5SeriesIE(InfoExtractor): | |
177 | IE_NAME = 'zee5:series' | |
178 | _VALID_URL = r'''(?x) | |
179 | (?: | |
180 | zee5:series:| | |
73f035e1 | 181 | https?://(?:www\.)?zee5\.com/(?:[^#?]+/)? |
ee7b9bdf | 182 | (?:tv-shows|kids|zee5originals)(?:/[^#/?]+){2}/ |
d488e254 | 183 | ) |
b3a5115f | 184 | (?P<id>[^#/?]+)(?:/episodes)?/?(?:$|[?#]) |
d488e254 A |
185 | ''' |
186 | _TESTS = [{ | |
ee7b9bdf AG |
187 | 'url': 'https://www.zee5.com/kids/kids-shows/bandbudh-aur-budbak/0-6-1899', |
188 | 'playlist_mincount': 156, | |
d488e254 | 189 | 'info_dict': { |
ee7b9bdf | 190 | 'id': '0-6-1899', |
d488e254 A |
191 | }, |
192 | }, { | |
ee7b9bdf | 193 | 'url': 'https://www.zee5.com/tv-shows/details/bhabi-ji-ghar-par-hai/0-6-199', |
d488e254 A |
194 | 'playlist_mincount': 1500, |
195 | 'info_dict': { | |
196 | 'id': '0-6-199', | |
197 | }, | |
198 | }, { | |
ee7b9bdf | 199 | 'url': 'https://www.zee5.com/tv-shows/details/agent-raghav-crime-branch/0-6-965', |
96c23f3b | 200 | 'playlist_mincount': 24, |
d488e254 A |
201 | 'info_dict': { |
202 | 'id': '0-6-965', | |
203 | }, | |
204 | }, { | |
ee7b9bdf | 205 | 'url': 'https://www.zee5.com/ta/tv-shows/details/nagabhairavi/0-6-3201', |
d488e254 A |
206 | 'playlist_mincount': 3, |
207 | 'info_dict': { | |
208 | 'id': '0-6-3201', | |
209 | }, | |
210 | }, { | |
ee7b9bdf | 211 | 'url': 'https://www.zee5.com/global/hi/tv-shows/details/khwaabon-ki-zamin-par/0-6-270', |
d488e254 A |
212 | 'playlist_mincount': 150, |
213 | 'info_dict': { | |
214 | 'id': '0-6-270', | |
215 | }, | |
b3a5115f | 216 | }, { |
ee7b9bdf | 217 | 'url': 'https://www.zee5.com/tv-shows/details/chala-hawa-yeu-dya-ladies-zindabaad/0-6-2943/episodes', |
b3a5115f | 218 | 'only_matching': True, |
219 | }] | |
d488e254 A |
220 | |
221 | def _entries(self, show_id): | |
222 | access_token_request = self._download_json( | |
223 | 'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app', | |
224 | show_id, note='Downloading access token') | |
225 | headers = { | |
226 | 'X-Access-Token': access_token_request['token'], | |
227 | 'Referer': 'https://www.zee5.com/', | |
228 | } | |
229 | show_url = 'https://gwapi.zee5.com/content/tvshow/{}?translation=en&country=IN'.format(show_id) | |
230 | ||
231 | page_num = 0 | |
232 | show_json = self._download_json(show_url, video_id=show_id, headers=headers) | |
233 | for season in show_json.get('seasons') or []: | |
234 | season_id = try_get(season, lambda x: x['id'], compat_str) | |
235 | 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) | |
236 | while next_url: | |
237 | page_num += 1 | |
238 | episodes_json = self._download_json( | |
239 | next_url, video_id=show_id, headers=headers, | |
240 | note='Downloading JSON metadata page %d' % page_num) | |
241 | for episode in try_get(episodes_json, lambda x: x['episode'], list) or []: | |
242 | video_id = episode.get('id') | |
243 | yield self.url_result( | |
244 | 'zee5:%s' % video_id, | |
245 | ie=Zee5IE.ie_key(), video_id=video_id) | |
246 | next_url = url_or_none(episodes_json.get('next_episode_api')) | |
247 | ||
248 | def _real_extract(self, url): | |
249 | show_id = self._match_id(url) | |
250 | return self.playlist_result(self._entries(show_id), playlist_id=show_id) |