m
This commit is contained in:
@@ -2021,8 +2021,16 @@ def extract_item_metadata(item: Any) -> Dict[str, Any]:
|
|||||||
if ext:
|
if ext:
|
||||||
out["Ext"] = ext
|
out["Ext"] = ext
|
||||||
else:
|
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
|
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)
|
size = extract_size_bytes_value(item)
|
||||||
if size is not None:
|
if size is not None:
|
||||||
@@ -2114,8 +2122,8 @@ class ItemDetailView(Table):
|
|||||||
if val is not None and val != "":
|
if val is not None and val != "":
|
||||||
details_table.add_row(f"{key}:", str(val))
|
details_table.add_row(f"{key}:", str(val))
|
||||||
has_details = True
|
has_details = True
|
||||||
elif key in ["Url", "Relations"]:
|
elif key in ["Url", "Relations", "Ext"]:
|
||||||
# User requested <null> for these if blank
|
# Show <null> for these important identifier fields if blank
|
||||||
details_table.add_row(f"{key}:", "[dim]<null>[/dim]")
|
details_table.add_row(f"{key}:", "[dim]<null>[/dim]")
|
||||||
has_details = True
|
has_details = True
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class Get_Metadata(Cmdlet):
|
|||||||
hash_value: Optional[str],
|
hash_value: Optional[str],
|
||||||
pages: Optional[int] = None,
|
pages: Optional[int] = None,
|
||||||
tag: Optional[List[str]] = None,
|
tag: Optional[List[str]] = None,
|
||||||
|
ext: Optional[str] = None,
|
||||||
) -> Dict[str,
|
) -> Dict[str,
|
||||||
Any]:
|
Any]:
|
||||||
"""Build a table row dict with metadata fields."""
|
"""Build a table row dict with metadata fields."""
|
||||||
@@ -136,6 +137,7 @@ class Get_Metadata(Cmdlet):
|
|||||||
"path": path,
|
"path": path,
|
||||||
"store": store,
|
"store": store,
|
||||||
"mime": mime,
|
"mime": mime,
|
||||||
|
"ext": ext or "",
|
||||||
"size_bytes": size_int,
|
"size_bytes": size_int,
|
||||||
"duration_seconds": dur_int,
|
"duration_seconds": dur_int,
|
||||||
"pages": pages_int,
|
"pages": pages_int,
|
||||||
@@ -230,25 +232,35 @@ class Get_Metadata(Cmdlet):
|
|||||||
else:
|
else:
|
||||||
item_tags = [str(t) for t in item_tags]
|
item_tags = [str(t) for t in item_tags]
|
||||||
|
|
||||||
# Try to enrich tags and title from backend
|
# Extract tags from metadata response instead of making a separate get_tag() request
|
||||||
try:
|
# This prevents duplicate API calls to Hydrus (metadata already includes tags)
|
||||||
backend_tags, _ = backend.get_tag(file_hash)
|
metadata_tags = metadata.get("tags")
|
||||||
if backend_tags:
|
if isinstance(metadata_tags, dict):
|
||||||
for t in backend_tags:
|
# metadata["tags"] is {service_key: {service_data}}
|
||||||
ts = str(t)
|
for service_data in metadata_tags.values():
|
||||||
if ts not in item_tags:
|
if isinstance(service_data, dict):
|
||||||
item_tags.append(ts)
|
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
|
# Extract metadata fields
|
||||||
mime_type = metadata.get("mime") or metadata.get("ext", "")
|
mime_type = metadata.get("mime") or metadata.get("ext", "")
|
||||||
|
file_ext = metadata.get("ext", "") # Extract file extension separately
|
||||||
file_size = metadata.get("size")
|
file_size = metadata.get("size")
|
||||||
duration_seconds = metadata.get("duration")
|
duration_seconds = metadata.get("duration")
|
||||||
if duration_seconds is None:
|
if duration_seconds is None:
|
||||||
@@ -309,6 +321,7 @@ class Get_Metadata(Cmdlet):
|
|||||||
hash_value=file_hash,
|
hash_value=file_hash,
|
||||||
pages=pages,
|
pages=pages,
|
||||||
tag=item_tags,
|
tag=item_tags,
|
||||||
|
ext=file_ext,
|
||||||
)
|
)
|
||||||
|
|
||||||
table_title = f"get-metadata: {title}" if title else "get-metadata"
|
table_title = f"get-metadata: {title}" if title else "get-metadata"
|
||||||
|
|||||||
Reference in New Issue
Block a user