diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index 10a599a..38c74d6 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -137,17 +137,11 @@ class ComicInfoXml: # second, convert each list to string, and add to XML struct assign("Writer", ", ".join(credit_writer_list)) - assign("Penciller", ", ".join(credit_penciller_list)) - assign("Inker", ", ".join(credit_inker_list)) - assign("Colorist", ", ".join(credit_colorist_list)) - assign("Letterer", ", ".join(credit_letterer_list)) - assign("CoverArtist", ", ".join(credit_cover_list)) - assign("Editor", ", ".join(credit_editor_list)) assign("Publisher", md.publisher) diff --git a/comicapi/genericmetadata.py b/comicapi/genericmetadata.py index 77700d7..4b7e4da 100644 --- a/comicapi/genericmetadata.py +++ b/comicapi/genericmetadata.py @@ -78,6 +78,7 @@ class GenericMetadata: is_empty: bool = True tag_origin: str | None = None + issue_id: int | None = None series: str | None = None issue: str | None = None diff --git a/comicapi/utils.py b/comicapi/utils.py index c162b87..8243f3d 100644 --- a/comicapi/utils.py +++ b/comicapi/utils.py @@ -37,6 +37,14 @@ class UtilsVars: already_fixed_encoding = False +def combine_notes(existing_notes: str | None, new_notes: str | None, split: str) -> str: + split_notes, _, untouched_notes = (existing_notes or "").rpartition(split) + if split_notes: + return (split_notes + (new_notes or "")).strip() + else: + return (untouched_notes + "\n" + (new_notes or "")).strip() + + def parse_date_str(date_str: str) -> tuple[int | None, int | None, int | None]: day = None month = None diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py index b48bed2..b73b75d 100644 --- a/comictaggerlib/cli.py +++ b/comictaggerlib/cli.py @@ -22,11 +22,13 @@ import logging import os import pathlib import sys +from datetime import datetime from pprint import pprint from comicapi import utils from comicapi.comicarchive import ComicArchive, MetaDataStyle from comicapi.genericmetadata import GenericMetadata +from comictaggerlib import ctversion from comictaggerlib.cbltransformer import CBLTransformer from comictaggerlib.comicvinetalker import ComicVineTalker, ComicVineTalkerException from comictaggerlib.filerenamer import FileRenamer, get_rename_dir @@ -112,7 +114,11 @@ def display_match_set_for_choice( if opts.overwrite: md = cv_md else: - md.overlay(cv_md) + notes = ( + f"Tagged with ComicTagger {ctversion.version} using info from Comic Vine on" + f" {datetime.now():%Y-%m-%d %H:%M:%S}. [Issue ID {cv_md.issue_id}]" + ) + md.overlay(cv_md.replace(notes=utils.combine_notes(md.notes, notes, "Tagged with ComicTagger"))) if opts.auto_imprint: md.fix_publisher() @@ -461,7 +467,11 @@ def process_file_cli( if opts.overwrite: md = cv_md else: - md.overlay(cv_md) + notes = ( + f"Tagged with ComicTagger {ctversion.version} using info from Comic Vine on" + f" {datetime.now():%Y-%m-%d %H:%M:%S}. [Issue ID {cv_md.issue_id}]" + ) + md.overlay(cv_md.replace(notes=utils.combine_notes(md.notes, notes, "Tagged with ComicTagger"))) if opts.auto_imprint: md.fix_publisher() diff --git a/comictaggerlib/comicvinetalker.py b/comictaggerlib/comicvinetalker.py index 5b56b14..13fedaf 100644 --- a/comictaggerlib/comicvinetalker.py +++ b/comictaggerlib/comicvinetalker.py @@ -19,7 +19,6 @@ import json import logging import re import time -from datetime import datetime from typing import Any, Callable, cast from urllib.parse import urlencode, urljoin, urlsplit @@ -466,6 +465,8 @@ class ComicVineTalker: # Now, map the Comic Vine data to generic metadata metadata = GenericMetadata() metadata.is_empty = False + metadata.tag_origin = "Comic Vine" + metadata.issue_id = issue_results["id"] metadata.series = utils.xlate(issue_results["volume"]["name"]) metadata.issue = IssueString(issue_results["issue_number"]).as_string() @@ -479,10 +480,6 @@ class ComicVineTalker: if settings.use_series_start_as_volume: metadata.volume = int(volume_results["start_year"]) - metadata.notes = ( - f"Tagged with ComicTagger {ctversion.version} using info from Comic Vine on" - f" {datetime.now():%Y-%m-%d %H:%M:%S}. [Issue ID {issue_results['id']}]" - ) metadata.web_link = issue_results["site_detail_url"] person_credits = issue_results["person_credits"] diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index f0698a2..f7c783a 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -27,6 +27,7 @@ import re import sys import webbrowser from collections.abc import Iterable +from datetime import datetime from typing import Any, Callable, cast from urllib.parse import urlparse @@ -1090,7 +1091,15 @@ Have fun! if self.settings.clear_form_before_populating_from_cv: self.clear_form() - self.metadata.overlay(new_metadata) + notes = ( + f"Tagged with ComicTagger {ctversion.version} using info from Comic Vine on" + f" {datetime.now():%Y-%m-%d %H:%M:%S}. [Issue ID {new_metadata.issue_id}]" + ) + self.metadata.overlay( + new_metadata.replace( + notes=utils.combine_notes(self.metadata.notes, notes, "Tagged with ComicTagger") + ) + ) # Now push the new combined data into the edit controls self.metadata_to_form() else: @@ -1794,7 +1803,11 @@ Have fun! if dlg.cbxRemoveMetadata.isChecked(): md = cv_md else: - md.overlay(cv_md) + notes = ( + f"Tagged with ComicTagger {ctversion.version} using info from Comic Vine on" + f" {datetime.now():%Y-%m-%d %H:%M:%S}. [Issue ID {cv_md.issue_id}]" + ) + md.overlay(cv_md.replace(notes=utils.combine_notes(md.notes, notes, "Tagged with ComicTagger"))) if self.settings.auto_imprint: md.fix_publisher() diff --git a/tests/utils_test.py b/tests/utils_test.py index 960c018..6d66b28 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -77,6 +77,23 @@ def test_get_language_iso(value, result): assert result == comicapi.utils.get_language_iso(value) +combine_values = [ + ("hello", "english", "en", "hello\nenglish"), + ("hello en", "english", "en", "hello english"), + ("hello en goodbye", "english", "en", "hello english"), + ("hello en en goodbye", "english", "en", "hello en english"), + ("", "english", "en", "english"), + (None, "english", "en", "english"), + ("hello", "", "en", "hello"), + ("hello", None, "en", "hello"), +] + + +@pytest.mark.parametrize("existing_notes, new_notes, split, result", combine_values) +def test_combine_notes(existing_notes, new_notes, split, result): + assert result == comicapi.utils.combine_notes(existing_notes, new_notes, split) + + def test_unique_file(tmp_path): file = tmp_path / "test.cbz" assert file == comicapi.utils.unique_file(file)