From 848c1741fe6c57859b6f955ddfeeb59181bce859 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Thu, 31 Jul 2025 14:15:22 +0800 Subject: [PATCH] feat: add parsing for 'air' field in Civitai resources to enhance metadata extraction. Fixes #322 --- py/recipes/parsers/automatic.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/py/recipes/parsers/automatic.py b/py/recipes/parsers/automatic.py index fff4b4c3..3c3534e0 100644 --- a/py/recipes/parsers/automatic.py +++ b/py/recipes/parsers/automatic.py @@ -181,13 +181,30 @@ class AutomaticMetadataParser(RecipeMetadataParser): # First use Civitai resources if available (more reliable source) if metadata.get("civitai_resources"): for resource in metadata.get("civitai_resources", []): + # --- Added: Parse 'air' field if present --- + air = resource.get("air") + if air: + # Format: urn:air:sdxl:lora:civitai:1221007@1375651 + # Or: urn:air:sdxl:checkpoint:civitai:623891@2019115 + air_pattern = r"urn:air:[^:]+:(?P[^:]+):civitai:(?P\d+)@(?P\d+)" + air_match = re.match(air_pattern, air) + if air_match: + air_type = air_match.group("type") + air_modelId = int(air_match.group("modelId")) + air_modelVersionId = int(air_match.group("modelVersionId")) + # checkpoint/lycoris/lora/hypernet + resource["type"] = air_type + resource["modelId"] = air_modelId + resource["modelVersionId"] = air_modelVersionId + # --- End added --- + if resource.get("type") in ["lora", "lycoris", "hypernet"] and resource.get("modelVersionId"): # Initialize lora entry lora_entry = { 'id': resource.get("modelVersionId", 0), 'modelId': resource.get("modelId", 0), 'name': resource.get("modelName", "Unknown LoRA"), - 'version': resource.get("modelVersionName", ""), + 'version': resource.get("modelVersionName", resource.get("versionName", "")), 'type': resource.get("type", "lora"), 'weight': round(float(resource.get("weight", 1.0)), 2), 'existsLocally': False,