From baae5ff72db1c1561df43cc446e09e9aaba96cf6 Mon Sep 17 00:00:00 2001 From: jbannon Date: Wed, 10 Aug 2022 23:52:32 +0000 Subject: [PATCH] subtitles almost ready --- src/ytdl_sub/downloaders/downloader.py | 1 + .../downloaders/soundcloud/albums_and_singles.py | 1 + src/ytdl_sub/downloaders/youtube/merge_playlist.py | 1 + src/ytdl_sub/downloaders/youtube/split_video.py | 3 +++ src/ytdl_sub/subscriptions/subscription.py | 3 +-- .../subscriptions/subscription_ytdl_options.py | 11 ++++++++++- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ytdl_sub/downloaders/downloader.py b/src/ytdl_sub/downloaders/downloader.py index 7fb7545a..22e83dc7 100644 --- a/src/ytdl_sub/downloaders/downloader.py +++ b/src/ytdl_sub/downloaders/downloader.py @@ -56,6 +56,7 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT] downloader_entry_type: Type[Entry] = Entry supports_download_archive: bool = True + supports_subtitles: bool = True _extract_entry_num_retries: int = 5 _extract_entry_retry_wait_sec: int = 3 diff --git a/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py b/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py index e5e9f760..a2ad1720 100644 --- a/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py +++ b/src/ytdl_sub/downloaders/soundcloud/albums_and_singles.py @@ -51,6 +51,7 @@ class SoundcloudAlbumsAndSinglesDownloader( SoundcloudDownloader[SoundcloudAlbumsAndSinglesDownloadOptions] ): downloader_options_type = SoundcloudAlbumsAndSinglesDownloadOptions + supports_subtitles = False @classmethod def ytdl_option_defaults(cls) -> Dict: diff --git a/src/ytdl_sub/downloaders/youtube/merge_playlist.py b/src/ytdl_sub/downloaders/youtube/merge_playlist.py index e585a1fc..e71adf04 100644 --- a/src/ytdl_sub/downloaders/youtube/merge_playlist.py +++ b/src/ytdl_sub/downloaders/youtube/merge_playlist.py @@ -64,6 +64,7 @@ class YoutubeMergePlaylistDownloader( downloader_options_type = YoutubeMergePlaylistDownloaderOptions downloader_entry_type = YoutubeVideo supports_download_archive = False + supports_subtitles = False @classmethod def ytdl_option_defaults(cls) -> Dict: diff --git a/src/ytdl_sub/downloaders/youtube/split_video.py b/src/ytdl_sub/downloaders/youtube/split_video.py index c113af63..a7059c74 100644 --- a/src/ytdl_sub/downloaders/youtube/split_video.py +++ b/src/ytdl_sub/downloaders/youtube/split_video.py @@ -107,6 +107,9 @@ class YoutubeSplitVideoDownloader( downloader_options_type = YoutubeSplitVideoDownloaderOptions downloader_entry_type = YoutubePlaylistVideo + supports_download_archive = False + supports_subtitles = False + @classmethod def ytdl_option_defaults(cls) -> Dict: """ diff --git a/src/ytdl_sub/subscriptions/subscription.py b/src/ytdl_sub/subscriptions/subscription.py index 2e69a850..5941916f 100644 --- a/src/ytdl_sub/subscriptions/subscription.py +++ b/src/ytdl_sub/subscriptions/subscription.py @@ -204,8 +204,7 @@ class Subscription: entry=entry, ) - # # TODO: see if entry even has subtitles - # if self.output_options.subtitles_name and ( + # if self.downloader_class.supports_subtitles and self.subtitle_options.subtitles_name and ( # entry.kwargs_contains("subtitles") or entry.kwargs_contains("automatic_captions") # ): # output_subtitles_name = self.overrides.apply_formatter( diff --git a/src/ytdl_sub/subscriptions/subscription_ytdl_options.py b/src/ytdl_sub/subscriptions/subscription_ytdl_options.py index ff1f4433..46360d93 100644 --- a/src/ytdl_sub/subscriptions/subscription_ytdl_options.py +++ b/src/ytdl_sub/subscriptions/subscription_ytdl_options.py @@ -1,7 +1,9 @@ from pathlib import Path from typing import Dict +from typing import Type from ytdl_sub.config.preset import Preset +from ytdl_sub.downloaders.downloader import Downloader from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder from ytdl_sub.ytdl_additions.enhanced_download_archive import EnhancedDownloadArchive @@ -19,6 +21,10 @@ class SubscriptionYTDLOptions: self._working_directory = working_directory self._dry_run = dry_run + @property + def _downloader(self) -> Type[Downloader]: + return self._preset.downloader + @property def _global_options(self) -> Dict: """ @@ -32,7 +38,7 @@ class SubscriptionYTDLOptions: } if ( - self._preset.downloader.supports_download_archive + self._downloader.supports_download_archive and self._preset.output_options.maintain_download_archive ): ytdl_options["download_archive"] = str( @@ -61,6 +67,9 @@ class SubscriptionYTDLOptions: @property def _subtitle_options(self) -> Dict: + if not self._downloader.supports_subtitles: + return {} + ytdl_options: Dict = {} subtitle_options = self._preset.subtitle_options