From 561468b8bd95d06b8341a1111dcb6a4db7b2255d Mon Sep 17 00:00:00 2001 From: Jordan Shatford <jordanshatford@live.com> Date: Thu, 9 Nov 2023 13:11:35 +1100 Subject: [PATCH] fix(core): use ??? if duration cannot be found in search results Signed-off-by: Jordan Shatford <jordanshatford@live.com> --- core/ydcore/search.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/ydcore/search.py b/core/ydcore/search.py index f99cbd5a..1b6511dd 100644 --- a/core/ydcore/search.py +++ b/core/ydcore/search.py @@ -123,7 +123,11 @@ def _parse_video(self, source: dict[Any, Any]) -> Video: video_id = source['videoId'] url = HttpUrl(f'{_YOUTUBE_BASE_URL}/watch?v={video_id}') title = _get(source, ['title', 'runs', 0, 'text']) - duration = _get(source, ['lengthText', 'simpleText']) + duration = '???' + try: + duration = _get(source, ['lengthText', 'simpleText']) + except KeyError: + pass if duration is None: duration = '--:--' thumbnails = _get(source, ['thumbnail', 'thumbnails'])