From eec715551a9026efa382807e391efa372deae389 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Tue, 17 May 2022 18:28:37 -0700 Subject: [PATCH] Allow overwriting existing metadata --- comictaggerlib/cli.py | 25 ++++++++++++++++++------- comictaggerlib/options.py | 6 ++++++ comictaggerlib/taggerwindow.py | 5 ++++- comictaggerlib/ui/autotagstartwindow.ui | 18 ++++++++++++++---- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py index b831709..9482446 100644 --- a/comictaggerlib/cli.py +++ b/comictaggerlib/cli.py @@ -108,7 +108,10 @@ def display_match_set_for_choice( opts, ca, ca.has_metadata(opts.data_style if opts.data_style is not None else 0), settings ) cv_md = actual_issue_data_fetch(match_set.matches[int(i) - 1], settings, opts) - md.overlay(cv_md) + if opts.overwrite_metadata: + md = cv_md + else: + md.overlay(cv_md) if opts.auto_imprint: md.fix_publisher() @@ -181,17 +184,22 @@ def create_local_metadata( # now, overlay the parsed filename info if opts.parse_filename: - md.overlay( - ca.metadata_from_filename( - settings.complicated_parser, settings.remove_c2c, settings.remove_fcbd, settings.remove_publisher - ) + f_md = ca.metadata_from_filename( + settings.complicated_parser, settings.remove_c2c, settings.remove_fcbd, settings.remove_publisher ) + if opts.overwrite_metadata: + md = f_md + else: + md.overlay(f_md) if has_desired_tags: md = ca.read_metadata(opts.data_style if opts.data_style is not None else 0) # finally, use explicit stuff - md.overlay(opts.metadata) + if opts.overwrite_metadata and not opts.metadata.is_empty: + md = opts.metadata + else: + md.overlay(opts.metadata) return md @@ -427,7 +435,10 @@ def process_file_cli( match_results.fetch_data_failures.append(str(ca.path.absolute())) return - md.overlay(cv_md) + if opts.overwrite_metadata: + md = cv_md + else: + md.overlay(cv_md) if opts.auto_imprint: md.fix_publisher() diff --git a/comictaggerlib/options.py b/comictaggerlib/options.py index d3550e0..79e9413 100644 --- a/comictaggerlib/options.py +++ b/comictaggerlib/options.py @@ -66,6 +66,8 @@ If no options are given, {0} will run in windowed mode. -o, --online Search online and attempt to identify file using existing metadata and images in archive. May be used in conjunction with -f and -m. + --overwrite Overwite any existing metadata. + May be used in conjunction with -o, -f and -m. --id=ID Use the issue ID when searching online. Overrides all other metadata. -m, --metadata=LIST Explicitly define, as a list, some tags to be @@ -146,6 +148,7 @@ For more help visit the wiki at: https://github.com/comictagger/comictagger/wiki self.darkmode = False self.copy_source: Optional[int] = None self.config_path = "" + self.overwrite_metadata = False def display_msg_and_quit(self, msg: Optional[str], code: int, show_help: bool = False) -> None: appname = os.path.basename(sys.argv[0]) @@ -292,6 +295,7 @@ For more help visit the wiki at: https://github.com/comictagger/comictagger/wiki "wait-on-cv-rate-limit", "darkmode", "config=", + "overwrite", ], ) @@ -330,6 +334,8 @@ For more help visit the wiki at: https://github.com/comictagger/comictagger/wiki self.display_msg_and_quit("Invalid copy tag source type", 1) if o in ("-o", "--online"): self.search_online = True + if o == "--overwrite": + self.overwrite_metadata = True if o in ("-n", "--dryrun"): self.dryrun = True if o in ("-m", "--metadata"): diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index a9b869a..42d5f0f 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -1750,7 +1750,10 @@ Please choose options below, and select OK. match_results.fetch_data_failures.append(str(ca.path.absolute())) if cv_md is not None: - md.overlay(cv_md) + if dlg.cbxRemoveMetadata.isChecked(): + md = cv_md + else: + md.overlay(cv_md) if self.settings.auto_imprint: md.fix_publisher() diff --git a/comictaggerlib/ui/autotagstartwindow.ui b/comictaggerlib/ui/autotagstartwindow.ui index 17faf32..7bbe128 100644 --- a/comictaggerlib/ui/autotagstartwindow.ui +++ b/comictaggerlib/ui/autotagstartwindow.ui @@ -44,7 +44,7 @@ - + @@ -139,7 +139,17 @@ - + + + + Removes existing metadata before applying retrieved metadata + + + Overwrite metadata + + + + @@ -155,7 +165,7 @@ - + @@ -165,7 +175,7 @@ - +