lkjlkj
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
This cmdlet retrieves tags for a selected result, supporting both:
|
||||
- Hydrus Network (for files with hash)
|
||||
- Local sidecar files (.tags)
|
||||
- Local sidecar files (.tag)
|
||||
|
||||
In interactive mode: navigate with numbers, add/delete tags
|
||||
In pipeline mode: display tags as read-only table, emit as structured JSON
|
||||
@@ -89,9 +89,9 @@ def _emit_tags_as_table(
|
||||
from result_table import ResultTable
|
||||
|
||||
# Create ResultTable with just tag column (no title)
|
||||
table_title = "Tags"
|
||||
table_title = "Tag"
|
||||
if item_title:
|
||||
table_title = f"Tags: {item_title}"
|
||||
table_title = f"Tag: {item_title}"
|
||||
if file_hash:
|
||||
table_title += f" [{file_hash[:8]}]"
|
||||
|
||||
@@ -195,19 +195,19 @@ def _rename_file_if_title_tag(media: Optional[Path], tags_added: List[str]) -> b
|
||||
return False
|
||||
|
||||
# Build sidecar paths BEFORE renaming the file
|
||||
old_sidecar = Path(str(file_path) + '.tags')
|
||||
new_sidecar = Path(str(new_file_path) + '.tags')
|
||||
old_sidecar = Path(str(file_path) + '.tag')
|
||||
new_sidecar = Path(str(new_file_path) + '.tag')
|
||||
|
||||
# Rename file
|
||||
try:
|
||||
file_path.rename(new_file_path)
|
||||
log(f"Renamed file: {old_name} → {new_name}")
|
||||
|
||||
# Rename .tags sidecar if it exists
|
||||
# Rename .tag sidecar if it exists
|
||||
if old_sidecar.exists():
|
||||
try:
|
||||
old_sidecar.rename(new_sidecar)
|
||||
log(f"Renamed sidecar: {old_name}.tags → {new_name}.tags")
|
||||
log(f"Renamed sidecar: {old_name}.tag → {new_name}.tag")
|
||||
except Exception as e:
|
||||
log(f"Failed to rename sidecar: {e}", file=sys.stderr)
|
||||
|
||||
@@ -232,7 +232,7 @@ def _apply_result_updates_from_tags(result: Any, tag_list: List[str]) -> None:
|
||||
|
||||
|
||||
def _handle_title_rename(old_path: Path, tags_list: List[str]) -> Optional[Path]:
|
||||
"""If a title: tag is present, rename the file and its .tags sidecar to match.
|
||||
"""If a title: tag is present, rename the file and its .tag sidecar to match.
|
||||
|
||||
Returns the new path if renamed, otherwise returns None.
|
||||
"""
|
||||
@@ -267,10 +267,10 @@ def _handle_title_rename(old_path: Path, tags_list: List[str]) -> Optional[Path]
|
||||
old_path.rename(new_path)
|
||||
log(f"Renamed file: {old_name} → {new_name}", file=sys.stderr)
|
||||
|
||||
# Rename the .tags sidecar if it exists
|
||||
old_tags_path = old_path.parent / (old_name + '.tags')
|
||||
# Rename the .tag sidecar if it exists
|
||||
old_tags_path = old_path.parent / (old_name + '.tag')
|
||||
if old_tags_path.exists():
|
||||
new_tags_path = old_path.parent / (new_name + '.tags')
|
||||
new_tags_path = old_path.parent / (new_name + '.tag')
|
||||
if new_tags_path.exists():
|
||||
log(f"Warning: Target sidecar already exists: {new_tags_path.name}", file=sys.stderr)
|
||||
else:
|
||||
@@ -368,14 +368,12 @@ def _write_sidecar(p: Path, media: Path, tag_list: List[str], url: List[str], ha
|
||||
return media
|
||||
|
||||
|
||||
|
||||
def _emit_tag_payload(source: str, tags_list: List[str], *, hash_value: Optional[str], extra: Optional[Dict[str, Any]] = None, store_label: Optional[str] = None) -> int:
|
||||
"""Emit tags as structured payload to pipeline.
|
||||
|
||||
Also emits individual tag objects to _PIPELINE_LAST_ITEMS so they can be selected by index.
|
||||
"""
|
||||
"""Emit tag values as structured payload to pipeline."""
|
||||
payload: Dict[str, Any] = {
|
||||
"source": source,
|
||||
"tags": list(tags_list),
|
||||
"tag": list(tags_list),
|
||||
"count": len(tags_list),
|
||||
}
|
||||
if hash_value:
|
||||
@@ -388,11 +386,9 @@ def _emit_tag_payload(source: str, tags_list: List[str], *, hash_value: Optional
|
||||
if store_label:
|
||||
label = store_label
|
||||
elif ctx.get_stage_context() is not None:
|
||||
label = "tags"
|
||||
label = "tag"
|
||||
if label:
|
||||
ctx.store_value(label, payload)
|
||||
if ctx.get_stage_context() is not None and label.lower() != "tags":
|
||||
ctx.store_value("tags", payload)
|
||||
|
||||
# Emit individual TagItem objects so they can be selected by bare index
|
||||
# When in pipeline, emit individual TagItem objects
|
||||
@@ -1065,7 +1061,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
return 1
|
||||
output = {
|
||||
"title": title,
|
||||
"tags": tags,
|
||||
"tag": tags,
|
||||
"formats": [(label, fmt_id) for label, fmt_id in formats],
|
||||
"playlist_items": playlist_items,
|
||||
}
|
||||
@@ -1080,7 +1076,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
|
||||
# Prefer identifier tags (ISBN/OLID/etc.) when available; fallback to title/filename
|
||||
identifier_tags: List[str] = []
|
||||
result_tags = get_field(result, "tags", None)
|
||||
result_tags = get_field(result, "tag", None)
|
||||
if isinstance(result_tags, list):
|
||||
identifier_tags = [str(t) for t in result_tags if isinstance(t, (str, bytes))]
|
||||
|
||||
@@ -1160,7 +1156,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
row.add_column("Album", item.get("album", ""))
|
||||
row.add_column("Year", item.get("year", ""))
|
||||
payload = {
|
||||
"tags": tags,
|
||||
"tag": tags,
|
||||
"provider": provider.name,
|
||||
"title": item.get("title"),
|
||||
"artist": item.get("artist"),
|
||||
@@ -1169,7 +1165,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
"hash": hash_for_payload,
|
||||
"store": store_for_payload,
|
||||
"extra": {
|
||||
"tags": tags,
|
||||
"tag": tags,
|
||||
"provider": provider.name,
|
||||
},
|
||||
}
|
||||
@@ -1236,13 +1232,13 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
# Build a subject payload representing the file whose tags are being shown
|
||||
subject_store = get_field(result, "store", None) or store_name
|
||||
subject_payload: Dict[str, Any] = {
|
||||
"tags": list(current),
|
||||
"tag": list(current),
|
||||
"title": item_title,
|
||||
"name": item_title,
|
||||
"store": subject_store,
|
||||
"service_name": service_name,
|
||||
"extra": {
|
||||
"tags": list(current),
|
||||
"tag": list(current),
|
||||
},
|
||||
}
|
||||
if file_hash:
|
||||
@@ -1288,9 +1284,9 @@ class Get_Tag(Cmdlet):
|
||||
"""Initialize get-tag cmdlet."""
|
||||
super().__init__(
|
||||
name="get-tag",
|
||||
summary="Get tags from Hydrus or local sidecar metadata",
|
||||
summary="Get tag values from Hydrus or local sidecar metadata",
|
||||
usage="get-tag [-hash <sha256>] [--store <key>] [--emit] [-scrape <url|provider>]",
|
||||
alias=["tags"],
|
||||
alias=[],
|
||||
arg=[
|
||||
SharedArgs.HASH,
|
||||
CmdletArg(
|
||||
|
||||
Reference in New Issue
Block a user