updated old legacy store names
This commit is contained in:
+68
-25
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, Sequence, Optional
|
||||
from typing import Any, Dict, Sequence, Optional, List
|
||||
import json
|
||||
import sys
|
||||
|
||||
@@ -235,6 +235,50 @@ class Get_Metadata(Cmdlet):
|
||||
columns_to_add.append(("Duration(s)", ""))
|
||||
add_row_columns(table, columns_to_add)
|
||||
|
||||
@staticmethod
|
||||
def _extract_metadata_tags(metadata: Dict[str, Any]) -> List[str]:
|
||||
tags: List[str] = []
|
||||
|
||||
def _append(tag_value: Any) -> None:
|
||||
text = str(tag_value or "").strip()
|
||||
if text and text not in tags:
|
||||
tags.append(text)
|
||||
|
||||
def _walk_tag_values(value: Any) -> None:
|
||||
if isinstance(value, str):
|
||||
_append(value)
|
||||
return
|
||||
if isinstance(value, dict):
|
||||
for nested_value in value.values():
|
||||
_walk_tag_values(nested_value)
|
||||
return
|
||||
if isinstance(value, (list, tuple, set)):
|
||||
for nested_value in value:
|
||||
_walk_tag_values(nested_value)
|
||||
|
||||
raw_tags = metadata.get("tags")
|
||||
if isinstance(raw_tags, dict):
|
||||
for service_data in raw_tags.values():
|
||||
if not isinstance(service_data, dict):
|
||||
continue
|
||||
matched_tag_key = False
|
||||
for key, tag_mapping in service_data.items():
|
||||
if "tag" not in str(key).strip().lower():
|
||||
continue
|
||||
matched_tag_key = True
|
||||
_walk_tag_values(tag_mapping)
|
||||
if not matched_tag_key:
|
||||
_walk_tag_values(service_data)
|
||||
elif isinstance(raw_tags, list):
|
||||
for tag_value in raw_tags:
|
||||
_append(tag_value)
|
||||
|
||||
for key in ("tags_flat", "tag"):
|
||||
raw_value = metadata.get(key)
|
||||
_walk_tag_values(raw_value)
|
||||
|
||||
return tags
|
||||
|
||||
def run(self, result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
"""Execute get-metadata cmdlet - retrieve and display file metadata.
|
||||
|
||||
@@ -309,30 +353,29 @@ class Get_Metadata(Cmdlet):
|
||||
else:
|
||||
item_tags = [str(t) for t in item_tags]
|
||||
|
||||
# Extract tags from metadata response instead of making a separate get_tag() request
|
||||
# This prevents duplicate API calls to Hydrus (metadata already includes tags)
|
||||
metadata_tags = metadata.get("tags")
|
||||
if isinstance(metadata_tags, dict):
|
||||
# metadata["tags"] is {service_key: {service_data}}
|
||||
for service_data in metadata_tags.values():
|
||||
if isinstance(service_data, dict):
|
||||
display_tags = service_data.get("display_tags", {})
|
||||
if isinstance(display_tags, dict):
|
||||
# display_tags is typically {status: tag_list}
|
||||
for tag_list in display_tags.values():
|
||||
if isinstance(tag_list, list):
|
||||
for t in tag_list:
|
||||
ts = str(t) if t else ""
|
||||
if ts and ts not in item_tags:
|
||||
item_tags.append(ts)
|
||||
# Check for title tag
|
||||
if not get_field(result, "title") and ts.lower().startswith("title:"):
|
||||
parts = ts.split(":", 1)
|
||||
if len(parts) > 1:
|
||||
title = parts[1].strip()
|
||||
break # Only use first status level
|
||||
if any(t for t in item_tags if str(t).lower().startswith("title:")):
|
||||
break # Found title tag, stop searching services
|
||||
metadata_tags = self._extract_metadata_tags(metadata)
|
||||
if not metadata_tags:
|
||||
get_tag = getattr(backend, "get_tag", None)
|
||||
if callable(get_tag):
|
||||
try:
|
||||
backend_tags, _source = get_tag(file_hash, config=config)
|
||||
metadata_tags = [
|
||||
str(tag) for tag in (backend_tags or [])
|
||||
if str(tag or "").strip()
|
||||
]
|
||||
except Exception:
|
||||
metadata_tags = []
|
||||
|
||||
for tag_value in metadata_tags:
|
||||
tag_text = str(tag_value or "").strip()
|
||||
if not tag_text:
|
||||
continue
|
||||
if tag_text not in item_tags:
|
||||
item_tags.append(tag_text)
|
||||
if not get_field(result, "title") and tag_text.lower().startswith("title:"):
|
||||
parts = tag_text.split(":", 1)
|
||||
if len(parts) > 1:
|
||||
title = parts[1].strip()
|
||||
|
||||
|
||||
# Extract metadata fields
|
||||
|
||||
Reference in New Issue
Block a user