fix nfo tags, no tests only manual inspection

This commit is contained in:
jbannon 2022-07-03 06:56:36 +00:00
parent 7006ce3dc7
commit dcd33b80ee
6 changed files with 33 additions and 15 deletions

View file

@ -56,7 +56,7 @@ class MusicTagsOptions(PluginOptions):
class MusicTagsPlugin(Plugin[MusicTagsOptions]): class MusicTagsPlugin(Plugin[MusicTagsOptions]):
plugin_options_type = MusicTagsOptions plugin_options_type = MusicTagsOptions
def post_process_entry(self, entry: Entry): def post_process_entry(self, entry: Entry) -> FileMetadata:
""" """
Tags the entry's audio file using values defined in the metadata options Tags the entry's audio file using values defined in the metadata options
""" """

View file

@ -80,7 +80,7 @@ class NfoTagsOptions(PluginOptions):
class NfoTagsPlugin(Plugin[NfoTagsOptions]): class NfoTagsPlugin(Plugin[NfoTagsOptions]):
plugin_options_type = NfoTagsOptions plugin_options_type = NfoTagsOptions
def post_process_entry(self, entry: Entry): def post_process_entry(self, entry: Entry) -> None:
""" """
Creates an entry's NFO file using values defined in the metadata options Creates an entry's NFO file using values defined in the metadata options
@ -115,7 +115,6 @@ class NfoTagsPlugin(Plugin[NfoTagsOptions]):
with open(nfo_file_path, "wb") as nfo_file: with open(nfo_file_path, "wb") as nfo_file:
nfo_file.write(xml) nfo_file.write(xml)
# Archive the nfo's file name # Save the nfo file and log its metadata
self.save_file(file_name=nfo_file_name, entry=entry) nfo_metadata = FileMetadata.from_dict(value_dict={nfo_root: nfo}, title="NFO tags:")
self.save_file(file_name=nfo_file_name, file_metadata=nfo_metadata, entry=entry)
return FileMetadata.from_dict(value_dict={nfo_root: nfo}, title="NFO tags:")

View file

@ -106,5 +106,5 @@ class OutputDirectoryNfoTagsPlugin(Plugin[OutputDirectoryNfoTagsOptions]):
with open(nfo_file_path, "wb") as nfo_file: with open(nfo_file_path, "wb") as nfo_file:
nfo_file.write(xml) nfo_file.write(xml)
self.save_file(file_name=nfo_file_name) nfo_metadata = FileMetadata.from_dict(value_dict={nfo_root: nfo}, title="NFO tags:")
return FileMetadata.from_dict(value_dict={nfo_root: nfo}, title="NFO tags:") self.save_file(file_name=nfo_file_name, file_metadata=nfo_metadata)

View file

@ -272,7 +272,9 @@ class Subscription:
entry, entry_metadata = entry entry, entry_metadata = entry
for plugin in plugins: for plugin in plugins:
entry_metadata.extend(plugin.post_process_entry(entry)) optional_plugin_entry_metadata = plugin.post_process_entry(entry)
if optional_plugin_entry_metadata:
entry_metadata.extend(optional_plugin_entry_metadata)
self._copy_entry_files_to_output_directory( self._copy_entry_files_to_output_directory(
entry=entry, entry_metadata=entry_metadata entry=entry, entry_metadata=entry_metadata

View file

@ -58,10 +58,18 @@ class FileMetadata:
def _recursive_add_dict_lines(rdict: Dict, indent: int): def _recursive_add_dict_lines(rdict: Dict, indent: int):
for key, value in sorted(rdict.items()): for key, value in sorted(rdict.items()):
if isinstance(value, Dict):
_recursive_add_dict_lines(rdict=value, indent=indent + 2)
_indent = " " * indent _indent = " " * indent
if isinstance(value, Dict):
lines.append(f"{_indent}{key}:")
_recursive_add_dict_lines(rdict=value, indent=indent + 2)
else:
value = str(value)
# If there are newlines in the value, print them indented
if "\n" in value:
lines.append(f"{_indent}{key}:")
for value_line in value.split("\n"):
lines.append(f" {_indent}{value_line.strip()}")
else:
lines.append(f"{_indent}{key}: {value}") lines.append(f"{_indent}{key}: {value}")
_recursive_add_dict_lines(rdict=value_dict, indent=2) _recursive_add_dict_lines(rdict=value_dict, indent=2)

View file

@ -618,7 +618,11 @@ class DownloadArchiver:
return self.__enhanced_download_archive.is_dry_run return self.__enhanced_download_archive.is_dry_run
def save_file( def save_file(
self, file_name: str, output_file_name: Optional[str] = None, entry: Optional[Entry] = None self,
file_name: str,
file_metadata: Optional[FileMetadata] = None,
output_file_name: Optional[str] = None,
entry: Optional[Entry] = None,
) -> None: ) -> None:
""" """
Saves a file in the working directory to the output directory. Saves a file in the working directory to the output directory.
@ -627,6 +631,8 @@ class DownloadArchiver:
---------- ----------
file_name file_name
Name of the file relative to the working directory Name of the file relative to the working directory
file_metadata
Optional. Metadata to record to the transaction log for this file
output_file_name output_file_name
Optional. Final name of the file in the output directory (does not include output Optional. Final name of the file in the output directory (does not include output
directory path). If None, use the same working_directory file_name directory path). If None, use the same working_directory file_name
@ -634,5 +640,8 @@ class DownloadArchiver:
Optional. Entry that the file belongs to Optional. Entry that the file belongs to
""" """
self.__enhanced_download_archive.save_file_to_output_directory( self.__enhanced_download_archive.save_file_to_output_directory(
file_name=file_name, output_file_name=output_file_name, entry=entry file_name=file_name,
file_metadata=file_metadata,
output_file_name=output_file_name,
entry=entry,
) )