style: apply ruff auto-fixes

This commit is contained in:
2026-01-19 03:14:30 -08:00
parent 3ab122a55d
commit a961ac3ce7
72 changed files with 2477 additions and 2871 deletions

View File

@@ -1894,6 +1894,61 @@ class HydrusNetwork(Store):
debug(f"{self._log_prefix()} add_url_bulk failed: {exc}")
return False
def add_tags_bulk(self, items: List[tuple[str, List[str]]], *, service_name: str | None = None) -> bool:
"""Bulk add tags to multiple Hydrus files.
Groups files by identical tag-sets and uses the Hydrus `mutate_tags_by_key`
call (when a service key is available) to reduce the number of API calls.
Falls back to per-hash `add_tag` calls if necessary.
"""
try:
client = self._client
if client is None:
debug(f"{self._log_prefix()} add_tags_bulk: client unavailable")
return False
# Group by canonical tag set (sorted tuple) to batch identical additions
buckets: dict[tuple[str, ...], list[str]] = {}
for file_identifier, tags in items or []:
h = str(file_identifier or "").strip().lower()
if len(h) != 64:
continue
tlist = [str(t).strip().lower() for t in (tags or []) if isinstance(t, str) and str(t).strip()]
if not tlist:
continue
key = tuple(sorted(tlist))
buckets.setdefault(key, []).append(h)
if not buckets:
return False
svc = service_name or "my tags"
service_key = self._get_service_key(svc)
any_success = False
for tag_tuple, hashes in buckets.items():
try:
if service_key:
# Mutate tags for many hashes in a single request
client.mutate_tags_by_key(hashes=hashes, service_key=service_key, add_tags=list(tag_tuple))
any_success = True
continue
except Exception as exc:
debug(f"{self._log_prefix()} add_tags_bulk mutate failed for tags {tag_tuple}: {exc}")
# Fallback: apply per-hash add_tag
for h in hashes:
try:
client.add_tag(h, list(tag_tuple), svc)
any_success = True
except Exception:
continue
return any_success
except Exception as exc:
debug(f"{self._log_prefix()} add_tags_bulk failed: {exc}")
return False
def delete_url(self, file_identifier: str, url: List[str], **kwargs: Any) -> bool:
"""Delete one or more url from a Hydrus file."""
try: