From 6351afb36c078825ec5bc387aae144b46124cf57 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sat, 8 Jun 2024 19:12:38 -0700 Subject: [PATCH] Add an option to prefer filename metadata on the CLI fixes #630 --- comictaggerlib/cli.py | 16 ++++++++++++---- comictaggerlib/ctsettings/commandline.py | 6 ++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py index 046d4ad..6ebf830 100644 --- a/comictaggerlib/cli.py +++ b/comictaggerlib/cli.py @@ -234,10 +234,11 @@ class CLI: def create_local_metadata(self, ca: ComicArchive) -> GenericMetadata: md = GenericMetadata() md.apply_default_page_list(ca.get_page_name_list()) + filename_md = GenericMetadata() # now, overlay the parsed filename info if self.config.Runtime_Options__parse_filename: - f_md = ca.metadata_from_filename( + filename_md = ca.metadata_from_filename( self.config.Filename_Parsing__filename_parser, self.config.Filename_Parsing__remove_c2c, self.config.Filename_Parsing__remove_fcbd, @@ -247,17 +248,24 @@ class CLI: self.config.Filename_Parsing__protofolius_issue_number_scheme, ) - md.overlay(f_md) - + file_md = GenericMetadata() for style in self.config.Runtime_Options__type_read: if ca.has_metadata(style): try: t_md = ca.read_metadata(style) - md.overlay(t_md, self.config.internal__load_data_overlay, self.config.internal__overlay_merge_lists) + file_md.overlay( + t_md, self.config.internal__load_data_overlay, self.config.internal__overlay_merge_lists + ) break except Exception as e: logger.error("Failed to load metadata for %s: %s", ca.path, e) + filename_merge = merge.Mode.ADD_MISSING + if self.config.Runtime_Options__prefer_filename: + filename_merge = merge.Mode.OVERLAY + + md.overlay(file_md, mode=merge.Mode.OVERLAY, merge_lists=False) + md.overlay(filename_md, mode=filename_merge, merge_lists=False) # finally, use explicit stuff (always 'overlay' mode) md.overlay(self.config.Runtime_Options__metadata, mode=merge.Mode.OVERLAY, merge_lists=True) diff --git a/comictaggerlib/ctsettings/commandline.py b/comictaggerlib/ctsettings/commandline.py index 8280714..0f7d199 100644 --- a/comictaggerlib/ctsettings/commandline.py +++ b/comictaggerlib/ctsettings/commandline.py @@ -90,6 +90,12 @@ def register_runtime(parser: settngs.Manager) -> None: help="""Parse the filename to get some info,\nspecifically series name, issue number,\nvolume, and publication year.\n\n""", file=False, ) + parser.add_setting( + "--prefer-filename", + action="store_true", + help="""Prefer metadata parsed from the filename. CLI only.\n\n""", + file=False, + ) parser.add_setting( "--id", dest="issue_id",