diff --git a/src/ytdl_sub/downloaders/youtube/channel.py b/src/ytdl_sub/downloaders/youtube/channel.py index c697f78c..4a369cc8 100644 --- a/src/ytdl_sub/downloaders/youtube/channel.py +++ b/src/ytdl_sub/downloaders/youtube/channel.py @@ -228,7 +228,7 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions self, thumbnail_url: str, output_thumbnail_path: str, - ): + ) -> Optional[bool]: """ Downloads a thumbnail and stores it in the output directory @@ -238,12 +238,16 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions Url of the thumbnail output_thumbnail_path: Path to store the thumbnail after downloading + + Returns + ------- + True if the thumbnail converted. None if it is missing or failed. """ if not thumbnail_url: download_logger.warning("Could not find a thumbnail for %s", self.channel.uid) - return + return None - convert_url_thumbnail( + return convert_url_thumbnail( thumbnail_url=thumbnail_url, output_thumbnail_path=output_thumbnail_path ) diff --git a/src/ytdl_sub/utils/thumbnail.py b/src/ytdl_sub/utils/thumbnail.py index 4e5aaabb..834203c8 100644 --- a/src/ytdl_sub/utils/thumbnail.py +++ b/src/ytdl_sub/utils/thumbnail.py @@ -1,4 +1,5 @@ import tempfile +from typing import Optional from urllib.request import urlopen from ytdl_sub.entries.entry import Entry @@ -34,7 +35,7 @@ def convert_download_thumbnail(entry: Entry, error_if_not_found: bool = True) -> @retry(times=5, exceptions=(Exception,)) -def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> bool: +def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> Optional[bool]: """ Downloads and converts a thumbnail from a url into a jpg @@ -47,7 +48,7 @@ def convert_url_thumbnail(thumbnail_url: str, output_thumbnail_path: str) -> boo Returns ------- - True to indicate it converted the thumbnail from url + True to indicate it converted the thumbnail from url. None if the retry failed. """ with urlopen(thumbnail_url) as file: with tempfile.NamedTemporaryFile() as thumbnail: diff --git a/tests/e2e/youtube/test_channel.py b/tests/e2e/youtube/test_channel.py index f6b21a4a..1b43a53f 100644 --- a/tests/e2e/youtube/test_channel.py +++ b/tests/e2e/youtube/test_channel.py @@ -70,12 +70,13 @@ class TestChannelAsKodiTvShow: config=channel_as_tv_show_config, preset_name="pz", preset_dict=channel_preset_dict ) - with assert_debug_log( + with assert_debug_log( # Ensure retry debug message is thrown logger=retry_logger, - expected_message="Exception thrown when attempting to run convert_url_thumbnail, attempt 5 of 5", - ), patch("ytdl_sub.utils.retry.sleep"), patch( + expected_message="Exception thrown when attempting to run %s, attempt %d of %d", + ), patch( # Make sleeps instant + "ytdl_sub.utils.retry.sleep" + ), patch( # Mock error when calling urlopen "ytdl_sub.utils.thumbnail.urlopen" ) as mock_urlopen: mock_urlopen.side_effect = [Exception("error")] - full_channel_subscription.download(dry_run=True)