[BACKEND] Avoid thumbnail downloads when possible (#105)
This commit is contained in:
parent
f66596d1a7
commit
c1aa973120
5 changed files with 24 additions and 5 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue