From 9f5ee153b779a8c1017272b8e146ce1dd12969c1 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sat, 26 Nov 2022 23:44:40 -0800 Subject: [PATCH] [BACKEND] Add URL thumbnail download timeout (#367) --- src/ytdl_sub/downloaders/downloader.py | 4 ++-- src/ytdl_sub/utils/thumbnail.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ytdl_sub/downloaders/downloader.py b/src/ytdl_sub/downloaders/downloader.py index c0c040c3..87b07f33 100644 --- a/src/ytdl_sub/downloaders/downloader.py +++ b/src/ytdl_sub/downloaders/downloader.py @@ -646,7 +646,7 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT], ABC): continue if (thumbnail_url := parent.get_thumbnail_url(thumbnail_id=thumbnail_id)) is None: - download_logger.warning("TODO: Failed to download channel's avatar image") + download_logger.warning("Failed to find thumbnail id '%s'", thumbnail_id) continue if self._download_thumbnail( @@ -656,7 +656,7 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT], ABC): self.save_file(file_name=thumbnail_name) thumbnails_downloaded.add(thumbnail_name) else: - download_logger.warning("TODO: Failed to download channel's avatar image") + download_logger.warning("Failed to download thumbnail id '%s'", thumbnail_id) return thumbnails_downloaded diff --git a/src/ytdl_sub/utils/thumbnail.py b/src/ytdl_sub/utils/thumbnail.py index 0507a52d..25a4b9f5 100644 --- a/src/ytdl_sub/utils/thumbnail.py +++ b/src/ytdl_sub/utils/thumbnail.py @@ -60,7 +60,8 @@ def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> Opt ------- True to indicate it converted the thumbnail from url. None if the retry failed. """ - with urlopen(thumbnail_url) as file: + # timeout after 8 seconds + with urlopen(thumbnail_url, timeout=8.0) as file: with tempfile.NamedTemporaryFile() as thumbnail: thumbnail.write(file.read())