2024-04-26 21:12:06 -07:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from comicapi import utils
|
|
|
|
from comicapi.genericmetadata import GenericMetadata
|
|
|
|
from comictaggerlib import ctversion
|
|
|
|
from comictaggerlib.cbltransformer import CBLTransformer
|
|
|
|
from comictaggerlib.ctsettings.settngs_namespace import SettngsNS
|
|
|
|
from comictalker.talker_utils import cleanup_html
|
|
|
|
|
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
def prepare_metadata(md: GenericMetadata, new_md: GenericMetadata, config: SettngsNS) -> GenericMetadata:
|
|
|
|
if config.Metadata_Options__apply_transform_on_import:
|
|
|
|
new_md = CBLTransformer(new_md, config).apply()
|
2024-04-26 21:12:06 -07:00
|
|
|
|
|
|
|
final_md = md.copy()
|
2024-06-20 16:47:10 -07:00
|
|
|
if config.Auto_Tag__clear_tags:
|
2024-04-26 21:12:06 -07:00
|
|
|
final_md = GenericMetadata()
|
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
final_md.overlay(new_md, config.Metadata_Options__metadata_merge, config.Metadata_Options__metadata_merge_lists)
|
2024-06-21 19:53:30 -07:00
|
|
|
|
|
|
|
issue_id = ""
|
|
|
|
if final_md.issue_id:
|
|
|
|
issue_id = f" [Issue ID {final_md.issue_id}]"
|
|
|
|
|
|
|
|
origin = ""
|
2024-06-20 16:47:10 -07:00
|
|
|
if final_md.data_origin is not None:
|
2024-06-21 19:53:30 -07:00
|
|
|
origin = f" using info from {final_md.data_origin.name}"
|
|
|
|
notes = f"Tagged with ComicTagger {ctversion.version}{origin} on {datetime.now():%Y-%m-%d %H:%M:%S}.{issue_id}"
|
2024-04-26 21:12:06 -07:00
|
|
|
|
2024-06-20 16:47:10 -07:00
|
|
|
if config.Auto_Tag__auto_imprint:
|
2024-04-27 16:43:51 -07:00
|
|
|
final_md.fix_publisher()
|
2024-04-28 13:53:41 -07:00
|
|
|
|
2024-04-27 16:43:51 -07:00
|
|
|
return final_md.replace(
|
2024-04-28 13:53:41 -07:00
|
|
|
is_empty=False,
|
|
|
|
notes=utils.combine_notes(final_md.notes, notes, "Tagged with ComicTagger"),
|
2024-06-21 19:53:30 -07:00
|
|
|
description=cleanup_html(final_md.description, config.Metadata_Options__remove_html_tables) or None,
|
2024-04-27 16:43:51 -07:00
|
|
|
)
|