From c1aa97312090007b1e915fa09d15a2d1d1f2f298 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sun, 17 Jul 2022 23:12:46 -0700 Subject: [PATCH] [BACKEND] Avoid thumbnail downloads when possible (#105) --- src/ytdl_sub/downloaders/downloader.py | 2 +- .../downloaders/soundcloud/albums_and_singles.py | 9 ++++++++- src/ytdl_sub/downloaders/youtube/channel.py | 2 ++ src/ytdl_sub/downloaders/youtube/playlist.py | 2 ++ src/ytdl_sub/subscriptions/subscription.py | 14 +++++++++++--- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/ytdl_sub/downloaders/downloader.py b/src/ytdl_sub/downloaders/downloader.py index add6339b..a7f2f0a0 100644 --- a/src/ytdl_sub/downloaders/downloader.py +++ b/src/ytdl_sub/downloaders/downloader.py @@ -54,7 +54,7 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT] @classmethod def ytdl_option_overrides(cls) -> Dict: """Global overrides that even overwrite user input""" - return {"writethumbnail": True, "noplaylist": True} + return {} @classmethod def ytdl_option_defaults(cls) -> Dict: diff --git a/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py b/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py index 85cb28f6..75c94cb1 100644 --- a/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py +++ b/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py @@ -120,7 +120,14 @@ class SoundcloudAlbumsAndSinglesDownloader( artist_albums_url = self.artist_albums_url(artist_url=self.download_options.url) artist_tracks_url = self.artist_tracks_url(artist_url=self.download_options.url) - album_entry_dicts = self.extract_info_via_info_json(url=artist_albums_url) + # Albums do not need to download anything since tracks contain all album tracks + album_entry_dicts = self.extract_info_via_info_json( + ytdl_options_overrides={ + "skip_download": True, + "writethumbnail": False, + }, + url=artist_albums_url, + ) tracks_entry_dicts = self.extract_info_via_info_json(url=artist_tracks_url) # Get all of the artist's albums diff --git a/src/ytdl_sub/downloaders/youtube/channel.py b/src/ytdl_sub/downloaders/youtube/channel.py index 1157e6a9..7525c8d1 100644 --- a/src/ytdl_sub/downloaders/youtube/channel.py +++ b/src/ytdl_sub/downloaders/youtube/channel.py @@ -159,6 +159,7 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions # videos that will be downloaded. Afterwards, download each video one-by-one if self.download_options.download_individually: ytdl_options_overrides["skip_download"] = True + ytdl_options_overrides["writethumbnail"] = False # If a date range is specified when download a YT channel, add it into the ytdl options source_date_range = self.download_options.get_date_range() @@ -173,6 +174,7 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions # If downloading individually, remove the skip_download to actually download the video if self.download_options.download_individually: del ytdl_options_overrides["skip_download"] + del ytdl_options_overrides["writethumbnail"] for entry_dict in entry_dicts: if entry_dict.get("extractor") == "youtube": diff --git a/src/ytdl_sub/downloaders/youtube/playlist.py b/src/ytdl_sub/downloaders/youtube/playlist.py index 7dd3041f..e36f5869 100644 --- a/src/ytdl_sub/downloaders/youtube/playlist.py +++ b/src/ytdl_sub/downloaders/youtube/playlist.py @@ -92,6 +92,7 @@ class YoutubePlaylistDownloader( # videos that will be downloaded. Afterwards, download each video one-by-one if self.download_options.download_individually: ytdl_options_overrides["skip_download"] = True + ytdl_options_overrides["writethumbnail"] = False entry_dicts = self.extract_info_via_info_json( ytdl_options_overrides=ytdl_options_overrides, url=self.download_options.playlist_url @@ -100,6 +101,7 @@ class YoutubePlaylistDownloader( # If downloading individually, remove the skip_download to actually download the video if self.download_options.download_individually: del ytdl_options_overrides["skip_download"] + del ytdl_options_overrides["writethumbnail"] for entry_dict in entry_dicts: if entry_dict.get("extractor") == "youtube": diff --git a/src/ytdl_sub/subscriptions/subscription.py b/src/ytdl_sub/subscriptions/subscription.py index b171ed20..eea59c0f 100644 --- a/src/ytdl_sub/subscriptions/subscription.py +++ b/src/ytdl_sub/subscriptions/subscription.py @@ -149,7 +149,10 @@ class Subscription: ) def _move_entry_files_to_output_directory( - self, entry: Entry, entry_metadata: Optional[FileMetadata] = None + self, + dry_run: bool, + entry: Entry, + entry_metadata: Optional[FileMetadata] = None, ): """ Helper function to move the media file and optionally thumbnail file to the output directory @@ -157,6 +160,8 @@ class Subscription: Parameters ---------- + dry_run + Whether this session is a dry-run or not entry: The entry with files to move entry_metadata @@ -179,7 +184,8 @@ class Subscription: ) # We always convert entry thumbnails to jpgs, and is performed here - convert_download_thumbnail(entry=entry) + if not dry_run: + convert_download_thumbnail(entry=entry) self._enhanced_download_archive.save_file_to_output_directory( file_name=entry.get_download_thumbnail_name(), @@ -252,8 +258,10 @@ class Subscription: # TODO: Move this logic to separate function # TODO: set id here as well ytdl_options = copy.deepcopy(self.ytdl_options.dict) + ytdl_options["writethumbnail"] = True if dry_run: ytdl_options["skip_download"] = True + ytdl_options["writethumbnail"] = False if self.downloader_class.supports_download_archive and self.maintain_download_archive: ytdl_options["download_archive"] = str( Path(self.working_directory) / self._enhanced_download_archive.archive_file_name @@ -289,7 +297,7 @@ class Subscription: entry_metadata.extend(optional_plugin_entry_metadata) self._move_entry_files_to_output_directory( - entry=entry, entry_metadata=entry_metadata + dry_run=dry_run, entry=entry, entry_metadata=entry_metadata ) # Re-save the download archive after each entry is moved to the output directory