j
This commit is contained in:
@@ -87,6 +87,7 @@ class Get_Metadata(Cmdlet):
|
||||
url: list[str],
|
||||
hash_value: Optional[str],
|
||||
pages: Optional[int] = None,
|
||||
tag: Optional[List[str]] = None,
|
||||
) -> Dict[str,
|
||||
Any]:
|
||||
"""Build a table row dict with metadata fields."""
|
||||
@@ -142,6 +143,7 @@ class Get_Metadata(Cmdlet):
|
||||
"imported": imported_label,
|
||||
"hash": hash_value,
|
||||
"url": url,
|
||||
"tag": tag or [],
|
||||
"columns": columns,
|
||||
}
|
||||
|
||||
@@ -220,16 +222,30 @@ class Get_Metadata(Cmdlet):
|
||||
|
||||
# Extract title from tags if available
|
||||
title = get_field(result, "title") or file_hash[:16]
|
||||
if not get_field(result, "title"):
|
||||
# Try to get title from tags
|
||||
try:
|
||||
tags, _ = backend.get_tag(file_hash)
|
||||
for tag in tags:
|
||||
if tag.lower().startswith("title:"):
|
||||
title = tag.split(":", 1)[1]
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Get tags from input result
|
||||
item_tags = get_field(result, "tag") or get_field(result, "tags") or []
|
||||
if not isinstance(item_tags, list):
|
||||
item_tags = [str(item_tags)]
|
||||
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)
|
||||
|
||||
# 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", "")
|
||||
@@ -292,6 +308,7 @@ class Get_Metadata(Cmdlet):
|
||||
url=url,
|
||||
hash_value=file_hash,
|
||||
pages=pages,
|
||||
tag=item_tags,
|
||||
)
|
||||
|
||||
table_title = f"get-metadata: {title}" if title else "get-metadata"
|
||||
|
||||
@@ -648,6 +648,34 @@ class Get_Url(Cmdlet):
|
||||
# Prepare metadata for the detail view
|
||||
metadata = extract_item_metadata(result)
|
||||
|
||||
# Enrich the metadata with tags if missing
|
||||
if not metadata.get("Tags"):
|
||||
try:
|
||||
from cmdlet._shared import get_field
|
||||
item_tags = get_field(result, "tag") or get_field(result, "tags") or []
|
||||
row_tags = []
|
||||
if isinstance(item_tags, list):
|
||||
row_tags.extend([str(t) for t in item_tags])
|
||||
elif isinstance(item_tags, str):
|
||||
row_tags.append(item_tags)
|
||||
|
||||
# Also collect from backend
|
||||
if file_hash and store_name:
|
||||
try:
|
||||
# Re-use existing backend variable
|
||||
if backend and hasattr(backend, "get_tag"):
|
||||
b_tags, _ = backend.get_tag(file_hash)
|
||||
if b_tags:
|
||||
row_tags.extend([str(t) for t in b_tags])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if row_tags:
|
||||
row_tags = sorted(list(set(row_tags)))
|
||||
metadata["Tags"] = ", ".join(row_tags)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if file_hash:
|
||||
metadata["Hash"] = file_hash
|
||||
if store_name:
|
||||
|
||||
Reference in New Issue
Block a user