better nfo test
This commit is contained in:
parent
fd80b93597
commit
61cfd3cbb0
4 changed files with 82 additions and 13 deletions
|
|
@ -103,7 +103,7 @@ class SharedNfoTagsPlugin(
|
|||
Shared code between NFO tags and Ouptut Directory NFO Tags
|
||||
"""
|
||||
|
||||
def _create_nfo(self, entry: Optional[Entry] = None) -> None:
|
||||
def _get_xml_element_dict(self, entry: Optional[Entry]) -> Dict[str, XmlElement]:
|
||||
nfo_tags: Dict[str, XmlElement] = {}
|
||||
|
||||
for key, string_tag in self.plugin_options.tags.string_tags.items():
|
||||
|
|
@ -121,18 +121,24 @@ class SharedNfoTagsPlugin(
|
|||
},
|
||||
)
|
||||
|
||||
return nfo_tags
|
||||
|
||||
def _create_nfo(self, entry: Optional[Entry] = None) -> None:
|
||||
# Write the nfo tags to XML with the nfo_root
|
||||
nfo_root = self.overrides.apply_formatter(
|
||||
formatter=self.plugin_options.nfo_root, entry=entry
|
||||
)
|
||||
nfo_tags = self._get_xml_element_dict(entry=entry)
|
||||
|
||||
if self.plugin_options.kodi_safe:
|
||||
nfo_root = to_max_3_byte_utf8_string(nfo_root)
|
||||
for key, xml_elem in nfo_tags.items():
|
||||
nfo_tags[key] = XmlElement(
|
||||
nfo_tags = {
|
||||
to_max_3_byte_utf8_string(key): XmlElement(
|
||||
text=to_max_3_byte_utf8_string(xml_elem.text),
|
||||
attributes=to_max_3_byte_utf8_dict(xml_elem.attributes),
|
||||
)
|
||||
for key, xml_elem in nfo_tags.items()
|
||||
}
|
||||
|
||||
xml = to_xml(nfo_dict=nfo_tags, nfo_root=nfo_root)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from ytdl_sub.subscriptions.subscription import Subscription
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def kodi_safe_subscription_dict(output_directory):
|
||||
def subscription_dict(output_directory):
|
||||
return {
|
||||
"preset": "yt_music_video",
|
||||
"youtube": {"video_url": "https://www.youtube.com/shorts/ucYmEqmlhFw"},
|
||||
|
|
@ -17,25 +17,40 @@ def kodi_safe_subscription_dict(output_directory):
|
|||
},
|
||||
"nfo_tags": {
|
||||
"tags": {
|
||||
"kodi_safe_title 🎸": "{title}",
|
||||
"kodi_safe_title 🎸": "kodi_safe_value 🎸",
|
||||
"kodi_safe_title_with_attrs": {
|
||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||
"tag": "the \n tag 🎸🎸",
|
||||
},
|
||||
},
|
||||
"kodi_safe": True,
|
||||
},
|
||||
"output_directory_nfo_tags": {
|
||||
"nfo_name": "test.nfo",
|
||||
"nfo_root": "kodi_safe_root 🎸",
|
||||
"tags": {"kodi_safe_title 🎸": "kodi_safe_value 🎸"},
|
||||
"kodi_safe": True,
|
||||
"tags": {
|
||||
"kodi_safe_title 🎸": "kodi_safe_value 🎸",
|
||||
"kodi_safe_title_with_attrs": {
|
||||
"attributes": {"🎸?": "value\nnewlines 🎸"},
|
||||
"tag": "the \n tag 🎸🎸",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class TestNfoTagsPlugins:
|
||||
def test_kodi_safe(self, kodi_safe_subscription_dict, music_video_config, output_directory):
|
||||
@pytest.mark.parametrize("kodi_safe", [True, False])
|
||||
def test_nfo_tags(self, subscription_dict, music_video_config, output_directory, kodi_safe):
|
||||
transaction_log_file_name = "test_nfo.txt"
|
||||
if kodi_safe:
|
||||
transaction_log_file_name = "test_nfo_kodi_safe.txt"
|
||||
subscription_dict["nfo_tags"]["kodi_safe"] = True
|
||||
subscription_dict["output_directory_nfo_tags"]["kodi_safe"] = True
|
||||
|
||||
subscription = Subscription.from_dict(
|
||||
config=music_video_config,
|
||||
preset_name="kodi_safe_xml",
|
||||
preset_dict=kodi_safe_subscription_dict,
|
||||
preset_dict=subscription_dict,
|
||||
)
|
||||
|
||||
# Only dry run is needed to see if NFO values are kodi safe
|
||||
|
|
@ -43,5 +58,5 @@ class TestNfoTagsPlugins:
|
|||
assert_transaction_log_matches(
|
||||
output_directory=output_directory,
|
||||
transaction_log=transaction_log,
|
||||
transaction_log_summary_file_name="plugins/test_kodi_safe_xml.txt",
|
||||
transaction_log_summary_file_name=f"plugins/nfo_tags/{transaction_log_file_name}",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
Files created in '{output_directory}'
|
||||
----------------------------------------
|
||||
Rick Beato - Can you hear the difference? 🎸🔥 #shorts-thumb.jpg
|
||||
Rick Beato - Can you hear the difference? 🎸🔥 #shorts.3gp
|
||||
Rick Beato - Can you hear the difference? 🎸🔥 #shorts.nfo
|
||||
NFO tags:
|
||||
musicvideo:
|
||||
album: Music Videos
|
||||
artist: Rick Beato
|
||||
kodi_safe_title 🎸: kodi_safe_value 🎸
|
||||
kodi_safe_title_with_attrs:
|
||||
attributes:
|
||||
🎸?:
|
||||
value
|
||||
newlines 🎸
|
||||
tag:
|
||||
the
|
||||
tag 🎸🎸
|
||||
title: Can you hear the difference? 🎸🔥 #shorts
|
||||
year: 2022
|
||||
test.nfo
|
||||
NFO tags:
|
||||
kodi_safe_root 🎸:
|
||||
kodi_safe_title 🎸: kodi_safe_value 🎸
|
||||
kodi_safe_title_with_attrs:
|
||||
attributes:
|
||||
🎸?:
|
||||
value
|
||||
newlines 🎸
|
||||
tag:
|
||||
the
|
||||
tag 🎸🎸
|
||||
|
|
@ -7,10 +7,26 @@ Rick Beato - Can you hear the difference? 🎸🔥 #shorts.nfo
|
|||
musicvideo:
|
||||
album: Music Videos
|
||||
artist: Rick Beato
|
||||
kodi_safe_title □: Can you hear the difference? □□ #shorts
|
||||
kodi_safe_title □: kodi_safe_value □
|
||||
kodi_safe_title_with_attrs:
|
||||
attributes:
|
||||
□?:
|
||||
value
|
||||
newlines □
|
||||
tag:
|
||||
the
|
||||
tag □□
|
||||
title: Can you hear the difference? □□ #shorts
|
||||
year: 2022
|
||||
test.nfo
|
||||
NFO tags:
|
||||
kodi_safe_root □:
|
||||
kodi_safe_title □: kodi_safe_value □
|
||||
kodi_safe_title_with_attrs:
|
||||
attributes:
|
||||
□?:
|
||||
value
|
||||
newlines □
|
||||
tag:
|
||||
the
|
||||
tag □□
|
||||
Loading…
Reference in a new issue