This commit is contained in:
2026-01-02 02:28:59 -08:00
parent deb05c0d44
commit 6e9a0c28ff
13 changed files with 1402 additions and 2334 deletions

View File

@@ -218,6 +218,23 @@ class HydrusNetwork(Store):
def get_name(self) -> str:
return self.NAME
def set_relationship(self, alt_hash: str, king_hash: str, kind: str = "alt") -> bool:
"""Persist a relationship via the Hydrus client API for this backend instance."""
try:
alt_norm = str(alt_hash or "").strip().lower()
king_norm = str(king_hash or "").strip().lower()
if len(alt_norm) != 64 or len(king_norm) != 64 or alt_norm == king_norm:
return False
client = getattr(self, "_client", None)
if client is None or not hasattr(client, "set_relationship"):
return False
client.set_relationship(alt_norm, king_norm, str(kind or "alt"))
return True
except Exception:
return False
def add_file(self, file_path: Path, **kwargs: Any) -> str:
"""Upload file to Hydrus with full metadata support.
@@ -284,9 +301,8 @@ class HydrusNetwork(Store):
file_exists = True
break
if file_exists:
log(
f" Duplicate detected - file already in Hydrus with hash: {file_hash}",
file=sys.stderr,
debug(
f"{self._log_prefix()} Duplicate detected - file already in Hydrus with hash: {file_hash}"
)
except Exception:
pass
@@ -301,9 +317,8 @@ class HydrusNetwork(Store):
# Upload file if not already present
if not file_exists:
log(
f"{self._log_prefix()} Uploading: {file_path.name}",
file=sys.stderr
debug(
f"{self._log_prefix()} Uploading: {file_path.name}"
)
response = client.add_file(file_path)
@@ -320,7 +335,7 @@ class HydrusNetwork(Store):
raise Exception(f"Hydrus response missing file hash: {response}")
file_hash = hydrus_hash
log(f"{self._log_prefix()} hash: {file_hash}", file=sys.stderr)
debug(f"{self._log_prefix()} hash: {file_hash}")
# Add tags if provided (both for new and existing files)
if tag_list:
@@ -335,9 +350,8 @@ class HydrusNetwork(Store):
f"{self._log_prefix()} Adding {len(tag_list)} tag(s): {tag_list}"
)
client.add_tag(file_hash, tag_list, service_name)
log(
f"{self._log_prefix()} Tags added via '{service_name}'",
file=sys.stderr
debug(
f"{self._log_prefix()} Tags added via '{service_name}'"
)
except Exception as exc:
log(
@@ -347,9 +361,8 @@ class HydrusNetwork(Store):
# Associate url if provided (both for new and existing files)
if url:
log(
f"{self._log_prefix()} Associating {len(url)} URL(s) with file",
file=sys.stderr
debug(
f"{self._log_prefix()} Associating {len(url)} URL(s) with file"
)
for url in url:
if url: