single working

This commit is contained in:
jbannon 2022-08-14 06:50:24 +00:00
parent 8538887029
commit 3708fde3ef
3 changed files with 35 additions and 1 deletions

View file

@ -71,6 +71,11 @@ class AudioExtractPlugin(Plugin[AudioExtractOptions]):
plugin_options_type = AudioExtractOptions plugin_options_type = AudioExtractOptions
def ytdl_options(self) -> Optional[Dict]: def ytdl_options(self) -> Optional[Dict]:
"""
Returns
-------
YTDL options for extracting audio
"""
ytdl_options_builder = YTDLOptionsBuilder() ytdl_options_builder = YTDLOptionsBuilder()
postprocessor_dict = { postprocessor_dict = {
@ -88,11 +93,25 @@ class AudioExtractPlugin(Plugin[AudioExtractOptions]):
).to_dict() ).to_dict()
def modify_entry(self, entry: Entry) -> Optional[Entry]: 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] new_ext = CODEC_TYPES_EXTENSION_MAPPING[self.plugin_options.codec]
extracted_audio_file = entry.get_download_file_path().removesuffix(entry.ext) + new_ext extracted_audio_file = entry.get_download_file_path().removesuffix(entry.ext) + new_ext
if not self.is_dry_run: if not self.is_dry_run:
if not os.path.isfile(extracted_audio_file): if not os.path.isfile(extracted_audio_file):
raise FileNotDownloadedException("Failed to find the 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 entry._kwargs["ext"] = new_ext
# pylint: enable=protected-access
return entry return entry

View file

@ -8,6 +8,7 @@ from typing import TypeVar
from ytdl_sub.config.preset import Preset from ytdl_sub.config.preset import Preset
from ytdl_sub.downloaders.downloader import Downloader from ytdl_sub.downloaders.downloader import Downloader
from ytdl_sub.downloaders.ytdl_options_builder import YTDLOptionsBuilder 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.plugin import Plugin
from ytdl_sub.plugins.subtitles import SubtitleOptions from ytdl_sub.plugins.subtitles import SubtitleOptions
from ytdl_sub.plugins.subtitles import SubtitlesPlugin from ytdl_sub.plugins.subtitles import SubtitlesPlugin
@ -81,6 +82,13 @@ class SubscriptionYTDLOptions:
return ytdl_options 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 @property
def _subtitle_options(self) -> Dict: def _subtitle_options(self) -> Dict:
if not (subtitle_plugin := self._get_plugin(SubtitlesPlugin)): if not (subtitle_plugin := self._get_plugin(SubtitlesPlugin)):
@ -90,6 +98,7 @@ class SubscriptionYTDLOptions:
# TODO: warn here # TODO: warn here
return {} return {}
# TODO: Use subtitle ytdl_options
builder = YTDLOptionsBuilder().add({"writesubtitles": True}) builder = YTDLOptionsBuilder().add({"writesubtitles": True})
subtitle_options: SubtitleOptions = subtitle_plugin.plugin_options subtitle_options: SubtitleOptions = subtitle_plugin.plugin_options
@ -141,7 +150,10 @@ class SubscriptionYTDLOptions:
) )
else: else:
ytdl_options_builder.add( 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 return ytdl_options_builder

View file

@ -0,0 +1,3 @@
{
"YouTube Rewind 2019 For the Record #YouTubeRewind.mp3": "2b44b454ecc58f3600731a44e0c61f1b"
}