f
This commit is contained in:
@@ -907,10 +907,13 @@ class HydrusNetwork:
|
||||
file_ids: Sequence[int] | None = None,
|
||||
hashes: Sequence[str] | None = None,
|
||||
include_service_keys_to_tags: bool = True,
|
||||
include_tag_services: bool = False,
|
||||
include_file_services: bool = False,
|
||||
include_file_url: bool = False,
|
||||
include_duration: bool = True,
|
||||
include_size: bool = True,
|
||||
include_mime: bool = False,
|
||||
include_is_trashed: bool = False,
|
||||
include_notes: bool = False,
|
||||
) -> dict[str,
|
||||
Any]:
|
||||
@@ -929,6 +932,16 @@ class HydrusNetwork:
|
||||
include_service_keys_to_tags,
|
||||
lambda v: "true" if v else None,
|
||||
),
|
||||
(
|
||||
"include_tag_services",
|
||||
include_tag_services,
|
||||
lambda v: "true" if v else None,
|
||||
),
|
||||
(
|
||||
"include_file_services",
|
||||
include_file_services,
|
||||
lambda v: "true" if v else None,
|
||||
),
|
||||
("include_file_url",
|
||||
include_file_url, lambda v: "true" if v else None),
|
||||
("include_duration",
|
||||
@@ -937,6 +950,11 @@ class HydrusNetwork:
|
||||
include_size, lambda v: "true" if v else None),
|
||||
("include_mime",
|
||||
include_mime, lambda v: "true" if v else None),
|
||||
(
|
||||
"include_is_trashed",
|
||||
include_is_trashed,
|
||||
lambda v: "true" if v else None,
|
||||
),
|
||||
("include_notes",
|
||||
include_notes, lambda v: "true" if v else None),
|
||||
]
|
||||
@@ -1831,6 +1849,48 @@ def get_tag_service_key(client: HydrusNetwork,
|
||||
if not isinstance(services, dict):
|
||||
return None
|
||||
|
||||
def _normalize_name(value: Any) -> str:
|
||||
if isinstance(value, bytes):
|
||||
try:
|
||||
return value.decode("utf-8", errors="ignore").strip().lower()
|
||||
except Exception:
|
||||
return ""
|
||||
try:
|
||||
return str(value or "").strip().lower()
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
def _normalize_service_key(value: Any) -> Optional[str]:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, bytes):
|
||||
# Hydrus service keys are raw bytes; API expects hex.
|
||||
try:
|
||||
hex_text = value.hex()
|
||||
except Exception:
|
||||
return None
|
||||
return hex_text if (len(hex_text) == 64 and all(ch in "0123456789abcdef" for ch in hex_text)) else None
|
||||
if isinstance(value, str):
|
||||
text = value.strip().lower()
|
||||
if text.startswith("0x"):
|
||||
text = text[2:]
|
||||
if len(text) == 64 and all(ch in "0123456789abcdef" for ch in text):
|
||||
return text
|
||||
return None
|
||||
try:
|
||||
text = str(value).strip().lower()
|
||||
except Exception:
|
||||
return None
|
||||
if text.startswith("0x"):
|
||||
text = text[2:]
|
||||
if len(text) == 64 and all(ch in "0123456789abcdef" for ch in text):
|
||||
return text
|
||||
return None
|
||||
|
||||
target_name = _normalize_name(fallback_name)
|
||||
if not target_name:
|
||||
target_name = "my tags"
|
||||
|
||||
# Hydrus returns services grouped by type; walk all lists and match on name
|
||||
for group in services.values():
|
||||
if not isinstance(group, list):
|
||||
@@ -1838,10 +1898,13 @@ def get_tag_service_key(client: HydrusNetwork,
|
||||
for item in group:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
name = str(item.get("name") or "").strip().lower()
|
||||
key = item.get("service_key") or item.get("key")
|
||||
if name == fallback_name.lower() and key:
|
||||
return str(key)
|
||||
name = _normalize_name(item.get("name"))
|
||||
if name != target_name:
|
||||
continue
|
||||
key_raw = item.get("service_key") or item.get("key")
|
||||
normalized_key = _normalize_service_key(key_raw)
|
||||
if normalized_key:
|
||||
return normalized_key
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user