import json
-import random
-import string
+import time
+import uuid
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
ExtractorError,
int_or_none,
+ jwt_decode_hs256,
parse_age_limit,
str_or_none,
+ try_call,
try_get,
unified_strdate,
unified_timestamp,
'display_id': 'adavari-matalaku-ardhale-verule',
'title': 'Adavari Matalaku Ardhale Verule',
'duration': 9360,
- 'description': compat_str,
+ 'description': str,
'alt_title': 'Adavari Matalaku Ardhale Verule',
'uploader': 'Zee Entertainment Enterprises Ltd',
'release_date': '20070427',
'thumbnail': r're:^https?://.*\.jpg$',
'episode_number': 0,
'episode': 'Episode 0',
- 'tags': list
+ 'tags': list,
},
'params': {
'format': 'bv',
'display_id': 'yoga-se-hoga-bandbudh-aur-budbak',
'title': 'Yoga Se Hoga-Bandbudh aur Budbak',
'duration': 659,
- 'description': compat_str,
+ 'description': str,
'alt_title': 'Yoga Se Hoga-Bandbudh aur Budbak',
'uploader': 'Zee Entertainment Enterprises Ltd',
'release_date': '20150101',
},
}, {
'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',
- 'only_matching': True
+ 'only_matching': True,
}, {
'url': 'https://www.zee5.com/global/hi/tv-shows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730',
- 'only_matching': True
+ 'only_matching': True,
}, {
'url': 'https://www.zee5.com/web-series/details/mithya/0-6-4z587408/maine-dekhi-hai-uski-mrityu/0-1-6z587412',
- 'only_matching': True
+ 'only_matching': True,
}, {
'url': 'https://www.zee5.com/kids/kids-movies/maya-bommalu/0-0-movie_1040370005',
- 'only_matching': True
+ 'only_matching': True,
}, {
'url': 'https://www.zee5.com/news/details/jana-sena-chief-pawan-kalyan-shows-slippers-to-ysrcp-leaders/0-0-newsauto_6ettj4242oo0',
- 'only_matching': True
+ 'only_matching': True,
}, {
'url': 'https://www.zee5.com/music-videos/details/adhento-gaani-vunnapaatuga-jersey-nani-shraddha-srinath/0-0-56973',
- 'only_matching': True
+ 'only_matching': True,
}]
- _DETAIL_API_URL = 'https://spapi.zee5.com/singlePlayback/getDetails/secure?content_id={}&device_id={}&platform_name=desktop_web&country=IN&check_parental_control=false'
- _DEVICE_ID = ''.join(random.choices(string.ascii_letters + string.digits, k=20)).ljust(32, '0')
+ _DEVICE_ID = str(uuid.uuid4())
_USER_TOKEN = None
_LOGIN_HINT = 'Use "--username <mobile_number>" to login using otp or "--username token" and "--password <user_token>" to login using user token.'
_NETRC_MACHINE = 'zee5'
_GEO_COUNTRIES = ['IN']
+ _USER_COUNTRY = None
def _perform_login(self, username, password):
if len(username) == 10 and username.isdigit() and self._USER_TOKEN is None:
self._USER_TOKEN = otp_verify_json.get('token')
if not self._USER_TOKEN:
raise ExtractorError(otp_request_json['message'], expected=True)
- elif username.lower() == 'token' and len(password) > 1198:
+ elif username.lower() == 'token' and try_call(lambda: jwt_decode_hs256(password)):
self._USER_TOKEN = password
else:
raise ExtractorError(self._LOGIN_HINT, expected=True)
+ token = jwt_decode_hs256(self._USER_TOKEN)
+ if token.get('exp', 0) <= int(time.time()):
+ raise ExtractorError('User token has expired', expected=True)
+ self._USER_COUNTRY = token.get('current_country')
+
def _real_extract(self, url):
video_id, display_id = self._match_valid_url(url).group('id', 'display_id')
access_token_request = self._download_json(
- 'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app',
- video_id, note='Downloading access token')
+ 'https://launchapi.zee5.com/launch?platform_name=web_app',
+ video_id, note='Downloading access token')['platform_token']
data = {
- 'x-access-token': access_token_request['token']
+ 'x-access-token': access_token_request['token'],
}
if self._USER_TOKEN:
- data['Authorization'] = 'bearer %s' % self._USER_TOKEN
+ data['Authorization'] = f'bearer {self._USER_TOKEN}'
else:
data['X-Z5-Guest-Token'] = self._DEVICE_ID
json_data = self._download_json(
- self._DETAIL_API_URL.format(video_id, self._DEVICE_ID),
- video_id, headers={'content-type': 'application/json'}, data=json.dumps(data).encode('utf-8'))
+ 'https://spapi.zee5.com/singlePlayback/getDetails/secure', video_id, query={
+ 'content_id': video_id,
+ 'device_id': self._DEVICE_ID,
+ 'platform_name': 'desktop_web',
+ 'country': self._USER_COUNTRY or self.get_param('geo_bypass_country') or 'IN',
+ 'check_parental_control': False,
+ }, headers={'content-type': 'application/json'}, data=json.dumps(data).encode())
asset_data = json_data['assetDetails']
show_data = json_data.get('showDetails', {})
if 'premium' in asset_data['business_type']:
if not asset_data.get('hls_url'):
self.raise_login_required(self._LOGIN_HINT, metadata_available=True, method=None)
formats, m3u8_subs = self._extract_m3u8_formats_and_subtitles(asset_data['hls_url'], video_id, 'mp4', fatal=False)
- self._sort_formats(formats)
subtitles = {}
for sub in asset_data.get('subtitle_url', []):
'season': try_get(show_data, lambda x: x['seasons']['title'], str),
'season_number': int_or_none(try_get(show_data, lambda x: x['seasons'][0]['orderid'])),
'episode_number': int_or_none(try_get(asset_data, lambda x: x['orderid'])),
- 'tags': try_get(asset_data, lambda x: x['tags'], list)
+ 'tags': try_get(asset_data, lambda x: x['tags'], list),
}
def _entries(self, show_id):
access_token_request = self._download_json(
- 'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app',
- show_id, note='Downloading access token')
+ 'https://launchapi.zee5.com/launch?platform_name=web_app',
+ show_id, note='Downloading access token')['platform_token']
headers = {
'X-Access-Token': access_token_request['token'],
'Referer': 'https://www.zee5.com/',
page_num = 0
show_json = self._download_json(show_url, video_id=show_id, headers=headers)
for season in show_json.get('seasons') or []:
- season_id = try_get(season, lambda x: x['id'], compat_str)
+ season_id = try_get(season, lambda x: x['id'], str)
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'
while next_url:
page_num += 1
episodes_json = self._download_json(
next_url, video_id=show_id, headers=headers,
- note='Downloading JSON metadata page %d' % page_num)
+ note=f'Downloading JSON metadata page {page_num}')
for episode in try_get(episodes_json, lambda x: x['episode'], list) or []:
video_id = episode.get('id')
yield self.url_result(
- 'zee5:%s' % video_id,
+ f'zee5:{video_id}',
ie=Zee5IE.ie_key(), video_id=video_id)
next_url = url_or_none(episodes_json.get('next_episode_api'))