output using last entry
This commit is contained in:
parent
030974c074
commit
34a9541d19
6 changed files with 34 additions and 38 deletions
|
|
@ -74,7 +74,7 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
|
||||||
Shared code between NFO tags and Ouptut Directory NFO Tags
|
Shared code between NFO tags and Ouptut Directory NFO Tags
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_xml_element_dict(self, entry: Optional[Entry]) -> Dict[str, List[XmlElement]]:
|
def _get_xml_element_dict(self, entry: Entry) -> Dict[str, List[XmlElement]]:
|
||||||
nfo_tags: Dict[str, List[XmlElement]] = defaultdict(list)
|
nfo_tags: Dict[str, List[XmlElement]] = defaultdict(list)
|
||||||
|
|
||||||
for key, string_tags in self.plugin_options.tags.string_tags.items():
|
for key, string_tags in self.plugin_options.tags.string_tags.items():
|
||||||
|
|
@ -102,7 +102,7 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
|
||||||
|
|
||||||
return nfo_tags
|
return nfo_tags
|
||||||
|
|
||||||
def _create_nfo(self, entry: Optional[Entry] = None) -> None:
|
def _create_nfo(self, entry: Entry, save_to_entry: bool = True) -> None:
|
||||||
# Write the nfo tags to XML with the nfo_root
|
# Write the nfo tags to XML with the nfo_root
|
||||||
nfo_root = self.overrides.apply_formatter(
|
nfo_root = self.overrides.apply_formatter(
|
||||||
formatter=self.plugin_options.nfo_root, entry=entry
|
formatter=self.plugin_options.nfo_root, entry=entry
|
||||||
|
|
@ -148,7 +148,11 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
|
||||||
},
|
},
|
||||||
title="NFO tags",
|
title="NFO tags",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if save_to_entry:
|
||||||
self.save_file(file_name=nfo_file_name, file_metadata=nfo_metadata, entry=entry)
|
self.save_file(file_name=nfo_file_name, file_metadata=nfo_metadata, entry=entry)
|
||||||
|
else:
|
||||||
|
self.save_file(file_name=nfo_file_name, file_metadata=nfo_metadata)
|
||||||
|
|
||||||
|
|
||||||
class NfoTagsOptions(SharedNfoTagsOptions):
|
class NfoTagsOptions(SharedNfoTagsOptions):
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,19 @@
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from ytdl_sub.config.preset_options import Overrides
|
||||||
|
from ytdl_sub.entries.entry import Entry
|
||||||
from ytdl_sub.plugins.nfo_tags import NfoTagsValidator
|
from ytdl_sub.plugins.nfo_tags import NfoTagsValidator
|
||||||
from ytdl_sub.plugins.nfo_tags import SharedNfoTagsOptions
|
from ytdl_sub.plugins.nfo_tags import SharedNfoTagsOptions
|
||||||
from ytdl_sub.plugins.nfo_tags import SharedNfoTagsPlugin
|
from ytdl_sub.plugins.nfo_tags import SharedNfoTagsPlugin
|
||||||
from ytdl_sub.validators.string_formatter_validators import StringFormatterValidator
|
from ytdl_sub.validators.string_formatter_validators import StringFormatterValidator
|
||||||
|
from ytdl_sub.ytdl_additions.enhanced_download_archive import EnhancedDownloadArchive
|
||||||
|
|
||||||
|
|
||||||
class OutputDirectoryNfoTagsOptions(SharedNfoTagsOptions):
|
class OutputDirectoryNfoTagsOptions(SharedNfoTagsOptions):
|
||||||
"""
|
"""
|
||||||
Adds a single NFO file in the output directory. An NFO file is simply an XML file with a
|
Adds a single NFO file in the output directory. An NFO file is simply an XML file with a
|
||||||
``.nfo`` extension. You can add any strings or override variables into this NFO.
|
``.nfo`` extension. It uses the last entry's source variables which can change per download
|
||||||
|
invocation. Be cautious of which variables you use.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
|
|
@ -77,8 +83,24 @@ class OutputDirectoryNfoTagsOptions(SharedNfoTagsOptions):
|
||||||
class OutputDirectoryNfoTagsPlugin(SharedNfoTagsPlugin):
|
class OutputDirectoryNfoTagsPlugin(SharedNfoTagsPlugin):
|
||||||
plugin_options_type = OutputDirectoryNfoTagsOptions
|
plugin_options_type = OutputDirectoryNfoTagsOptions
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
plugin_options: OutputDirectoryNfoTagsOptions,
|
||||||
|
overrides: Overrides,
|
||||||
|
enhanced_download_archive: EnhancedDownloadArchive,
|
||||||
|
):
|
||||||
|
super().__init__(plugin_options, overrides, enhanced_download_archive)
|
||||||
|
self._last_entry: Optional[Entry] = None
|
||||||
|
|
||||||
|
def post_process_entry(self, entry: Entry) -> None:
|
||||||
|
"""
|
||||||
|
Tracks the last entry processed
|
||||||
|
"""
|
||||||
|
self._last_entry = entry
|
||||||
|
|
||||||
def post_process_subscription(self):
|
def post_process_subscription(self):
|
||||||
"""
|
"""
|
||||||
Creates an NFO file in the root of the output directory
|
Creates an NFO file in the root of the output directory using the last entry
|
||||||
"""
|
"""
|
||||||
self._create_nfo()
|
if self._last_entry:
|
||||||
|
self._create_nfo(entry=self._last_entry, save_to_entry=False)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from typing import Type
|
from typing import Type
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
from typing import final
|
|
||||||
|
|
||||||
from ytdl_sub.config.preset_options import AddsVariablesMixin
|
from ytdl_sub.config.preset_options import AddsVariablesMixin
|
||||||
from ytdl_sub.config.preset_options import Overrides
|
from ytdl_sub.config.preset_options import Overrides
|
||||||
|
|
@ -60,7 +59,6 @@ class Plugin(DownloadArchiver, Generic[PluginOptionsT], ABC):
|
||||||
# If the plugin creates multile entries from a single entry
|
# If the plugin creates multile entries from a single entry
|
||||||
is_split_plugin: bool = False
|
is_split_plugin: bool = False
|
||||||
|
|
||||||
@final
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
plugin_options: PluginOptionsT,
|
plugin_options: PluginOptionsT,
|
||||||
|
|
|
||||||
|
|
@ -83,30 +83,3 @@ class TestNfoTagsPlugins:
|
||||||
transaction_log=transaction_log,
|
transaction_log=transaction_log,
|
||||||
transaction_log_summary_file_name=f"plugins/nfo_tags/{transaction_log_file_name}",
|
transaction_log_summary_file_name=f"plugins/nfo_tags/{transaction_log_file_name}",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_source_variable_in_output_directory_nfo_tags_errors(
|
|
||||||
self, subscription_dict, music_video_config
|
|
||||||
):
|
|
||||||
subscription_dict["output_directory_nfo_tags"]["tags"]["kodi_safe_title_with_attrs"][
|
|
||||||
"attributes"
|
|
||||||
]["tag"] = "{title}"
|
|
||||||
with pytest.raises(ValidationException):
|
|
||||||
Subscription.from_dict(
|
|
||||||
config=music_video_config,
|
|
||||||
preset_name="kodi_safe_xml",
|
|
||||||
preset_dict=subscription_dict,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_source_variable_in_output_directory_nfo_tags_list_errors(
|
|
||||||
self, subscription_dict, music_video_config
|
|
||||||
):
|
|
||||||
subscription_dict["output_directory_nfo_tags"]["tags"]["kodi_safe_title_with_attrs"] = [
|
|
||||||
"okay value",
|
|
||||||
"not okay {title}",
|
|
||||||
]
|
|
||||||
with pytest.raises(ValidationException):
|
|
||||||
Subscription.from_dict(
|
|
||||||
config=music_video_config,
|
|
||||||
preset_name="kodi_safe_xml",
|
|
||||||
preset_dict=subscription_dict,
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
".ytdl-sub-recent-download-archive.json": "99914b932bd37a50b983c5e7c90ae93b",
|
".ytdl-sub-recent-download-archive.json": "99914b932bd37a50b983c5e7c90ae93b",
|
||||||
"fanart.jpg": "129c6639b47299bc48062f0365e670ee",
|
"fanart.jpg": "129c6639b47299bc48062f0365e670ee",
|
||||||
"poster.jpg": "5de28eea5a921a041452ab3ce1041f73",
|
"poster.jpg": "5de28eea5a921a041452ab3ce1041f73"
|
||||||
"tvshow.nfo": "c1c888ff6691f36328d1fb9d8c43adff"
|
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +230,7 @@ class TestPreset:
|
||||||
):
|
):
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
StringFormattingVariableNotFoundException,
|
StringFormattingVariableNotFoundException,
|
||||||
match="Override variable 'dne_var' does not exist",
|
match="Format variable 'dne_var' does not exist",
|
||||||
):
|
):
|
||||||
_ = Preset(
|
_ = Preset(
|
||||||
config=config_file,
|
config=config_file,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue