[FEATURE] Create output_directory_nfo_tags on first entry instead of last (#809)
This commit is contained in:
parent
e257210e4a
commit
395691f2b9
3 changed files with 43 additions and 23 deletions
|
|
@ -97,16 +97,18 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
|
||||||
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():
|
||||||
nfo_tags[key].extend(
|
tags = [
|
||||||
XmlElement(
|
XmlElement(
|
||||||
text=self.overrides.apply_formatter(formatter=string_tag, entry=entry),
|
text=self.overrides.apply_formatter(formatter=string_tag, entry=entry),
|
||||||
attributes={},
|
attributes={},
|
||||||
)
|
)
|
||||||
for string_tag in string_tags
|
for string_tag in string_tags
|
||||||
)
|
]
|
||||||
|
# Do not add tags with empty text
|
||||||
|
nfo_tags[key].extend(tag for tag in tags if tag.text)
|
||||||
|
|
||||||
for key, attribute_tags in self.plugin_options.tags.attribute_tags.items():
|
for key, attribute_tags in self.plugin_options.tags.attribute_tags.items():
|
||||||
nfo_tags[key].extend(
|
tags = [
|
||||||
XmlElement(
|
XmlElement(
|
||||||
text=self.overrides.apply_formatter(formatter=attribute_tag.tag, entry=entry),
|
text=self.overrides.apply_formatter(formatter=attribute_tag.tag, entry=entry),
|
||||||
attributes={
|
attributes={
|
||||||
|
|
@ -117,9 +119,12 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
for attribute_tag in attribute_tags
|
for attribute_tag in attribute_tags
|
||||||
)
|
]
|
||||||
|
# Do not add tags with empty text
|
||||||
|
nfo_tags[key].extend(tag for tag in tags if tag.text)
|
||||||
|
|
||||||
return nfo_tags
|
# Do not add tags with empty lists
|
||||||
|
return {key: tags for key, tags in nfo_tags.items() if len(tags) > 0}
|
||||||
|
|
||||||
def _create_nfo(self, entry: Entry, save_to_entry: bool = True) -> 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
|
||||||
|
|
@ -128,6 +133,10 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
|
||||||
)
|
)
|
||||||
nfo_tags = self._get_xml_element_dict(entry=entry)
|
nfo_tags = self._get_xml_element_dict(entry=entry)
|
||||||
|
|
||||||
|
# If the nfo tags are empty, then stop continuing
|
||||||
|
if not nfo_tags:
|
||||||
|
return
|
||||||
|
|
||||||
if self.plugin_options.kodi_safe:
|
if self.plugin_options.kodi_safe:
|
||||||
nfo_root = to_max_3_byte_utf8_string(nfo_root)
|
nfo_root = to_max_3_byte_utf8_string(nfo_root)
|
||||||
nfo_tags = {
|
nfo_tags = {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from ytdl_sub.config.preset_options import Overrides
|
from ytdl_sub.config.preset_options import Overrides
|
||||||
from ytdl_sub.entries.entry import Entry
|
from ytdl_sub.entries.entry import Entry
|
||||||
from ytdl_sub.plugins.nfo_tags import NfoTagsValidator
|
from ytdl_sub.plugins.nfo_tags import NfoTagsValidator
|
||||||
|
|
@ -95,23 +93,16 @@ class OutputDirectoryNfoTagsPlugin(SharedNfoTagsPlugin):
|
||||||
enhanced_download_archive: EnhancedDownloadArchive,
|
enhanced_download_archive: EnhancedDownloadArchive,
|
||||||
):
|
):
|
||||||
super().__init__(options, overrides, enhanced_download_archive)
|
super().__init__(options, overrides, enhanced_download_archive)
|
||||||
self._last_entry: Optional[Entry] = None
|
self._created_output_nfo = False
|
||||||
|
|
||||||
def post_process_entry(self, entry: Entry) -> None:
|
def post_process_entry(self, entry: Entry) -> None:
|
||||||
"""
|
"""
|
||||||
Tracks the last entry processed
|
Creates output NFO using the first entry, and only creates it once
|
||||||
"""
|
|
||||||
self._last_entry = entry
|
|
||||||
|
|
||||||
def post_process_subscription(self):
|
|
||||||
"""
|
|
||||||
Creates an NFO file in the root of the output directory using the last entry
|
|
||||||
"""
|
"""
|
||||||
if (
|
if (
|
||||||
self.plugin_options.nfo_name is None
|
not self._created_output_nfo
|
||||||
or self.plugin_options.nfo_root is None
|
and self.plugin_options.nfo_name is not None
|
||||||
or self._last_entry is None
|
and self.plugin_options.nfo_root is not None
|
||||||
):
|
):
|
||||||
return
|
self._create_nfo(entry=entry, save_to_entry=False)
|
||||||
|
self._created_output_nfo = True
|
||||||
self._create_nfo(entry=self._last_entry, save_to_entry=False)
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ def subscription_dict(output_directory):
|
||||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
"tag": "the \n tag 🎸🎸",
|
"tag": "the \n tag 🎸🎸",
|
||||||
},
|
},
|
||||||
"kodi_safe_multi_title 🎸": ["value 1 🎸", "value 2 🎸"],
|
# should not show third empty
|
||||||
|
"kodi_safe_multi_title 🎸": ["value 1 🎸", "value 2 🎸", ""],
|
||||||
"kodi_safe_multi_title_with_attrs": [
|
"kodi_safe_multi_title_with_attrs": [
|
||||||
{
|
{
|
||||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
|
|
@ -29,7 +30,16 @@ def subscription_dict(output_directory):
|
||||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
"tag": "the \n tag 2 🎸🎸",
|
"tag": "the \n tag 2 🎸🎸",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"attributes": {"🎸?": "EMPTY TAG SHOULD NOT SHOW"},
|
||||||
|
"tag": "",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
"empty_attribute_tag_SHOULD_NOT_SHOW": {
|
||||||
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
|
"tag": "",
|
||||||
|
},
|
||||||
|
"empty_tag_SHOULD_NOT_SHOW": "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"output_directory_nfo_tags": {
|
"output_directory_nfo_tags": {
|
||||||
|
|
@ -41,7 +51,8 @@ def subscription_dict(output_directory):
|
||||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
"tag": "the \n tag 🎸🎸",
|
"tag": "the \n tag 🎸🎸",
|
||||||
},
|
},
|
||||||
"kodi_safe_multi_title 🎸": ["value 1 🎸", "value 2 🎸"],
|
# should not show third empty
|
||||||
|
"kodi_safe_multi_title 🎸": ["value 1 🎸", "value 2 🎸", ""],
|
||||||
"kodi_safe_multi_title_with_attrs": [
|
"kodi_safe_multi_title_with_attrs": [
|
||||||
{
|
{
|
||||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
|
|
@ -51,7 +62,16 @@ def subscription_dict(output_directory):
|
||||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
"tag": "the \n tag 2 🎸🎸",
|
"tag": "the \n tag 2 🎸🎸",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"attributes": {"🎸?": "EMPTY TAG SHOULD NOT SHOW"},
|
||||||
|
"tag": "",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
"empty_attribute_tag_SHOULD_NOT_SHOW": {
|
||||||
|
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||||
|
"tag": "",
|
||||||
|
},
|
||||||
|
"empty_tag_SHOULD_NOT_SHOW": "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue