updating and refining plugin system refactor
This commit is contained in:
+18
-17
@@ -4,6 +4,7 @@ import re
|
||||
import sys
|
||||
import tempfile
|
||||
import shutil
|
||||
from collections.abc import Mapping, Sequence as SequenceABC
|
||||
from collections import deque
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Literal, Optional, Sequence, Tuple
|
||||
@@ -169,7 +170,7 @@ class HydrusNetwork(Store):
|
||||
api_key: Hydrus Client API access key
|
||||
url: Hydrus client URL (e.g., 'http://192.168.1.230:45869')
|
||||
"""
|
||||
from API.HydrusNetwork import HydrusNetwork as HydrusClient
|
||||
from plugins.hydrusnetwork.api import HydrusNetwork as HydrusClient
|
||||
|
||||
if instance_name is None and NAME is not None:
|
||||
instance_name = str(NAME)
|
||||
@@ -713,7 +714,7 @@ class HydrusNetwork(Store):
|
||||
"""Best-effort URL search by scanning Hydrus metadata with include_file_url=True."""
|
||||
|
||||
try:
|
||||
from API.HydrusNetwork import _generate_hydrus_url_variants
|
||||
from plugins.hydrusnetwork.api import _generate_hydrus_url_variants
|
||||
except Exception:
|
||||
_generate_hydrus_url_variants = None # type: ignore[assignment]
|
||||
|
||||
@@ -808,7 +809,7 @@ class HydrusNetwork(Store):
|
||||
self._has_url_predicate = True
|
||||
except Exception as exc:
|
||||
try:
|
||||
from API.HydrusNetwork import HydrusRequestError
|
||||
from plugins.hydrusnetwork.api import HydrusRequestError
|
||||
|
||||
if isinstance(exc, HydrusRequestError) and getattr(exc, "status", None) == 400:
|
||||
self._has_url_predicate = False
|
||||
@@ -1844,7 +1845,7 @@ class HydrusNetwork(Store):
|
||||
extracted_tags = self._extract_tags_from_hydrus_meta(
|
||||
meta,
|
||||
service_key=None,
|
||||
service_name="my tags",
|
||||
service_name=None,
|
||||
)
|
||||
for raw_tag in extracted_tags:
|
||||
tag_text = str(raw_tag or "").strip()
|
||||
@@ -2201,7 +2202,7 @@ class HydrusNetwork(Store):
|
||||
return []
|
||||
|
||||
try:
|
||||
from API.HydrusNetwork import HydrusRequestSpec, _generate_hydrus_url_variants
|
||||
from plugins.hydrusnetwork.api import HydrusRequestSpec, _generate_hydrus_url_variants
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
@@ -2339,7 +2340,7 @@ class HydrusNetwork(Store):
|
||||
try:
|
||||
return client.get_url_info(u) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
from API.HydrusNetwork import HydrusRequestSpec
|
||||
from plugins.hydrusnetwork.api import HydrusRequestSpec
|
||||
|
||||
spec = HydrusRequestSpec(
|
||||
method="GET",
|
||||
@@ -2563,7 +2564,7 @@ class HydrusNetwork(Store):
|
||||
meta: Dict[str,
|
||||
Any],
|
||||
service_key: Optional[str],
|
||||
service_name: str
|
||||
service_name: Optional[str]
|
||||
) -> List[str]:
|
||||
"""Extract current tags from Hydrus metadata dict.
|
||||
|
||||
@@ -2571,7 +2572,7 @@ class HydrusNetwork(Store):
|
||||
Falls back to storage_tags status '0' (current).
|
||||
"""
|
||||
tags_payload = meta.get("tags")
|
||||
if not isinstance(tags_payload, dict):
|
||||
if not isinstance(tags_payload, Mapping):
|
||||
return []
|
||||
|
||||
desired_service_name = str(service_name or "").strip().lower()
|
||||
@@ -2593,20 +2594,20 @@ class HydrusNetwork(Store):
|
||||
out.append(cleaned)
|
||||
|
||||
def _collect_current(container: Any, out: List[str]) -> None:
|
||||
if isinstance(container, list):
|
||||
if isinstance(container, SequenceABC) and not isinstance(container, (str, bytes, bytearray, Mapping)):
|
||||
for tag in container:
|
||||
_append_tag(out, tag)
|
||||
return
|
||||
if isinstance(container, dict):
|
||||
if isinstance(container, Mapping):
|
||||
current = container.get("0")
|
||||
if current is None:
|
||||
current = container.get(0)
|
||||
if isinstance(current, list):
|
||||
if isinstance(current, SequenceABC) and not isinstance(current, (str, bytes, bytearray, Mapping)):
|
||||
for tag in current:
|
||||
_append_tag(out, tag)
|
||||
|
||||
def _collect_service_data(service_data: Any, out: List[str]) -> None:
|
||||
if not isinstance(service_data, dict):
|
||||
if not isinstance(service_data, Mapping):
|
||||
return
|
||||
|
||||
display = (
|
||||
@@ -2630,7 +2631,7 @@ class HydrusNetwork(Store):
|
||||
|
||||
if not collected and desired_service_name:
|
||||
for maybe_service in tags_payload.values():
|
||||
if not isinstance(maybe_service, dict):
|
||||
if not isinstance(maybe_service, Mapping):
|
||||
continue
|
||||
svc_name = str(
|
||||
maybe_service.get("service_name")
|
||||
@@ -2642,11 +2643,11 @@ class HydrusNetwork(Store):
|
||||
|
||||
names_map = tags_payload.get("service_keys_to_names")
|
||||
statuses_map = tags_payload.get("service_keys_to_statuses_to_tags")
|
||||
if isinstance(statuses_map, dict):
|
||||
if isinstance(statuses_map, Mapping):
|
||||
keys_to_collect: List[str] = []
|
||||
if desired_service_key:
|
||||
keys_to_collect.append(desired_service_key)
|
||||
if desired_service_name and isinstance(names_map, dict):
|
||||
if desired_service_name and isinstance(names_map, Mapping):
|
||||
for raw_key, raw_name in names_map.items():
|
||||
if str(raw_name or "").strip().lower() == desired_service_name:
|
||||
keys_to_collect.append(str(raw_key))
|
||||
@@ -2663,7 +2664,7 @@ class HydrusNetwork(Store):
|
||||
_collect_service_data(maybe_service, collected)
|
||||
|
||||
top_level_tags = meta.get("tags_flat")
|
||||
if isinstance(top_level_tags, list):
|
||||
if isinstance(top_level_tags, SequenceABC) and not isinstance(top_level_tags, (str, bytes, bytearray, Mapping)):
|
||||
_collect_current(top_level_tags, collected)
|
||||
|
||||
deduped: List[str] = []
|
||||
@@ -2682,7 +2683,7 @@ class HydrusNetwork(Store):
|
||||
tags = HydrusNetwork._extract_tags_from_hydrus_meta(
|
||||
meta,
|
||||
service_key=None,
|
||||
service_name="my tags",
|
||||
service_name=None,
|
||||
)
|
||||
|
||||
normalized_tags: List[str] = []
|
||||
|
||||
Reference in New Issue
Block a user