diff --git a/src/ytdl_sub/plugins/music_tags.py b/src/ytdl_sub/plugins/music_tags.py index 14724c37..c74c85a1 100644 --- a/src/ytdl_sub/plugins/music_tags.py +++ b/src/ytdl_sub/plugins/music_tags.py @@ -56,7 +56,7 @@ class MusicTagsOptions(PluginOptions): class MusicTagsPlugin(Plugin[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 """ diff --git a/src/ytdl_sub/plugins/nfo_tags.py b/src/ytdl_sub/plugins/nfo_tags.py index f1b9705a..38d8d15b 100644 --- a/src/ytdl_sub/plugins/nfo_tags.py +++ b/src/ytdl_sub/plugins/nfo_tags.py @@ -80,7 +80,7 @@ class NfoTagsOptions(PluginOptions): class NfoTagsPlugin(Plugin[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 @@ -115,7 +115,6 @@ class NfoTagsPlugin(Plugin[NfoTagsOptions]): with open(nfo_file_path, "wb") as nfo_file: nfo_file.write(xml) - # Archive the nfo's file name - self.save_file(file_name=nfo_file_name, entry=entry) - - return FileMetadata.from_dict(value_dict={nfo_root: nfo}, title="NFO tags:") + # Save the nfo file and log its metadata + 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) diff --git a/src/ytdl_sub/plugins/output_directory_nfo_tags.py b/src/ytdl_sub/plugins/output_directory_nfo_tags.py index e0aa7294..1d2a5dba 100644 --- a/src/ytdl_sub/plugins/output_directory_nfo_tags.py +++ b/src/ytdl_sub/plugins/output_directory_nfo_tags.py @@ -106,5 +106,5 @@ class OutputDirectoryNfoTagsPlugin(Plugin[OutputDirectoryNfoTagsOptions]): with open(nfo_file_path, "wb") as nfo_file: nfo_file.write(xml) - self.save_file(file_name=nfo_file_name) - return FileMetadata.from_dict(value_dict={nfo_root: nfo}, title="NFO tags:") + 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) diff --git a/src/ytdl_sub/subscriptions/subscription.py b/src/ytdl_sub/subscriptions/subscription.py index c7e9647a..6123a164 100644 --- a/src/ytdl_sub/subscriptions/subscription.py +++ b/src/ytdl_sub/subscriptions/subscription.py @@ -272,7 +272,9 @@ class Subscription: entry, entry_metadata = entry 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( entry=entry, entry_metadata=entry_metadata diff --git a/src/ytdl_sub/utils/file_handler.py b/src/ytdl_sub/utils/file_handler.py index e298c730..5cea379d 100644 --- a/src/ytdl_sub/utils/file_handler.py +++ b/src/ytdl_sub/utils/file_handler.py @@ -58,11 +58,19 @@ class FileMetadata: def _recursive_add_dict_lines(rdict: Dict, indent: int): for key, value in sorted(rdict.items()): - if isinstance(value, Dict): - _recursive_add_dict_lines(rdict=value, indent=indent + 2) - _indent = " " * indent - lines.append(f"{_indent}{key}: {value}") + 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}") _recursive_add_dict_lines(rdict=value_dict, indent=2) return cls(metadata=lines) diff --git a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py index cc2ca39d..43eb4346 100644 --- a/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py +++ b/src/ytdl_sub/ytdl_additions/enhanced_download_archive.py @@ -618,7 +618,11 @@ class DownloadArchiver: return self.__enhanced_download_archive.is_dry_run 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: """ Saves a file in the working directory to the output directory. @@ -627,6 +631,8 @@ class DownloadArchiver: ---------- file_name 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 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 @@ -634,5 +640,8 @@ class DownloadArchiver: Optional. Entry that the file belongs to """ 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, )