From 333e92b1e5a07fd1000ad863db7e4f155474ad8e Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 18 Apr 2024 19:02:59 +0200 Subject: [PATCH] [extractor/echo360] use traverse_obj with lambda and parse_duration --- yt_dlp/extractor/echo360.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/yt_dlp/extractor/echo360.py b/yt_dlp/extractor/echo360.py index 893c5cfb96..40d8c1ed69 100644 --- a/yt_dlp/extractor/echo360.py +++ b/yt_dlp/extractor/echo360.py @@ -1,7 +1,13 @@ import re from .common import InfoExtractor -from ..utils import determine_ext, float_or_none, traverse_obj, update_url +from ..utils import ( + determine_ext, + float_or_none, + parse_duration, + traverse_obj, + update_url, +) class Echo360IE(InfoExtractor): @@ -50,19 +56,14 @@ def _get_query_string(self, uri, query_strings): def _parse_mediapackage(self, video): video_id = video['playableAudioVideo']['mediaId'] - query_strings = traverse_obj(video, ('sourceQueryStrings', 'queryStrings')) or [] + query_strings = traverse_obj(video, ('sourceQueryStrings', 'queryStrings', ...)) formats = [] - for track in traverse_obj(video, ('playableAudioVideo', 'playableMedias', ...)): - href = track.get('uri') - if href is None: - continue - href = update_url(href, query=self._get_query_string(href, query_strings)) - if track.get('isHls') or determine_ext(href, None) == 'm3u8': + for track in traverse_obj(video, ('playableAudioVideo', 'playableMedias', lambda _, v: v['uri'])): + href = update_url(track['uri'], query=self._get_query_string(track['uri'], query_strings)) + if track.get('isHls') or determine_ext(href) == 'm3u8': hls_formats = self._extract_m3u8_formats( - href, video_id, live=track.get('isLive'), m3u8_id='hls', - entry_protocol='m3u8_native', fatal=False - ) + href, video_id, live=track.get('isLive'), m3u8_id='hls', fatal=False) for hls_format in hls_formats: query_string = self._get_query_string(hls_format['url'], query_strings) @@ -75,9 +76,7 @@ def _parse_mediapackage(self, video): 'id': video_id, 'formats': formats, 'title': video.get('mediaName'), - 'duration': float_or_none(self._search_regex( - r'PT([\d.]+)S', traverse_obj(video, ('playableAudioVideo', 'duration')), - 'video duration', fatal=False)), + 'duration': traverse_obj(video, ('playableAudioVideo', 'duration', {parse_duration})), } def _real_extract(self, url):