from __future__ import annotations from typing import Any, Dict, Sequence import json from . import register import models import pipeline as ctx from API import HydrusNetwork as hydrus_wrapper from ._shared import Cmdlet, CmdletArg, SharedArgs, normalize_hash, get_hash_for_operation, fetch_hydrus_metadata, get_field, should_show_help from SYS.logger import log CMDLET = Cmdlet( name="get-note", summary="List notes on a Hydrus file.", usage="get-note [-hash ]", arg=[ SharedArgs.HASH, ], detail=[ "- Prints notes by service and note name.", ], ) @register(["get-note", "get-notes", "get_note"]) # aliases def get_notes(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int: # Help if should_show_help(args): log(json.dumps(CMDLET, ensure_ascii=False, indent=2)) return 0 from ._shared import parse_cmdlet_args, get_hash_for_operation, fetch_hydrus_metadata parsed = parse_cmdlet_args(args, CMDLET) override_hash = parsed.get("hash") hash_hex = get_hash_for_operation(override_hash, result) if not hash_hex: log("Selected result does not include a Hydrus hash") return 1 meta, error_code = fetch_hydrus_metadata(config, hash_hex, include_service_keys_to_tags=False, include_notes=True) if error_code != 0: return error_code notes = {} if isinstance(meta, dict): # Hydrus returns service_keys_to_tags; for notes we expect 'service_names_to_notes' in modern API notes = meta.get('notes') or meta.get('service_names_to_notes') or {} if notes: ctx.emit("Notes:") # Print flattened: service -> (name: text) if isinstance(notes, dict) and any(isinstance(v, dict) for v in notes.values()): for svc, mapping in notes.items(): ctx.emit(f"- {svc}:") if isinstance(mapping, dict): for k, v in mapping.items(): ctx.emit(f" • {k}: {str(v).strip()}") elif isinstance(notes, dict): for k, v in notes.items(): ctx.emit(f"- {k}: {str(v).strip()}") else: ctx.emit("No notes found.") return 0