m
This commit is contained in:
@@ -88,6 +88,7 @@ class Get_Metadata(Cmdlet):
|
||||
hash_value: Optional[str],
|
||||
pages: Optional[int] = None,
|
||||
tag: Optional[List[str]] = None,
|
||||
ext: Optional[str] = None,
|
||||
) -> Dict[str,
|
||||
Any]:
|
||||
"""Build a table row dict with metadata fields."""
|
||||
@@ -136,6 +137,7 @@ class Get_Metadata(Cmdlet):
|
||||
"path": path,
|
||||
"store": store,
|
||||
"mime": mime,
|
||||
"ext": ext or "",
|
||||
"size_bytes": size_int,
|
||||
"duration_seconds": dur_int,
|
||||
"pages": pages_int,
|
||||
@@ -230,25 +232,35 @@ class Get_Metadata(Cmdlet):
|
||||
else:
|
||||
item_tags = [str(t) for t in item_tags]
|
||||
|
||||
# Try to enrich tags and title from backend
|
||||
try:
|
||||
backend_tags, _ = backend.get_tag(file_hash)
|
||||
if backend_tags:
|
||||
for t in backend_tags:
|
||||
ts = str(t)
|
||||
if ts not in item_tags:
|
||||
item_tags.append(ts)
|
||||
# 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
|
||||
|
||||
# Also check for title tag if we don't have a title yet
|
||||
if not get_field(result, "title") and ts.lower().startswith("title:"):
|
||||
parts = ts.split(":", 1)
|
||||
if len(parts) > 1:
|
||||
title = parts[1].strip()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Extract metadata fields
|
||||
mime_type = metadata.get("mime") or metadata.get("ext", "")
|
||||
file_ext = metadata.get("ext", "") # Extract file extension separately
|
||||
file_size = metadata.get("size")
|
||||
duration_seconds = metadata.get("duration")
|
||||
if duration_seconds is None:
|
||||
@@ -309,6 +321,7 @@ class Get_Metadata(Cmdlet):
|
||||
hash_value=file_hash,
|
||||
pages=pages,
|
||||
tag=item_tags,
|
||||
ext=file_ext,
|
||||
)
|
||||
|
||||
table_title = f"get-metadata: {title}" if title else "get-metadata"
|
||||
|
||||
Reference in New Issue
Block a user