Bump version to 0.8.2; enhance image parameter extraction
Some checks failed
Gitea/kapitanbooru-uploader/pipeline/head There was a failure building this commit

This commit is contained in:
2025-03-28 23:49:28 +01:00
parent df83c9dcdc
commit f3e1463b2b
8 changed files with 161 additions and 15 deletions

View File

@ -32,7 +32,7 @@ class ImageBrowser(tk.Tk):
super().__init__()
self.title("Kapitanbooru Uploader")
self.geometry("900x600")
self.version = "0.8.1"
self.version = "0.8.2"
self.acknowledged_version = parse_version(self.version)
self.settings = Settings()

View File

@ -1,6 +1,6 @@
msgid ""
msgstr ""
"Project-Id-Version: Kapitanbooru Uploader 0.8.1\n"
"Project-Id-Version: Kapitanbooru Uploader 0.8.2\n"
"Report-Msgid-Bugs-To: kapitan@mlesniak.pl\n"
"POT-Creation-Date: 2025-03-27 20:47+0100\n"
"Content-Type: text/plain; charset=UTF-8\n"

View File

@ -1,6 +1,6 @@
msgid ""
msgstr ""
"Project-Id-Version: Kapitanbooru Uploader 0.8.1\n"
"Project-Id-Version: Kapitanbooru Uploader 0.8.2\n"
"Report-Msgid-Bugs-To: kapitan@mlesniak.pl\n"
"POT-Creation-Date: 2025-03-27 20:47+0100\n"
"Language: pl\n"

View File

@ -52,7 +52,7 @@ def get_artist_tags(tags_repo: TagsRepo):
# Wzorce i ustawienia związane z tagami
PARAMETERS_PATTERN = re.compile(
r"^(?P<prompt>.*?)\s+(?:Negative prompt:\s+(?P<negative_prompt>.*?)\s+)?Steps:\s+(?P<steps>\d+),\s+Sampler:\s+(?P<sampler>.*?),\s+Schedule type:\s+(?P<schedule_type>.*?),\s+CFG scale:\s+(?P<cfg_scale>.*?),\s+Seed:\s+(?P<seed>.*?),\s+Size:\s+(?P<size>.*?),\s+Model hash:\s+(?P<model_hash>.*?),\s+Model:\s+(?P<model>.*?),\s+(?:Denoising strength:\s+(?P<denoising_strength>.*?),\s+)?(?:Clip skip: (?P<clip_skip>.*?),\s+)?(?:Hires CFG Scale:\s+(?P<hires_cfg_scale>.*?),\s+Hires upscale:\s+(?P<hires_upscale>.*?),\s+Hires steps:\s+(?P<hires_steps>.*?),\s+Hires upscaler:\s+(?P<hires_upscaler>.*?),\s+)?Version:\s+(?P<version>.*?)\s*$",
r"^(?P<prompt>.*?),?\s+(?:Negative prompt:\s+(?P<negative_prompt>.*?)\s+)?Steps:\s+(?P<steps>\d+),\s+Sampler:\s+(?P<sampler>.*?),\s+Schedule type:\s+(?P<schedule_type>.*?),\s+CFG scale:\s+(?P<cfg_scale>.*?),\s+Seed:\s+(?P<seed>.*?),\s+Size:\s+(?P<size>.*?),\s+Model hash:\s+(?P<model_hash>.*?),\s+Model:\s+(?P<model>.*?),\s+(?:Denoising strength:\s+(?P<denoising_strength>.*?),\s+)?(?:Clip skip: (?P<clip_skip>.*?),\s+)?(?:Hires CFG Scale:\s+(?P<hires_cfg_scale>.*?),\s+Hires upscale:\s+(?P<hires_upscale>.*?),\s+Hires steps:\s+(?P<hires_steps>.*?),\s+Hires upscaler:\s+(?P<hires_upscaler>.*?),\s+)?(?:Lora hashes:\s+\"(?P<lora_hashes>.*?)\",\s+)?Version:\s+(?P<version>.*?)\s*$",
re.DOTALL,
)
COEFFICIENT_PATTERN = re.compile(r"^.*?(:\d+|\d+\.\d+)$")
@ -122,25 +122,53 @@ def extract_parameters(img: Image, file_path: str) -> str:
parameters = ""
lower_path = file_path.lower()
# For PNG: use the custom "parameters" field.
# Dla PNG: korzystamy z niestandardowego pola "parameters".
if isinstance(img, PngImagePlugin.PngImageFile):
parameters = img.info.get("parameters", "")
# For JPEG, WebP, and AVIF: extract EXIF UserComment (EXIF tag 37510).
# Dla JPEG, WebP i AVIF: wyciągamy EXIF UserComment (tag 37510) ze zagnieżdżonego słownika (tag 34665).
elif lower_path.endswith((".jpg", ".jpeg", ".webp", ".avif")):
exif_data = img.getexif()
user_comment = exif_data.get(37510)
exif_ifd = exif_data.get_ifd(34665)
user_comment = None
if exif_ifd:
user_comment = exif_ifd.get(37510)
if user_comment:
# UserComment might be stored as bytes; decode to string.
if isinstance(user_comment, bytes):
try:
parameters = user_comment.decode("utf-8", errors="replace")
except Exception:
parameters = str(user_comment)
if isinstance(user_comment, bytes) and len(user_comment) >= 8:
header = user_comment[:8]
comment_bytes = user_comment[8:]
if header.startswith(b'ASCII'):
try:
parameters = comment_bytes.decode("ascii", errors="ignore")
except Exception:
parameters = str(comment_bytes)
elif header.startswith(b'UNICODE'):
# Sprawdzenie obecności BOM w danych
if comment_bytes[:2] in (b'\xff\xfe', b'\xfe\xff'):
try:
parameters = comment_bytes.decode("utf-16", errors="ignore")
except UnicodeDecodeError:
parameters = comment_bytes.decode("utf-16-be", errors="ignore")
else:
try:
parameters = comment_bytes.decode("utf-16-be", errors="ignore")
except UnicodeDecodeError:
parameters = comment_bytes.decode("utf-16", errors="ignore")
elif header.startswith(b'JIS'):
try:
parameters = comment_bytes.decode("shift_jis", errors="ignore")
except Exception:
parameters = str(comment_bytes)
else:
# Fallback: próba dekodowania jako ASCII
try:
parameters = comment_bytes.decode("ascii", errors="ignore")
except Exception:
parameters = str(comment_bytes)
else:
parameters = str(user_comment)
# For GIF: extract the GIF comment.
# Dla GIF: wyciągamy komentarz GIF.
elif lower_path.endswith(".gif"):
comment = img.info.get("comment")
if comment: