From 3708fde3ef771e3b61e7421bf86bf67153c47bd6 Mon Sep 17 00:00:00 2001 From: jbannon Date: Sun, 14 Aug 2022 06:50:24 +0000 Subject: [PATCH] single working --- src/ytdl_sub/plugins/audio_extract.py | 19 +++++++++++++++++++ .../subscription_ytdl_options.py | 14 +++++++++++++- .../plugins/test_audio_extract_single.json | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_single.json diff --git a/src/ytdl_sub/plugins/audio_extract.py b/src/ytdl_sub/plugins/audio_extract.py index a5cd9c4f..c7e6c4fd 100644 --- a/src/ytdl_sub/plugins/audio_extract.py +++ b/src/ytdl_sub/plugins/audio_extract.py @@ -71,6 +71,11 @@ class AudioExtractPlugin(Plugin[AudioExtractOptions]): plugin_options_type = AudioExtractOptions def ytdl_options(self) -> Optional[Dict]: + """ + Returns + ------- + YTDL options for extracting audio + """ ytdl_options_builder = YTDLOptionsBuilder() postprocessor_dict = { @@ -88,11 +93,25 @@ class AudioExtractPlugin(Plugin[AudioExtractOptions]): ).to_dict() def modify_entry(self, entry: Entry) -> Optional[Entry]: + """ + Parameters + ---------- + entry + Entry with extracted audio + + Returns + ------- + Entry with updated 'ext' source variable + """ new_ext = CODEC_TYPES_EXTENSION_MAPPING[self.plugin_options.codec] extracted_audio_file = entry.get_download_file_path().removesuffix(entry.ext) + new_ext if not self.is_dry_run: if not os.path.isfile(extracted_audio_file): raise FileNotDownloadedException("Failed to find the extracted audio file") + # TODO: create entry function to update kwargs + # pylint: disable=protected-access entry._kwargs["ext"] = new_ext + # pylint: enable=protected-access + return entry diff --git a/src/ytdl_sub/subscriptions/subscription_ytdl_options.py b/src/ytdl_sub/subscriptions/subscription_ytdl_options.py index 22b83c02..e4dc95a3 100644 --- a/src/ytdl_sub/subscriptions/subscription_ytdl_options.py +++ b/src/ytdl_sub/subscriptions/subscription_ytdl_options.py @@ -8,6 +8,7 @@ from typing import TypeVar 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.plugins.audio_extract import AudioExtractPlugin from ytdl_sub.plugins.plugin import Plugin from ytdl_sub.plugins.subtitles import SubtitleOptions from ytdl_sub.plugins.subtitles import SubtitlesPlugin @@ -81,6 +82,13 @@ class SubscriptionYTDLOptions: return ytdl_options + @property + def _audio_extract_options(self) -> Dict: + if not (audio_extract_plugin := self._get_plugin(AudioExtractPlugin)): + return {} + + return audio_extract_plugin.ytdl_options() + @property def _subtitle_options(self) -> Dict: if not (subtitle_plugin := self._get_plugin(SubtitlesPlugin)): @@ -90,6 +98,7 @@ class SubscriptionYTDLOptions: # TODO: warn here return {} + # TODO: Use subtitle ytdl_options builder = YTDLOptionsBuilder().add({"writesubtitles": True}) subtitle_options: SubtitleOptions = subtitle_plugin.plugin_options @@ -141,7 +150,10 @@ class SubscriptionYTDLOptions: ) else: ytdl_options_builder.add( - self._output_options, self._subtitle_options, self._user_ytdl_options + self._output_options, + self._subtitle_options, + self._audio_extract_options, + self._user_ytdl_options, ) return ytdl_options_builder diff --git a/tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_single.json b/tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_single.json new file mode 100644 index 00000000..0efc1e08 --- /dev/null +++ b/tests/e2e/resources/expected_downloads_summaries/plugins/test_audio_extract_single.json @@ -0,0 +1,3 @@ +{ + "YouTube Rewind 2019: For the Record | #YouTubeRewind.mp3": "2b44b454ecc58f3600731a44e0c61f1b" +} \ No newline at end of file