2021-08-20 21:13:12 +02:00
|
|
|
import json
|
2023-06-11 19:15:05 +02:00
|
|
|
import time
|
|
|
|
import uuid
|
2021-02-22 18:20:43 +01:00
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2021-03-11 08:48:09 +01:00
|
|
|
from ..compat import compat_str
|
2021-02-22 18:20:43 +01:00
|
|
|
from ..utils import (
|
2021-08-20 21:13:12 +02:00
|
|
|
ExtractorError,
|
2021-02-22 18:20:43 +01:00
|
|
|
int_or_none,
|
2023-06-11 19:15:05 +02:00
|
|
|
jwt_decode_hs256,
|
2021-02-22 18:20:43 +01:00
|
|
|
parse_age_limit,
|
|
|
|
str_or_none,
|
2023-06-11 19:15:05 +02:00
|
|
|
try_call,
|
2021-02-22 18:20:43 +01:00
|
|
|
try_get,
|
|
|
|
unified_strdate,
|
|
|
|
unified_timestamp,
|
|
|
|
url_or_none,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Zee5IE(InfoExtractor):
|
2021-03-11 08:48:09 +01:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
(?:
|
|
|
|
zee5:|
|
2021-11-30 17:14:47 +01:00
|
|
|
https?://(?:www\.)?zee5\.com/(?:[^#?]+/)?
|
2021-03-11 08:48:09 +01:00
|
|
|
(?:
|
2022-02-21 09:07:36 +01:00
|
|
|
(?:tv-shows|kids|web-series|zee5originals)(?:/[^#/?]+){3}
|
2022-10-21 12:41:43 +02:00
|
|
|
|(?:movies|kids|videos|news|music-videos)/(?!kids-shows)[^#/?]+
|
2021-03-11 08:48:09 +01:00
|
|
|
)/(?P<display_id>[^#/?]+)/
|
|
|
|
)
|
|
|
|
(?P<id>[^#/?]+)/?(?:$|[?#])
|
|
|
|
'''
|
2021-02-22 18:20:43 +01:00
|
|
|
_TESTS = [{
|
2022-07-24 10:33:39 +02:00
|
|
|
'url': 'https://www.zee5.com/movies/details/adavari-matalaku-ardhale-verule/0-0-movie_1143162669',
|
2021-02-22 18:20:43 +01:00
|
|
|
'info_dict': {
|
2022-07-24 10:33:39 +02:00
|
|
|
'id': '0-0-movie_1143162669',
|
2021-03-11 08:48:09 +01:00
|
|
|
'ext': 'mp4',
|
2022-07-24 10:33:39 +02:00
|
|
|
'display_id': 'adavari-matalaku-ardhale-verule',
|
|
|
|
'title': 'Adavari Matalaku Ardhale Verule',
|
|
|
|
'duration': 9360,
|
2021-05-02 20:18:35 +02:00
|
|
|
'description': compat_str,
|
2022-07-24 10:33:39 +02:00
|
|
|
'alt_title': 'Adavari Matalaku Ardhale Verule',
|
2021-03-11 08:48:09 +01:00
|
|
|
'uploader': 'Zee Entertainment Enterprises Ltd',
|
2022-07-24 10:33:39 +02:00
|
|
|
'release_date': '20070427',
|
|
|
|
'upload_date': '20070427',
|
|
|
|
'timestamp': 1177632000,
|
2021-12-26 15:31:43 +01:00
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
|
|
|
'episode_number': 0,
|
|
|
|
'episode': 'Episode 0',
|
2021-03-11 08:48:09 +01:00
|
|
|
'tags': list
|
2021-02-22 18:20:43 +01:00
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'format': 'bv',
|
|
|
|
},
|
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/kids/kids-shows/bandbudh-aur-budbak/0-6-1899/yoga-se-hoga-bandbudh-aur-budbak/0-1-239839',
|
2021-02-22 18:20:43 +01:00
|
|
|
'info_dict': {
|
2021-12-26 15:31:43 +01:00
|
|
|
'id': '0-1-239839',
|
2021-03-11 08:48:09 +01:00
|
|
|
'ext': 'mp4',
|
2021-12-26 15:31:43 +01:00
|
|
|
'display_id': 'yoga-se-hoga-bandbudh-aur-budbak',
|
|
|
|
'title': 'Yoga Se Hoga-Bandbudh aur Budbak',
|
|
|
|
'duration': 659,
|
2021-05-02 20:18:35 +02:00
|
|
|
'description': compat_str,
|
2021-12-26 15:31:43 +01:00
|
|
|
'alt_title': 'Yoga Se Hoga-Bandbudh aur Budbak',
|
2021-08-20 21:13:12 +02:00
|
|
|
'uploader': 'Zee Entertainment Enterprises Ltd',
|
2021-12-26 15:31:43 +01:00
|
|
|
'release_date': '20150101',
|
|
|
|
'upload_date': '20150101',
|
|
|
|
'timestamp': 1420070400,
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
|
|
|
'series': 'Bandbudh Aur Budbak',
|
2021-03-11 08:48:09 +01:00
|
|
|
'season_number': 1,
|
|
|
|
'episode_number': 1,
|
2021-12-26 15:31:43 +01:00
|
|
|
'episode': 'Episode 1',
|
|
|
|
'season': 'Season 1',
|
2021-03-11 08:48:09 +01:00
|
|
|
'tags': list,
|
2021-02-22 18:20:43 +01:00
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'format': 'bv',
|
|
|
|
},
|
2021-03-09 10:41:33 +01:00
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'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',
|
2021-03-09 10:41:33 +01:00
|
|
|
'only_matching': True
|
2021-03-11 08:48:09 +01:00
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/global/hi/tv-shows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730',
|
2021-03-11 08:48:09 +01:00
|
|
|
'only_matching': True
|
2022-02-21 09:07:36 +01:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.zee5.com/web-series/details/mithya/0-6-4z587408/maine-dekhi-hai-uski-mrityu/0-1-6z587412',
|
|
|
|
'only_matching': True
|
2022-10-03 16:12:56 +02:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.zee5.com/kids/kids-movies/maya-bommalu/0-0-movie_1040370005',
|
|
|
|
'only_matching': True
|
2022-10-21 12:41:43 +02:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.zee5.com/news/details/jana-sena-chief-pawan-kalyan-shows-slippers-to-ysrcp-leaders/0-0-newsauto_6ettj4242oo0',
|
|
|
|
'only_matching': True
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.zee5.com/music-videos/details/adhento-gaani-vunnapaatuga-jersey-nani-shraddha-srinath/0-0-56973',
|
|
|
|
'only_matching': True
|
2021-02-22 18:20:43 +01:00
|
|
|
}]
|
2023-06-11 19:15:05 +02:00
|
|
|
_DEVICE_ID = str(uuid.uuid4())
|
2021-08-20 21:13:12 +02:00
|
|
|
_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'
|
2022-01-04 08:20:11 +01:00
|
|
|
_GEO_COUNTRIES = ['IN']
|
2023-06-11 19:15:05 +02:00
|
|
|
_USER_COUNTRY = None
|
2021-08-20 21:13:12 +02:00
|
|
|
|
2022-03-18 21:53:33 +01:00
|
|
|
def _perform_login(self, username, password):
|
|
|
|
if len(username) == 10 and username.isdigit() and self._USER_TOKEN is None:
|
|
|
|
self.report_login()
|
2022-04-11 17:10:28 +02:00
|
|
|
otp_request_json = self._download_json(f'https://b2bapi.zee5.com/device/sendotp_v1.php?phoneno=91{username}',
|
2022-03-18 21:53:33 +01:00
|
|
|
None, note='Sending OTP')
|
|
|
|
if otp_request_json['code'] == 0:
|
|
|
|
self.to_screen(otp_request_json['message'])
|
2022-01-03 20:37:24 +01:00
|
|
|
else:
|
2022-03-18 21:53:33 +01:00
|
|
|
raise ExtractorError(otp_request_json['message'], expected=True)
|
|
|
|
otp_code = self._get_tfa_info('OTP')
|
2022-04-11 17:10:28 +02:00
|
|
|
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',
|
2022-03-18 21:53:33 +01:00
|
|
|
None, note='Verifying OTP', fatal=False)
|
|
|
|
if not otp_verify_json:
|
|
|
|
raise ExtractorError('Unable to verify OTP.', expected=True)
|
|
|
|
self._USER_TOKEN = otp_verify_json.get('token')
|
|
|
|
if not self._USER_TOKEN:
|
|
|
|
raise ExtractorError(otp_request_json['message'], expected=True)
|
2023-06-11 19:15:05 +02:00
|
|
|
elif username.lower() == 'token' and try_call(lambda: jwt_decode_hs256(password)):
|
2022-03-18 21:53:33 +01:00
|
|
|
self._USER_TOKEN = password
|
|
|
|
else:
|
|
|
|
raise ExtractorError(self._LOGIN_HINT, expected=True)
|
2021-02-22 18:20:43 +01:00
|
|
|
|
2023-06-11 19:15:05 +02:00
|
|
|
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')
|
|
|
|
|
2021-02-22 18:20:43 +01:00
|
|
|
def _real_extract(self, url):
|
2021-08-19 03:41:24 +02:00
|
|
|
video_id, display_id = self._match_valid_url(url).group('id', 'display_id')
|
2021-02-22 18:20:43 +01:00
|
|
|
access_token_request = self._download_json(
|
2023-08-20 18:10:15 +02:00
|
|
|
'https://launchapi.zee5.com/launch?platform_name=web_app',
|
|
|
|
video_id, note='Downloading access token')['platform_token']
|
2021-08-20 21:13:12 +02:00
|
|
|
data = {
|
|
|
|
'x-access-token': access_token_request['token']
|
|
|
|
}
|
|
|
|
if self._USER_TOKEN:
|
|
|
|
data['Authorization'] = 'bearer %s' % self._USER_TOKEN
|
|
|
|
else:
|
|
|
|
data['X-Z5-Guest-Token'] = self._DEVICE_ID
|
2021-02-22 18:20:43 +01:00
|
|
|
|
2021-08-20 21:13:12 +02:00
|
|
|
json_data = self._download_json(
|
2023-06-11 19:15:05 +02:00
|
|
|
'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('utf-8'))
|
2021-08-20 21:13:12 +02:00
|
|
|
asset_data = json_data['assetDetails']
|
|
|
|
show_data = json_data.get('showDetails', {})
|
|
|
|
if 'premium' in asset_data['business_type']:
|
|
|
|
raise ExtractorError('Premium content is DRM protected.', expected=True)
|
|
|
|
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)
|
|
|
|
|
|
|
|
subtitles = {}
|
|
|
|
for sub in asset_data.get('subtitle_url', []):
|
|
|
|
sub_url = sub.get('url')
|
|
|
|
if not sub_url:
|
|
|
|
continue
|
|
|
|
subtitles.setdefault(sub.get('language', 'en'), []).append({
|
|
|
|
'url': self._proto_relative_url(sub_url),
|
|
|
|
})
|
|
|
|
subtitles = self._merge_subtitles(subtitles, m3u8_subs)
|
2021-02-22 18:20:43 +01:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'display_id': display_id,
|
2021-08-20 21:13:12 +02:00
|
|
|
'title': asset_data['title'],
|
2021-02-22 18:20:43 +01:00
|
|
|
'formats': formats,
|
2021-08-20 21:13:12 +02:00
|
|
|
'subtitles': subtitles,
|
|
|
|
'duration': int_or_none(asset_data.get('duration')),
|
|
|
|
'description': str_or_none(asset_data.get('description')),
|
|
|
|
'alt_title': str_or_none(asset_data.get('original_title')),
|
|
|
|
'uploader': str_or_none(asset_data.get('content_owner')),
|
|
|
|
'age_limit': parse_age_limit(asset_data.get('age_rating')),
|
|
|
|
'release_date': unified_strdate(asset_data.get('release_date')),
|
|
|
|
'timestamp': unified_timestamp(asset_data.get('release_date')),
|
|
|
|
'thumbnail': url_or_none(asset_data.get('image_url')),
|
|
|
|
'series': str_or_none(asset_data.get('tvshow_name')),
|
|
|
|
'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)
|
2021-02-22 18:20:43 +01:00
|
|
|
}
|
2021-03-11 08:48:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Zee5SeriesIE(InfoExtractor):
|
|
|
|
IE_NAME = 'zee5:series'
|
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
(?:
|
|
|
|
zee5:series:|
|
2021-11-30 17:14:47 +01:00
|
|
|
https?://(?:www\.)?zee5\.com/(?:[^#?]+/)?
|
2022-10-03 16:12:56 +02:00
|
|
|
(?:tv-shows|web-series|kids|zee5originals)/(?!kids-movies)(?:[^#/?]+/){2}
|
2021-03-11 08:48:09 +01:00
|
|
|
)
|
2021-12-16 23:59:06 +01:00
|
|
|
(?P<id>[^#/?]+)(?:/episodes)?/?(?:$|[?#])
|
2021-03-11 08:48:09 +01:00
|
|
|
'''
|
|
|
|
_TESTS = [{
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/kids/kids-shows/bandbudh-aur-budbak/0-6-1899',
|
|
|
|
'playlist_mincount': 156,
|
2021-03-11 08:48:09 +01:00
|
|
|
'info_dict': {
|
2021-12-26 15:31:43 +01:00
|
|
|
'id': '0-6-1899',
|
2021-03-11 08:48:09 +01:00
|
|
|
},
|
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/tv-shows/details/bhabi-ji-ghar-par-hai/0-6-199',
|
2021-03-11 08:48:09 +01:00
|
|
|
'playlist_mincount': 1500,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '0-6-199',
|
|
|
|
},
|
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/tv-shows/details/agent-raghav-crime-branch/0-6-965',
|
2021-08-20 21:13:12 +02:00
|
|
|
'playlist_mincount': 24,
|
2021-03-11 08:48:09 +01:00
|
|
|
'info_dict': {
|
|
|
|
'id': '0-6-965',
|
|
|
|
},
|
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/ta/tv-shows/details/nagabhairavi/0-6-3201',
|
2021-03-11 08:48:09 +01:00
|
|
|
'playlist_mincount': 3,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '0-6-3201',
|
|
|
|
},
|
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/global/hi/tv-shows/details/khwaabon-ki-zamin-par/0-6-270',
|
2021-03-11 08:48:09 +01:00
|
|
|
'playlist_mincount': 150,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '0-6-270',
|
|
|
|
},
|
2021-12-16 23:59:06 +01:00
|
|
|
}, {
|
2021-12-26 15:31:43 +01:00
|
|
|
'url': 'https://www.zee5.com/tv-shows/details/chala-hawa-yeu-dya-ladies-zindabaad/0-6-2943/episodes',
|
2021-12-16 23:59:06 +01:00
|
|
|
'only_matching': True,
|
2022-02-21 09:07:36 +01:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.zee5.com/web-series/details/mithya/0-6-4z587408',
|
|
|
|
'only_matching': True,
|
2021-12-16 23:59:06 +01:00
|
|
|
}]
|
2021-03-11 08:48:09 +01:00
|
|
|
|
|
|
|
def _entries(self, show_id):
|
|
|
|
access_token_request = self._download_json(
|
2023-08-20 18:10:15 +02:00
|
|
|
'https://launchapi.zee5.com/launch?platform_name=web_app',
|
|
|
|
show_id, note='Downloading access token')['platform_token']
|
2021-03-11 08:48:09 +01:00
|
|
|
headers = {
|
|
|
|
'X-Access-Token': access_token_request['token'],
|
|
|
|
'Referer': 'https://www.zee5.com/',
|
|
|
|
}
|
2022-04-11 17:10:28 +02:00
|
|
|
show_url = f'https://gwapi.zee5.com/content/tvshow/{show_id}?translation=en&country=IN'
|
2021-03-11 08:48:09 +01:00
|
|
|
|
|
|
|
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)
|
2022-04-11 17:10:28 +02:00
|
|
|
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'
|
2021-03-11 08:48:09 +01:00
|
|
|
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)
|
|
|
|
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,
|
|
|
|
ie=Zee5IE.ie_key(), video_id=video_id)
|
|
|
|
next_url = url_or_none(episodes_json.get('next_episode_api'))
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
show_id = self._match_id(url)
|
|
|
|
return self.playlist_result(self._entries(show_id), playlist_id=show_id)
|