From 65f87ef4b674107819b1f87fc44e0d2c9d1a1c15 Mon Sep 17 00:00:00 2001 From: DogmaDragon <103123951+DogmaDragon@users.noreply.github.com> Date: Wed, 2 Sep 2026 20:55:43 +0300 Subject: [PATCH] Refactor config import from yaml to py --- .../comicInfoExtractor/comicInfoExtractor.py | 21 ++----------------- .../comicInfoExtractor/comicInfoExtractor.yml | 2 +- plugins/comicInfoExtractor/config.py | 11 ++++++++++ plugins/comicInfoExtractor/config.yml | 12 ----------- 4 files changed, 14 insertions(+), 32 deletions(-) create mode 100644 plugins/comicInfoExtractor/config.py delete mode 100644 plugins/comicInfoExtractor/config.yml diff --git a/plugins/comicInfoExtractor/comicInfoExtractor.py b/plugins/comicInfoExtractor/comicInfoExtractor.py index c3e21a64..442884f4 100644 --- a/plugins/comicInfoExtractor/comicInfoExtractor.py +++ b/plugins/comicInfoExtractor/comicInfoExtractor.py @@ -1,12 +1,11 @@ import stashapi.log as log from stashapi.stashapp import StashInterface import stashapi.marker_parse as mp -import yaml import json -import os import sys import xml.etree.ElementTree as ET import zipfile +from config import ImportList as CONFIG_IMPORT_LIST per_page = 100 @@ -122,23 +121,7 @@ def processAll(): FRAGMENT_SERVER = json_input["server_connection"] stash = StashInterface(FRAGMENT_SERVER) -# Load Config -with open( - os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.yml"), "r" -) as f: - try: - config = yaml.safe_load(f) - except yaml.YAMLError as exc: - log.error("Could not load config.yml: " + str(exc)) - sys.exit(1) -try: - ImportList = config["ImportList"] -except KeyError as key: - log.error( - str(key) - + " is not defined in config.yml, but is needed for this script to proceed" - ) - sys.exit(1) +ImportList = CONFIG_IMPORT_LIST.copy() if "mode" in json_input["args"]: PLUGIN_ARGS = json_input["args"]["mode"] diff --git a/plugins/comicInfoExtractor/comicInfoExtractor.yml b/plugins/comicInfoExtractor/comicInfoExtractor.yml index 535f2e81..c2683559 100644 --- a/plugins/comicInfoExtractor/comicInfoExtractor.yml +++ b/plugins/comicInfoExtractor/comicInfoExtractor.yml @@ -1,6 +1,6 @@ name: Comic Info Extractor description: Extract the metadata from cbz with the Comicrack standard (ComicInfo.xml) -version: 0.1 +version: 0.2 url: https://discourse.stashapp.cc/t/comic-info-extractor/1372 exec: - python diff --git a/plugins/comicInfoExtractor/config.py b/plugins/comicInfoExtractor/config.py new file mode 100644 index 00000000..879d45ce --- /dev/null +++ b/plugins/comicInfoExtractor/config.py @@ -0,0 +1,11 @@ +# ImportList maps ComicInfo.xml fields to Stash gallery fields. +# Fields that refer to different types of media are resolved by name and created if necessary. +# Fields that can contain multiple values are expected to be comma-separated strings. + +ImportList = { + "Genre": "tags", + "Title": "title", + "Writer": "studio", + "Year": "date", + "Summary": "details", +} \ No newline at end of file diff --git a/plugins/comicInfoExtractor/config.yml b/plugins/comicInfoExtractor/config.yml deleted file mode 100644 index 235e8524..00000000 --- a/plugins/comicInfoExtractor/config.yml +++ /dev/null @@ -1,12 +0,0 @@ -#pkgignore -#ImportList is a dictionary -#that matches an xml Attribute from ComicInfo.xml to the according value in stash (using the graphql naming) -#Fields that refer to different types of media are resolved by name and created if necessary (tags, studio, performers) -#Fields that can contain multiple values (tags, performers) will be expected as a comma separated string, like -#Outdoor, Blonde -ImportList: - Genre: tags - Title: title - Writer: studio - Year: date - Summary: details