Add YAPF style + ignore, and format tracked Python files

This commit is contained in:
2025-12-29 18:42:02 -08:00
parent c019c00aed
commit 507946a3e4
108 changed files with 11664 additions and 6494 deletions

View File

@@ -12,8 +12,10 @@ from SYS.utils_constant import mime_maps
from Store._base import Store
_HYDRUS_INIT_CHECK_CACHE: dict[tuple[str, str], tuple[bool, Optional[str]]] = {}
_HYDRUS_INIT_CHECK_CACHE: dict[tuple[str,
str],
tuple[bool,
Optional[str]]] = {}
class HydrusNetwork(Store):
@@ -85,21 +87,29 @@ class HydrusNetwork(Store):
if cached is not None:
ok, err = cached
if not ok:
raise RuntimeError(f"Hydrus '{self.NAME}' unavailable: {err or 'Unavailable'}")
raise RuntimeError(
f"Hydrus '{self.NAME}' unavailable: {err or 'Unavailable'}"
)
else:
api_version_url = f"{self.URL}/api_version"
verify_key_url = f"{self.URL}/verify_access_key"
try:
with httpx.Client(timeout=5.0, verify=False, follow_redirects=True) as client:
with httpx.Client(timeout=5.0,
verify=False,
follow_redirects=True) as client:
version_resp = client.get(api_version_url)
version_resp.raise_for_status()
version_payload = version_resp.json()
if not isinstance(version_payload, dict):
raise RuntimeError("Hydrus /api_version returned an unexpected response")
raise RuntimeError(
"Hydrus /api_version returned an unexpected response"
)
verify_resp = client.get(
verify_key_url,
headers={"Hydrus-Client-API-Access-Key": self.API},
headers={
"Hydrus-Client-API-Access-Key": self.API
},
)
verify_resp.raise_for_status()
verify_payload = verify_resp.json()
@@ -115,7 +125,11 @@ class HydrusNetwork(Store):
raise RuntimeError(f"Hydrus '{self.NAME}' unavailable: {err}") from exc
# Create a persistent client for this instance (auth via access key by default).
self._client = HydrusClient(url=self.URL, access_key=self.API, instance_name=self.NAME)
self._client = HydrusClient(
url=self.URL,
access_key=self.API,
instance_name=self.NAME
)
# Best-effort total count (used for startup diagnostics). Avoid heavy payloads.
# Some Hydrus setups appear to return no count via the CBOR client for this endpoint,
@@ -149,7 +163,9 @@ class HydrusNetwork(Store):
"Hydrus-Client-API-Access-Key": self.API,
"Accept": "application/json",
}
with httpx.Client(timeout=5.0, verify=False, follow_redirects=True) as client:
with httpx.Client(timeout=5.0,
verify=False,
follow_redirects=True) as client:
resp = client.get(url, params=params, headers=headers)
resp.raise_for_status()
payload = resp.json()
@@ -165,7 +181,10 @@ class HydrusNetwork(Store):
self.total_count = count_val
return self.total_count
except Exception as exc:
debug(f"{self._log_prefix()} total count (json) unavailable: {exc}", file=sys.stderr)
debug(
f"{self._log_prefix()} total count (json) unavailable: {exc}",
file=sys.stderr
)
# 2) Fallback to the API client (CBOR).
try:
@@ -186,7 +205,10 @@ class HydrusNetwork(Store):
self.total_count = count_val
return self.total_count
except Exception as exc:
debug(f"{self._log_prefix()} total count (client) unavailable: {exc}", file=sys.stderr)
debug(
f"{self._log_prefix()} total count (client) unavailable: {exc}",
file=sys.stderr
)
return self.total_count
@@ -220,13 +242,13 @@ class HydrusNetwork(Store):
# Add title to tags if provided and not already present
if title:
title_tag = f"title:{title}".strip().lower()
if not any(str(candidate).lower().startswith("title:") for candidate in tag_list):
if not any(str(candidate).lower().startswith("title:")
for candidate in tag_list):
tag_list = [title_tag] + list(tag_list)
# Hydrus is lowercase-only tags; normalize here for consistency.
tag_list = [
str(t).strip().lower()
for t in (tag_list or [])
str(t).strip().lower() for t in (tag_list or [])
if isinstance(t, str) and str(t).strip()
]
@@ -257,7 +279,8 @@ class HydrusNetwork(Store):
# Hydrus returns placeholder rows for unknown hashes.
# Only treat as a real duplicate if it has a concrete file_id.
for meta in metas:
if isinstance(meta, dict) and meta.get("file_id") is not None:
if isinstance(meta,
dict) and meta.get("file_id") is not None:
file_exists = True
break
if file_exists:
@@ -278,7 +301,10 @@ 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)
log(
f"{self._log_prefix()} Uploading: {file_path.name}",
file=sys.stderr
)
response = client.add_file(file_path)
# Extract hash from response
@@ -305,16 +331,25 @@ class HydrusNetwork(Store):
service_name = "my tags"
try:
debug(f"{self._log_prefix()} Adding {len(tag_list)} tag(s): {tag_list}")
debug(
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)
log(
f"{self._log_prefix()} Tags added via '{service_name}'",
file=sys.stderr
)
except Exception as exc:
log(f"{self._log_prefix()} ⚠️ Failed to add tags: {exc}", file=sys.stderr)
log(
f"{self._log_prefix()} ⚠️ Failed to add tags: {exc}",
file=sys.stderr
)
# 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
f"{self._log_prefix()} Associating {len(url)} URL(s) with file",
file=sys.stderr
)
for url in url:
if url:
@@ -378,8 +413,11 @@ class HydrusNetwork(Store):
return []
def _iter_url_filtered_metadata(
url_value: str | None, want_any: bool, fetch_limit: int
) -> list[dict[str, Any]]:
url_value: str | None,
want_any: bool,
fetch_limit: int
) -> list[dict[str,
Any]]:
"""Best-effort URL search by scanning Hydrus metadata with include_file_url=True."""
# First try a fast system predicate if Hydrus supports it.
@@ -393,12 +431,14 @@ class HydrusNetwork(Store):
return_file_ids=True,
return_file_count=False,
)
ids = url_search.get("file_ids", []) if isinstance(url_search, dict) else []
ids = url_search.get("file_ids",
[]) if isinstance(url_search,
dict) else []
if isinstance(ids, list):
candidate_file_ids = [
int(x)
for x in ids
if isinstance(x, (int, float, str)) and str(x).strip().isdigit()
int(x) for x in ids
if isinstance(x, (int, float,
str)) and str(x).strip().isdigit()
]
except Exception:
candidate_file_ids = []
@@ -411,9 +451,13 @@ class HydrusNetwork(Store):
return_file_ids=True,
return_file_count=False,
)
ids = everything.get("file_ids", []) if isinstance(everything, dict) else []
ids = everything.get("file_ids",
[]) if isinstance(everything,
dict) else []
if isinstance(ids, list):
candidate_file_ids = [int(x) for x in ids if isinstance(x, (int, float))]
candidate_file_ids = [
int(x) for x in ids if isinstance(x, (int, float))
]
if not candidate_file_ids:
return []
@@ -425,7 +469,7 @@ class HydrusNetwork(Store):
for start in range(0, len(candidate_file_ids), chunk_size):
if len(out) >= fetch_limit:
break
chunk = candidate_file_ids[start : start + chunk_size]
chunk = candidate_file_ids[start:start + chunk_size]
try:
payload = client.fetch_file_metadata(
file_ids=chunk,
@@ -438,7 +482,9 @@ class HydrusNetwork(Store):
except Exception:
continue
metas = payload.get("metadata", []) if isinstance(payload, dict) else []
metas = payload.get("metadata",
[]) if isinstance(payload,
dict) else []
if not isinstance(metas, list):
continue
@@ -480,7 +526,11 @@ class HydrusNetwork(Store):
m = re.search(r"\bextension:([^\s,]+)", query_lower)
if m:
ext_filter = _normalize_ext_filter(m.group(1)) or None
query_lower = re.sub(r"\s*\b(?:ext|extension):[^\s,]+", " ", query_lower)
query_lower = re.sub(
r"\s*\b(?:ext|extension):[^\s,]+",
" ",
query_lower
)
query_lower = re.sub(r"\s{2,}", " ", query_lower).strip().strip(",")
query = query_lower
if ext_filter and not query_lower:
@@ -504,20 +554,27 @@ class HydrusNetwork(Store):
if namespace == "url":
if not pattern or pattern == "*":
metadata_list = _iter_url_filtered_metadata(
None, want_any=True, fetch_limit=int(limit) if limit else 100
None,
want_any=True,
fetch_limit=int(limit) if limit else 100
)
else:
# Fast-path: exact URL via /add_urls/get_url_files when a full URL is provided.
try:
if pattern.startswith("http://") or pattern.startswith("https://"):
if pattern.startswith("http://") or pattern.startswith(
"https://"):
from API.HydrusNetwork import HydrusRequestSpec
spec = HydrusRequestSpec(
method="GET",
endpoint="/add_urls/get_url_files",
query={"url": pattern},
query={
"url": pattern
},
)
response = client._perform_request(spec) # type: ignore[attr-defined]
response = client._perform_request(
spec
) # type: ignore[attr-defined]
hashes: list[str] = []
file_ids: list[int] = []
if isinstance(response, dict):
@@ -526,8 +583,7 @@ class HydrusNetwork(Store):
)
if isinstance(raw_hashes, list):
hashes = [
str(h).strip()
for h in raw_hashes
str(h).strip() for h in raw_hashes
if isinstance(h, str) and str(h).strip()
]
raw_ids = response.get("file_ids")
@@ -548,12 +604,14 @@ class HydrusNetwork(Store):
include_mime=True,
)
metas = (
payload.get("metadata", [])
if isinstance(payload, dict)
else []
payload.get("metadata",
[]) if isinstance(payload,
dict) else []
)
if isinstance(metas, list):
metadata_list = [m for m in metas if isinstance(m, dict)]
metadata_list = [
m for m in metas if isinstance(m, dict)
]
elif hashes:
payload = client.fetch_file_metadata(
hashes=hashes,
@@ -564,19 +622,23 @@ class HydrusNetwork(Store):
include_mime=True,
)
metas = (
payload.get("metadata", [])
if isinstance(payload, dict)
else []
payload.get("metadata",
[]) if isinstance(payload,
dict) else []
)
if isinstance(metas, list):
metadata_list = [m for m in metas if isinstance(m, dict)]
metadata_list = [
m for m in metas if isinstance(m, dict)
]
except Exception:
metadata_list = None
# Fallback: substring scan
if metadata_list is None:
metadata_list = _iter_url_filtered_metadata(
pattern, want_any=False, fetch_limit=int(limit) if limit else 100
pattern,
want_any=False,
fetch_limit=int(limit) if limit else 100
)
# Parse the query into tags
@@ -624,7 +686,8 @@ class HydrusNetwork(Store):
continue
if isinstance(raw_hashes, list):
hashes_out = [
str(h).strip() for h in raw_hashes if isinstance(h, str) and str(h).strip()
str(h).strip() for h in raw_hashes
if isinstance(h, str) and str(h).strip()
]
return ids_out, hashes_out
@@ -676,7 +739,9 @@ class HydrusNetwork(Store):
return []
search_result = client.search_files(
tags=tags, return_hashes=True, return_file_ids=True
tags=tags,
return_hashes=True,
return_file_ids=True
)
file_ids, hashes = _extract_search_ids(search_result)
@@ -694,7 +759,7 @@ class HydrusNetwork(Store):
for start in range(0, len(file_ids), chunk_size):
if len(results) >= limit:
break
chunk = file_ids[start : start + chunk_size]
chunk = file_ids[start:start + chunk_size]
try:
payload = client.fetch_file_metadata(
file_ids=chunk,
@@ -706,7 +771,9 @@ class HydrusNetwork(Store):
)
except Exception:
continue
metas = payload.get("metadata", []) if isinstance(payload, dict) else []
metas = payload.get("metadata",
[]) if isinstance(payload,
dict) else []
if not isinstance(metas, list):
continue
for meta in metas:
@@ -720,7 +787,9 @@ class HydrusNetwork(Store):
for category in mime_maps.values():
for _ext_key, info in category.items():
if mime_type in info.get("mimes", []):
ext = str(info.get("ext", "")).strip().lstrip(".")
ext = str(info.get("ext",
"")
).strip().lstrip(".")
break
if ext:
break
@@ -731,7 +800,8 @@ class HydrusNetwork(Store):
hash_hex = meta.get("hash")
size = meta.get("size", 0)
tags_set = meta.get("tags", {})
tags_set = meta.get("tags",
{})
all_tags: list[str] = []
title = f"Hydrus File {file_id}"
if isinstance(tags_set, dict):
@@ -748,20 +818,24 @@ class HydrusNetwork(Store):
if not tag_l:
continue
all_tags.append(tag_l)
if (
tag_l.startswith("title:")
and title == f"Hydrus File {file_id}"
):
if (tag_l.startswith("title:") and title
== f"Hydrus File {file_id}"):
title = tag_l.split(":", 1)[1].strip()
for _service_name, service_tags in tags_set.items():
if not isinstance(service_tags, dict):
continue
storage_tags = service_tags.get("storage_tags", {})
storage_tags = service_tags.get(
"storage_tags",
{}
)
if isinstance(storage_tags, dict):
for tag_list in storage_tags.values():
_collect(tag_list)
display_tags = service_tags.get("display_tags", [])
display_tags = service_tags.get(
"display_tags",
[]
)
_collect(display_tags)
file_url = f"{self.URL.rstrip('/')}/get_files/file?hash={hash_hex}"
@@ -814,7 +888,8 @@ class HydrusNetwork(Store):
metadata_list = []
# If our free-text searches produce nothing (or nothing survived downstream filtering), fallback to scanning.
if (not metadata_list) and (query_lower != "*") and (":" not in query_lower):
if (not metadata_list) and (query_lower
!= "*") and (":" not in query_lower):
try:
search_result = client.search_files(
tags=["system:everything"],
@@ -858,7 +933,8 @@ class HydrusNetwork(Store):
size = meta.get("size", 0)
# Get tags for this file and extract title
tags_set = meta.get("tags", {})
tags_set = meta.get("tags",
{})
all_tags = []
title = f"Hydrus File {file_id}" # Default fallback
all_tags_str = "" # For substring matching
@@ -880,14 +956,16 @@ class HydrusNetwork(Store):
continue
all_tags.append(tag_l)
all_tags_str += " " + tag_l
if tag_l.startswith("title:") and title == f"Hydrus File {file_id}":
if tag_l.startswith("title:"
) and title == f"Hydrus File {file_id}":
title = tag_l.split(":", 1)[1].strip()
for _service_name, service_tags in tags_set.items():
if not isinstance(service_tags, dict):
continue
storage_tags = service_tags.get("storage_tags", {})
storage_tags = service_tags.get("storage_tags",
{})
if isinstance(storage_tags, dict):
for tag_list in storage_tags.values():
_collect(tag_list)
@@ -939,7 +1017,8 @@ class HydrusNetwork(Store):
# Free-form search: check if search terms match title or FREEFORM tags.
# Do NOT implicitly match other namespace tags (except title:).
freeform_tags = [
t for t in all_tags if isinstance(t, str) and t and (":" not in t)
t for t in all_tags
if isinstance(t, str) and t and (":" not in t)
]
searchable_text = (title + " " + " ".join(freeform_tags)).lower()
@@ -1019,13 +1098,17 @@ class HydrusNetwork(Store):
return False
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
debug(f"{self._log_prefix()} delete_file: invalid file hash '{file_identifier}'")
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
debug(
f"{self._log_prefix()} delete_file: invalid file hash '{file_identifier}'"
)
return False
reason = kwargs.get("reason")
reason_text = (
str(reason).strip() if isinstance(reason, str) and reason.strip() else None
str(reason).strip() if isinstance(reason,
str) and reason.strip() else None
)
# 1) Delete file
@@ -1035,7 +1118,9 @@ class HydrusNetwork(Store):
try:
client.clear_file_deletion_record([file_hash])
except Exception as exc:
debug(f"{self._log_prefix()} delete_file: clear_file_deletion_record failed: {exc}")
debug(
f"{self._log_prefix()} delete_file: clear_file_deletion_record failed: {exc}"
)
return True
except Exception as exc:
@@ -1078,11 +1163,13 @@ class HydrusNetwork(Store):
# Extract title from tags
title = f"Hydrus_{file_hash[:12]}"
tags_payload = meta.get("tags", {})
tags_payload = meta.get("tags",
{})
if isinstance(tags_payload, dict):
for service_data in tags_payload.values():
if isinstance(service_data, dict):
display_tags = service_data.get("display_tags", {})
display_tags = service_data.get("display_tags",
{})
if isinstance(display_tags, dict):
current_tags = display_tags.get("0", [])
if isinstance(current_tags, list):
@@ -1096,7 +1183,8 @@ class HydrusNetwork(Store):
# Hydrus may return mime as an int enum, or sometimes a human label.
mime_val = meta.get("mime")
filetype_human = (
meta.get("filetype_human") or meta.get("mime_human") or meta.get("mime_string")
meta.get("filetype_human") or meta.get("mime_human")
or meta.get("mime_string")
)
# Determine ext: prefer Hydrus metadata ext, then filetype_human (when it looks like an ext),
@@ -1170,14 +1258,16 @@ class HydrusNetwork(Store):
except Exception:
dur_int = None
raw_urls = meta.get("known_urls") or meta.get("urls") or meta.get("url") or []
raw_urls = meta.get("known_urls") or meta.get("urls") or meta.get("url"
) or []
url_list: list[str] = []
if isinstance(raw_urls, str):
s = raw_urls.strip()
url_list = [s] if s else []
elif isinstance(raw_urls, list):
url_list = [
str(u).strip() for u in raw_urls if isinstance(u, str) and str(u).strip()
str(u).strip() for u in raw_urls
if isinstance(u, str) and str(u).strip()
]
return {
@@ -1212,8 +1302,11 @@ class HydrusNetwork(Store):
from API import HydrusNetwork as hydrus_wrapper
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
debug(f"{self._log_prefix()} get_tags: invalid file hash '{file_identifier}'")
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
debug(
f"{self._log_prefix()} get_tags: invalid file hash '{file_identifier}'"
)
return [], "unknown"
# Get Hydrus client and service info
@@ -1224,17 +1317,23 @@ class HydrusNetwork(Store):
# Fetch file metadata
payload = client.fetch_file_metadata(
hashes=[file_hash], include_service_keys_to_tags=True, include_file_url=False
hashes=[file_hash],
include_service_keys_to_tags=True,
include_file_url=False
)
items = payload.get("metadata") if isinstance(payload, dict) else None
if not isinstance(items, list) or not items:
debug(f"{self._log_prefix()} get_tags: no metadata for hash {file_hash}")
debug(
f"{self._log_prefix()} get_tags: no metadata for hash {file_hash}"
)
return [], "unknown"
meta = items[0] if isinstance(items[0], dict) else None
if not isinstance(meta, dict) or meta.get("file_id") is None:
debug(f"{self._log_prefix()} get_tags: invalid metadata for hash {file_hash}")
debug(
f"{self._log_prefix()} get_tags: invalid metadata for hash {file_hash}"
)
return [], "unknown"
# Extract tags using service name
@@ -1261,14 +1360,16 @@ class HydrusNetwork(Store):
return False
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
debug(f"{self._log_prefix()} add_tag: invalid file hash '{file_identifier}'")
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
debug(
f"{self._log_prefix()} add_tag: invalid file hash '{file_identifier}'"
)
return False
service_name = kwargs.get("service_name") or "my tags"
incoming_tags = [
str(t).strip().lower()
for t in (tags or [])
str(t).strip().lower() for t in (tags or [])
if isinstance(t, str) and str(t).strip()
]
if not incoming_tags:
@@ -1316,13 +1417,17 @@ class HydrusNetwork(Store):
return False
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
debug(f"{self._log_prefix()} delete_tag: invalid file hash '{file_identifier}'")
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
debug(
f"{self._log_prefix()} delete_tag: invalid file hash '{file_identifier}'"
)
return False
service_name = kwargs.get("service_name") or "my tags"
raw_list = list(tags) if isinstance(tags, (list, tuple)) else [str(tags)]
tag_list = [
str(t).strip().lower() for t in raw_list if isinstance(t, str) and str(t).strip()
str(t).strip().lower() for t in raw_list
if isinstance(t, str) and str(t).strip()
]
if not tag_list:
return False
@@ -1338,16 +1443,22 @@ class HydrusNetwork(Store):
client = self._client
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
return []
payload = client.fetch_file_metadata(hashes=[file_hash], include_file_url=False)
payload = client.fetch_file_metadata(
hashes=[file_hash],
include_file_url=False
)
items = payload.get("metadata") if isinstance(payload, dict) else None
if not isinstance(items, list) or not items:
return []
meta = items[0] if isinstance(items[0], dict) else {}
meta = items[0] if isinstance(items[0],
dict) else {}
raw_urls: Any = meta.get("known_urls") or meta.get("urls") or meta.get("url") or []
raw_urls: Any = meta.get("known_urls"
) or meta.get("urls") or meta.get("url") or []
if isinstance(raw_urls, str):
val = raw_urls.strip()
return [val] if val else []
@@ -1434,7 +1545,8 @@ class HydrusNetwork(Store):
return {}
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
return {}
payload = client.fetch_file_metadata(hashes=[file_hash], include_notes=True)
@@ -1447,14 +1559,23 @@ class HydrusNetwork(Store):
notes_payload = meta.get("notes")
if isinstance(notes_payload, dict):
return {str(k): str(v or "") for k, v in notes_payload.items() if str(k).strip()}
return {
str(k): str(v or "")
for k, v in notes_payload.items() if str(k).strip()
}
return {}
except Exception as exc:
debug(f"{self._log_prefix()} get_note failed: {exc}")
return {}
def set_note(self, file_identifier: str, name: str, text: str, **kwargs: Any) -> bool:
def set_note(
self,
file_identifier: str,
name: str,
text: str,
**kwargs: Any
) -> bool:
"""Set a named note for a Hydrus file (default note service only)."""
try:
client = self._client
@@ -1463,7 +1584,8 @@ class HydrusNetwork(Store):
return False
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
return False
note_name = str(name or "").strip()
@@ -1471,7 +1593,10 @@ class HydrusNetwork(Store):
return False
note_text = str(text or "")
client.set_notes(file_hash, {note_name: note_text})
client.set_notes(file_hash,
{
note_name: note_text
})
return True
except Exception as exc:
debug(f"{self._log_prefix()} set_note failed: {exc}")
@@ -1486,7 +1611,8 @@ class HydrusNetwork(Store):
return False
file_hash = str(file_identifier or "").strip().lower()
if len(file_hash) != 64 or not all(ch in "0123456789abcdef" for ch in file_hash):
if len(file_hash) != 64 or not all(ch in "0123456789abcdef"
for ch in file_hash):
return False
note_name = str(name or "").strip()
@@ -1501,7 +1627,10 @@ class HydrusNetwork(Store):
@staticmethod
def _extract_tags_from_hydrus_meta(
meta: Dict[str, Any], service_key: Optional[str], service_name: str
meta: Dict[str,
Any],
service_key: Optional[str],
service_name: str
) -> List[str]:
"""Extract current tags from Hydrus metadata dict.
@@ -1521,7 +1650,10 @@ class HydrusNetwork(Store):
# Prefer display_tags (Hydrus computes siblings/parents)
display = svc_data.get("display_tags")
if isinstance(display, list) and display:
return [str(t) for t in display if isinstance(t, (str, bytes)) and str(t).strip()]
return [
str(t) for t in display
if isinstance(t, (str, bytes)) and str(t).strip()
]
# Fallback to storage_tags status '0' (current)
storage = svc_data.get("storage_tags")
@@ -1529,7 +1661,8 @@ class HydrusNetwork(Store):
current_list = storage.get("0") or storage.get(0)
if isinstance(current_list, list):
return [
str(t) for t in current_list if isinstance(t, (str, bytes)) and str(t).strip()
str(t) for t in current_list
if isinstance(t, (str, bytes)) and str(t).strip()
]
return []