updated plugin refactor and added FTP and SCP plugins , also hydrusnetwork plugin migration

This commit is contained in:
2026-04-27 21:17:53 -07:00
parent bfd5c20dc3
commit 8685fbb723
24 changed files with 3650 additions and 405 deletions
+16 -37
View File
@@ -5,12 +5,12 @@ import sys
from SYS.detail_view_helpers import create_detail_view, prepare_detail_metadata
from SYS.logger import log
from ProviderCore.registry import get_plugin
from SYS.result_table_helpers import add_row_columns
from SYS.selection_builder import build_hash_store_selection
from SYS.result_publication import publish_result_table
from SYS import pipeline as ctx
from API import HydrusNetwork as hydrus_wrapper
from . import _shared as sh
Cmdlet = sh.Cmdlet
@@ -22,7 +22,6 @@ get_hash_for_operation = sh.get_hash_for_operation
fetch_hydrus_metadata = sh.fetch_hydrus_metadata
should_show_help = sh.should_show_help
get_field = sh.get_field
from Store import Store
CMDLET = Cmdlet(
name="get-relationship",
@@ -109,6 +108,7 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
return 1
# Fetch Hydrus relationships if we have a hash.
hydrus_provider = get_plugin("hydrusnetwork", config)
hash_hex = (
normalize_hash(override_hash)
@@ -118,29 +118,18 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
if hash_hex:
try:
client = None
store_label = "hydrus"
backend_obj = None
if store_name:
# Store specified: do not fall back to a global/default Hydrus client.
store_label = str(store_name)
try:
store = Store(config)
backend_obj = store[str(store_name)]
candidate = getattr(backend_obj, "_client", None)
if candidate is not None and hasattr(candidate,
"get_file_relationships"):
client = candidate
except Exception:
client = None
if client is None:
if hydrus_provider is None:
log(
f"Hydrus client unavailable for store '{store_name}'",
file=sys.stderr
)
return 1
relationships = hydrus_provider.get_relationships(hash_hex, store_name=store_name)
else:
client = hydrus_wrapper.get_client(config)
relationships = hydrus_provider.get_relationships(hash_hex) if hydrus_provider is not None else None
def _resolve_related_title(rel_hash: str) -> str:
"""Best-effort resolve a Hydrus hash to a human title.
@@ -154,22 +143,15 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
if not h:
return str(rel_hash)
# Prefer backend tag extraction when available.
if backend_obj is not None and hasattr(backend_obj, "get_tag"):
# Prefer provider-backed title resolution when available.
if hydrus_provider is not None:
try:
tag_result = backend_obj.get_tag(h)
tags = (
tag_result[0]
if isinstance(tag_result,
tuple) and tag_result else tag_result
resolved_title = hydrus_provider.get_title(
h,
store_name=store_label if store_name else None,
)
if isinstance(tags, list):
for t in tags:
if isinstance(t,
str) and t.lower().startswith("title:"):
val = t.split(":", 1)[1].strip()
if val:
return val
if isinstance(resolved_title, str) and resolved_title.strip():
return resolved_title.strip()
except Exception:
pass
@@ -179,7 +161,6 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
config,
h,
store_name=store_label if store_name else None,
hydrus_client=client,
include_service_keys_to_tags=True,
include_file_url=False,
include_duration=False,
@@ -224,14 +205,12 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
return h[:16] + "..."
if client:
rel = client.get_file_relationships(hash_hex)
if rel:
file_rels = rel.get("file_relationships",
if relationships:
file_rels = relationships.get("file_relationships",
{})
this_file_rels = file_rels.get(hash_hex)
this_file_rels = file_rels.get(hash_hex)
if this_file_rels:
if this_file_rels:
# Map Hydrus relationship IDs to names.
# For /manage_file_relationships/get_file_relationships, the Hydrus docs define:
# 0=potential duplicates, 1=false positives, 3=alternates, 8=duplicates