This commit is contained in:
2026-01-22 02:04:15 -08:00
parent c74a1b264f
commit 3d571b007b
2 changed files with 81 additions and 103 deletions

View File

@@ -36,94 +36,72 @@ CMDLET = Cmdlet(
def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int: def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
pass # Help
if should_show_help(_args):
log(f"Cmdlet: {CMDLET.name}\nSummary: {CMDLET.summary}\nUsage: {CMDLET.usage}")
return 0
_add_relationship( # Parse -query and -store override
{ override_query: str | None = None
"hash": related_hash, override_store: str | None = None
"type": entry_type, args_list = list(_args)
"title": related_title, i = 0
"path": None, while i < len(args_list):
"store": str(store_name), a = args_list[i]
} low = str(a).lower()
) if low in {"-query", "--query", "query"} and i + 1 < len(args_list):
override_query = str(args_list[i + 1]).strip()
i += 2
continue
if low in {"-store", "--store", "store"} and i + 1 < len(args_list):
override_store = str(args_list[i + 1]).strip()
i += 2
continue
i += 1
# Reverse relationships (alts pointing to this hash) override_hash: str | None = (
try: sh.parse_single_hash_query(override_query) if override_query else None
reverse_children = db.find_files_pointing_to_hash(hash_hex) )
except Exception: if override_query and not override_hash:
reverse_children = [] log('get-relationship requires -query "hash:<sha256>"', file=sys.stderr)
return 1
for child in reverse_children or []: # Handle @N selection which creates a list
child_hash = normalize_hash(str(child.get("hash") or "")) if isinstance(result, list):
rel_type = str(child.get("type") or "").strip().lower() if len(result) == 0:
if not child_hash or child_hash == hash_hex: result = None
continue elif len(result) > 1 and not override_hash:
log(
'get-relationship expects a single item; select one row (e.g. @1) or pass -query "hash:<sha256>"',
file=sys.stderr,
)
return 1
else:
result = result[0]
child_title = child_hash[:16] + "..." # Initialize results collection
try: found_relationships = [] # List of dicts: {hash, type, title, path, store}
child_tags = db.get_tags(child_hash) source_title = "Unknown"
for t in child_tags:
if isinstance(t,
str) and t.lower().startswith("title:"):
child_title = t[6:].strip()
break
except Exception:
pass
entry_type = "alt" if rel_type == "alt" else ( # Store/hash-first subject resolution
rel_type or "related" store_name: Optional[str] = override_store
) if not store_name:
_add_relationship( store_name = get_field(result, "store")
{
"hash": child_hash,
"type": entry_type,
"title": child_title,
"path": None,
"store": str(store_name),
}
)
# Siblings (alts that share the same king) hash_hex = (
for king_hash in king_hashes: normalize_hash(override_hash)
try: if override_hash else normalize_hash(get_hash_for_operation(None, result))
siblings = db.find_files_pointing_to_hash(king_hash) )
except Exception:
siblings = []
for sib in siblings or []:
sib_hash = normalize_hash(str(sib.get("hash") or ""))
sib_type = str(sib.get("type") or "").strip().lower()
if not sib_hash or sib_hash in {hash_hex,
king_hash}:
continue
sib_title = sib_hash[:16] + "..." if not source_title or source_title == "Unknown":
try: source_title = (
sib_tags = db.get_tags(sib_hash) get_field(result, "title") or get_field(result, "name")
for t in sib_tags: or (hash_hex[:16] + "..." if hash_hex else "Unknown")
if isinstance( )
t,
str) and t.lower().startswith("title:"):
sib_title = t[6:].strip()
break
except Exception:
pass
entry_type = "alt" if sib_type == "alt" else ( if not hash_hex:
sib_type or "related" log('get-relationship requires -query "hash:<sha256>"', file=sys.stderr)
) return 1
_add_relationship(
{
"hash": sib_hash,
"type": entry_type,
"title": sib_title,
"path": None,
"store": str(store_name),
}
)
except Exception as e:
log(f"Error checking store relationships: {e}", file=sys.stderr)
# Fetch Hydrus relationships if we have a hash. # Fetch Hydrus relationships if we have a hash.

View File

@@ -1473,31 +1473,31 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
name, items = result name, items = result
current_playlist_name = name current_playlist_name = name
# Queue items (replacing current playlist) # Queue items (replacing current playlist)
if items: if items:
_queue_items( _queue_items(
items, items,
clear_first=True, clear_first=True,
config=config, config=config,
start_opts=start_opts start_opts=start_opts
) )
else: else:
# Empty playlist, just clear # Empty playlist, just clear
_send_ipc_command( _send_ipc_command(
{ {
"command": ["playlist-clear"] "command": ["playlist-clear"]
}, },
silent=True silent=True
) )
# Switch to list mode to show the result # Switch to list mode to show the result
list_mode = True list_mode = True
index_arg = None index_arg = None
# Fall through to list logic # Fall through to list logic
except ValueError: except ValueError:
debug(f"Invalid playlist ID: {index_arg}") debug(f"Invalid playlist ID: {index_arg}")
return 1 return 1
# If we deleted or didn't have an index, list playlists # If we deleted or didn't have an index, list playlists
if not index_arg: if not index_arg: