[FEATURE] Create output_directory_nfo_tags on first entry instead of last (#809)

This commit is contained in:
Jesse Bannon 2023-11-05 23:10:29 -08:00 committed by GitHub
parent e257210e4a
commit 395691f2b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 23 deletions

View file

@ -97,16 +97,18 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
nfo_tags: Dict[str, List[XmlElement]] = defaultdict(list)
for key, string_tags in self.plugin_options.tags.string_tags.items():
nfo_tags[key].extend(
tags = [
XmlElement(
text=self.overrides.apply_formatter(formatter=string_tag, entry=entry),
attributes={},
)
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():
nfo_tags[key].extend(
tags = [
XmlElement(
text=self.overrides.apply_formatter(formatter=attribute_tag.tag, entry=entry),
attributes={
@ -117,9 +119,12 @@ class SharedNfoTagsPlugin(Plugin[SharedNfoTagsOptions], ABC):
},
)
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:
# 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)
# If the nfo tags are empty, then stop continuing
if not nfo_tags:
return
if self.plugin_options.kodi_safe:
nfo_root = to_max_3_byte_utf8_string(nfo_root)
nfo_tags = {

View file

@ -1,5 +1,3 @@
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
@ -95,23 +93,16 @@ class OutputDirectoryNfoTagsPlugin(SharedNfoTagsPlugin):
enhanced_download_archive: EnhancedDownloadArchive,
):
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:
"""
Tracks the last entry processed
"""
self._last_entry = entry
def post_process_subscription(self):
"""
Creates an NFO file in the root of the output directory using the last entry
Creates output NFO using the first entry, and only creates it once
"""
if (
self.plugin_options.nfo_name is None
or self.plugin_options.nfo_root is None
or self._last_entry is None
not self._created_output_nfo
and self.plugin_options.nfo_name is not None
and self.plugin_options.nfo_root is not None
):
return
self._create_nfo(entry=self._last_entry, save_to_entry=False)
self._create_nfo(entry=entry, save_to_entry=False)
self._created_output_nfo = True

View file

@ -19,7 +19,8 @@ def subscription_dict(output_directory):
"attributes": {"🎸?": "value\nnewlines 🎸"},
"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": [
{
"attributes": {"🎸?": "value\nnewlines 🎸"},
@ -29,7 +30,16 @@ def subscription_dict(output_directory):
"attributes": {"🎸?": "value\nnewlines 🎸"},
"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": {
@ -41,7 +51,8 @@ def subscription_dict(output_directory):
"attributes": {"🎸?": "value\nnewlines 🎸"},
"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": [
{
"attributes": {"🎸?": "value\nnewlines 🎸"},
@ -51,7 +62,16 @@ def subscription_dict(output_directory):
"attributes": {"🎸?": "value\nnewlines 🎸"},
"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": "",
},
},
}