mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-16 21:33:19 +00:00
[Zee5] Fix extractor and add subtitles (#733)
Closes #728 Authored by Ashish0804
This commit is contained in:
parent
6e7dfe4959
commit
96c23f3be8
|
@ -1,11 +1,13 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_str
|
from ..compat import compat_str
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
parse_age_limit,
|
parse_age_limit,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
|
@ -60,7 +62,7 @@ class Zee5IE(InfoExtractor):
|
||||||
'average_rating': 4,
|
'average_rating': 4,
|
||||||
'description': compat_str,
|
'description': compat_str,
|
||||||
'alt_title': 'Episode 1 - The Test Of Bramha',
|
'alt_title': 'Episode 1 - The Test Of Bramha',
|
||||||
'uploader': 'Green Gold',
|
'uploader': 'Zee Entertainment Enterprises Ltd',
|
||||||
'release_date': '20090101',
|
'release_date': '20090101',
|
||||||
'upload_date': '20090101',
|
'upload_date': '20090101',
|
||||||
'timestamp': 1230768000,
|
'timestamp': 1230768000,
|
||||||
|
@ -80,53 +82,91 @@ class Zee5IE(InfoExtractor):
|
||||||
'url': 'https://www.zee5.com/global/hi/tvshows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730',
|
'url': 'https://www.zee5.com/global/hi/tvshows/details/kundali-bhagya/0-6-366/kundali-bhagya-march-08-2021/0-1-manual_7g9jv1os7730',
|
||||||
'only_matching': True
|
'only_matching': True
|
||||||
}]
|
}]
|
||||||
|
_DETAIL_API_URL = 'https://spapi.zee5.com/singlePlayback/getDetails?content_id={}&device_id={}&platform_name=desktop_web&country=IN&check_parental_control=false'
|
||||||
|
_DEVICE_ID = 'iIxsxYf40cqO3koIkwzKHZhnJzHN13zb'
|
||||||
|
_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'
|
||||||
|
|
||||||
|
def _login(self):
|
||||||
|
username, password = self._get_login_info()
|
||||||
|
if username:
|
||||||
|
if len(username) == 10 and username.isdigit() and self._USER_TOKEN is None:
|
||||||
|
self.report_login()
|
||||||
|
otp_request_json = self._download_json('https://b2bapi.zee5.com/device/sendotp_v1.php?phoneno=91{}'.format(username),
|
||||||
|
None, note='Sending OTP')
|
||||||
|
if otp_request_json['code'] == 0:
|
||||||
|
self.to_screen(otp_request_json['message'])
|
||||||
|
else:
|
||||||
|
raise ExtractorError(otp_request_json['message'], expected=True)
|
||||||
|
otp_code = self._get_tfa_info('OTP')
|
||||||
|
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),
|
||||||
|
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)
|
||||||
|
elif username.lower() == 'token' and len(password) > 1198:
|
||||||
|
self._USER_TOKEN = password
|
||||||
|
|
||||||
|
def _real_initialize(self):
|
||||||
|
self._login()
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id, display_id = re.match(self._VALID_URL, url).group('id', 'display_id')
|
video_id, display_id = re.match(self._VALID_URL, url).group('id', 'display_id')
|
||||||
access_token_request = self._download_json(
|
access_token_request = self._download_json(
|
||||||
'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app',
|
'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app',
|
||||||
video_id, note='Downloading access token')
|
video_id, note='Downloading access token')
|
||||||
token_request = self._download_json(
|
data = {
|
||||||
'https://useraction.zee5.com/tokennd',
|
'x-access-token': access_token_request['token']
|
||||||
video_id, note='Downloading video token')
|
}
|
||||||
json_data = self._download_json(
|
if self._USER_TOKEN:
|
||||||
'https://gwapi.zee5.com/content/details/{}?translation=en&country=IN'.format(video_id),
|
data['Authorization'] = 'bearer %s' % self._USER_TOKEN
|
||||||
video_id, headers={'X-Access-Token': access_token_request['token']})
|
else:
|
||||||
m3u8_url = try_get(
|
data['X-Z5-Guest-Token'] = self._DEVICE_ID
|
||||||
json_data,
|
|
||||||
(lambda x: x['hls'][0], lambda x: x['video_details']['hls_url']),
|
|
||||||
compat_str)
|
|
||||||
formats = self._extract_m3u8_formats(
|
|
||||||
'https://zee5vodnd.akamaized.net' + m3u8_url.replace('/drm', '/hls', 1) + token_request['video_token'],
|
|
||||||
video_id, 'mp4', fatal=False)
|
|
||||||
mpd_url = try_get(
|
|
||||||
json_data,
|
|
||||||
(lambda x: x['video'][0], lambda x: x['video_details']['url']),
|
|
||||||
compat_str)
|
|
||||||
formats += self._extract_mpd_formats(
|
|
||||||
'https://zee5vod.akamaized.net' + mpd_url,
|
|
||||||
video_id, fatal=False)
|
|
||||||
|
|
||||||
|
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'))
|
||||||
|
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)
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
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)
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'display_id': display_id,
|
'display_id': display_id,
|
||||||
'title': json_data['title'],
|
'title': asset_data['title'],
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'duration': int_or_none(json_data.get('duration')),
|
'subtitles': subtitles,
|
||||||
'average_rating': int_or_none(json_data.get('rating')),
|
'duration': int_or_none(asset_data.get('duration')),
|
||||||
'description': str_or_none(json_data.get('description')),
|
'average_rating': int_or_none(asset_data.get('rating')),
|
||||||
'alt_title': str_or_none(json_data.get('original_title')),
|
'description': str_or_none(asset_data.get('description')),
|
||||||
'uploader': str_or_none(json_data.get('content_owner')),
|
'alt_title': str_or_none(asset_data.get('original_title')),
|
||||||
'age_limit': parse_age_limit(json_data.get('age_rating')),
|
'uploader': str_or_none(asset_data.get('content_owner')),
|
||||||
'release_date': unified_strdate(json_data.get('release_date')),
|
'age_limit': parse_age_limit(asset_data.get('age_rating')),
|
||||||
'timestamp': unified_timestamp(json_data.get('release_date')),
|
'release_date': unified_strdate(asset_data.get('release_date')),
|
||||||
'thumbnail': url_or_none(json_data.get('image_url')),
|
'timestamp': unified_timestamp(asset_data.get('release_date')),
|
||||||
'series': try_get(json_data, lambda x: x['tvshow_details']['title'], str),
|
'thumbnail': url_or_none(asset_data.get('image_url')),
|
||||||
'season': try_get(json_data, lambda x: x['season_details']['title'], str),
|
'series': str_or_none(asset_data.get('tvshow_name')),
|
||||||
'season_number': int_or_none(try_get(json_data, lambda x: x['season_details']['index'])),
|
'season': try_get(show_data, lambda x: x['seasons']['title'], str),
|
||||||
'episode_number': int_or_none(try_get(json_data, lambda x: x['index'])),
|
'season_number': int_or_none(try_get(show_data, lambda x: x['seasons'][0]['orderid'])),
|
||||||
'tags': try_get(json_data, lambda x: x['tags'], list)
|
'episode_number': int_or_none(try_get(asset_data, lambda x: x['orderid'])),
|
||||||
|
'tags': try_get(asset_data, lambda x: x['tags'], list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,7 +194,7 @@ class Zee5SeriesIE(InfoExtractor):
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.zee5.com/tvshows/details/agent-raghav-crime-branch/0-6-965',
|
'url': 'https://www.zee5.com/tvshows/details/agent-raghav-crime-branch/0-6-965',
|
||||||
'playlist_mincount': 25,
|
'playlist_mincount': 24,
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '0-6-965',
|
'id': '0-6-965',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue