m
This commit is contained in:
@@ -2021,8 +2021,16 @@ def extract_item_metadata(item: Any) -> Dict[str, Any]:
|
||||
if ext:
|
||||
out["Ext"] = ext
|
||||
else:
|
||||
e = data.get("ext") or data.get("extension")
|
||||
e = data.get("ext") or data.get("extension") or data.get("file_ext")
|
||||
if e: out["Ext"] = e
|
||||
else:
|
||||
# Fallback: try to extract from metadata nested in ResultModel
|
||||
if ResultModel is not None and isinstance(item, ResultModel):
|
||||
meta = item.metadata or {}
|
||||
ext_from_meta = meta.get("ext") or meta.get("extension") or meta.get("file_ext")
|
||||
if ext_from_meta:
|
||||
out["Ext"] = ext_from_meta
|
||||
|
||||
|
||||
size = extract_size_bytes_value(item)
|
||||
if size is not None:
|
||||
@@ -2114,8 +2122,8 @@ class ItemDetailView(Table):
|
||||
if val is not None and val != "":
|
||||
details_table.add_row(f"{key}:", str(val))
|
||||
has_details = True
|
||||
elif key in ["Url", "Relations"]:
|
||||
# User requested <null> for these if blank
|
||||
elif key in ["Url", "Relations", "Ext"]:
|
||||
# Show <null> for these important identifier fields if blank
|
||||
details_table.add_row(f"{key}:", "[dim]<null>[/dim]")
|
||||
has_details = True
|
||||
|
||||
|
||||
@@ -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