mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-11-02 15:45:18 +00:00
[utils] Add try_call
This commit is contained in:
@@ -14,6 +14,7 @@ from ..utils import (
|
||||
float_or_none,
|
||||
mimetype2ext,
|
||||
str_or_none,
|
||||
try_call,
|
||||
try_get,
|
||||
unescapeHTML,
|
||||
unsmuggle_url,
|
||||
@@ -145,11 +146,11 @@ class MediasiteIE(InfoExtractor):
|
||||
'duration': slide['Time'] / 1000,
|
||||
})
|
||||
|
||||
next_time = try_get(None, [
|
||||
lambda _: Stream['Slides'][i + 1]['Time'],
|
||||
lambda _: duration,
|
||||
lambda _: slide['Time'],
|
||||
], expected_type=(int, float))
|
||||
next_time = try_call(
|
||||
lambda: Stream['Slides'][i + 1]['Time'],
|
||||
lambda: duration,
|
||||
lambda: slide['Time'],
|
||||
expected_type=(int, float))
|
||||
|
||||
fragments.append({
|
||||
'path': fname_template.format(slide.get('Number', i + 1)),
|
||||
|
||||
@@ -5,6 +5,7 @@ from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
int_or_none,
|
||||
qualities,
|
||||
try_call,
|
||||
try_get,
|
||||
ExtractorError,
|
||||
)
|
||||
@@ -26,10 +27,10 @@ class WhoWatchIE(InfoExtractor):
|
||||
metadata = self._download_json('https://api.whowatch.tv/lives/%s' % video_id, video_id)
|
||||
live_data = self._download_json('https://api.whowatch.tv/lives/%s/play' % video_id, video_id)
|
||||
|
||||
title = try_get(None, (
|
||||
lambda x: live_data['share_info']['live_title'][1:-1],
|
||||
lambda x: metadata['live']['title'],
|
||||
), compat_str)
|
||||
title = try_call(
|
||||
lambda: live_data['share_info']['live_title'][1:-1],
|
||||
lambda: metadata['live']['title'],
|
||||
expected_type=str)
|
||||
|
||||
hls_url = live_data.get('hls_url')
|
||||
if not hls_url:
|
||||
|
||||
Reference in New Issue
Block a user