1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-26 02:14:32 +01:00

[viu:ott] optimize try and error logic

This commit is contained in:
lkho 2020-10-23 23:05:11 +08:00
parent 9960d74039
commit 2290860e1f

View File

@ -243,8 +243,7 @@ class ViuOTTIE(InfoExtractor):
'password': password, 'password': password,
'platform_flag_label': 'web', 'platform_flag_label': 'web',
}).encode()) }).encode())
data = self._detect_error(data) self._user_info = self._detect_error(data)['user']
self._user_info = data['user']
return self._user_info return self._user_info
@ -278,36 +277,33 @@ class ViuOTTIE(InfoExtractor):
'Referer': re.search(r'https?://[^/]+', url).group(0), 'Referer': re.search(r'https?://[^/]+', url).group(0),
'Origin': re.search(r'https?://[^/]+', url).group(0), 'Origin': re.search(r'https?://[^/]+', url).group(0),
} }
try:
stream_data = self._download_json( def _try_download_stream_data():
temp1 = self._download_json(
'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code, 'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code,
video_id, 'Downloading stream info', query=query, headers=headers) video_id, 'Downloading stream info', query=query, headers=headers)
stream_data = self._detect_error(stream_data)['stream'] return self._detect_error(temp1).get('stream')
except (ExtractorError, KeyError):
stream_data = None stream_data = None
try:
stream_data = _try_download_stream_data()
except (ExtractorError, KeyError):
if video_data.get('user_level', 0) > 0: if video_data.get('user_level', 0) > 0:
user = self._login(country_code, video_id) user = self._login(country_code, video_id)
if user: if user:
query['identity'] = user['identity'] query['identity'] = user['identity']
stream_data = self._download_json(
'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code,
video_id, 'Downloading stream info', query=query, headers=headers)
stream_data = self._detect_error(stream_data).get('stream')
else: else:
# preview is limited to 3min for non-members # preview is limited to 3min for non-members
# try to bypass the duration limit # try to bypass the duration limit
duration_limit = True duration_limit = True
query['duration'] = '180' query['duration'] = '180'
stream_data = self._download_json( stream_data = _try_download_stream_data()
'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code,
video_id, 'Downloading stream info', query=query, headers=headers)
try:
stream_data = self._detect_error(stream_data)['stream']
except (ExtractorError, KeyError):
# if still not working, give up
self._raise_login_required()
if not stream_data: if not stream_data:
if duration_limit:
# raise login required message if we have tried with the duration hack
self._raise_login_required()
else:
raise ExtractorError('Cannot get stream info', expected=True) raise ExtractorError('Cannot get stream info', expected=True)
stream_sizes = stream_data.get('size', {}) stream_sizes = stream_data.get('size', {})