This commit is contained in:
2026-01-19 06:24:09 -08:00
parent a961ac3ce7
commit 7ddf0065d1
45 changed files with 627 additions and 411 deletions

View File

@@ -452,7 +452,7 @@ class HTTPClient:
else:
kwargs["headers"] = self._get_headers()
last_exception = None
last_exception: Exception | None = None
for attempt in range(self.retries):
self._debug_panel(
@@ -875,7 +875,7 @@ def download_direct_file(
pass
tags: List[str] = []
if extract_ytdlp_tags:
if extract_ytdlp_tags is not None:
try:
tags = extract_ytdlp_tags(info)
except Exception as exc:
@@ -884,7 +884,7 @@ def download_direct_file(
if not any(str(t).startswith("title:") for t in tags):
info["title"] = str(filename)
tags = []
if extract_ytdlp_tags:
if extract_ytdlp_tags is not None:
try:
tags = extract_ytdlp_tags(info)
except Exception as exc:
@@ -1135,7 +1135,7 @@ class AsyncHTTPClient:
else:
kwargs["headers"] = self._get_headers()
last_exception = None
last_exception: Exception | None = None
for attempt in range(self.retries):
try:

View File

@@ -2066,9 +2066,9 @@ def _derive_title(
"original_display_filename",
"original_filename",
):
value = entry.get(key)
if isinstance(value, str):
cleaned = value.strip()
raw_val = entry.get(key)
if isinstance(raw_val, str):
cleaned = raw_val.strip()
if cleaned:
return cleaned
return None
@@ -2444,7 +2444,7 @@ def fetch_hydrus_metadata_by_url(payload: Dict[str, Any]) -> Dict[str, Any]:
matched_url = None
normalized_reported = None
seen: Set[str] = set()
queue = deque()
queue: deque[str] = deque()
for variant in _generate_hydrus_url_variants(url):
queue.append(variant)
if not queue:
@@ -2486,11 +2486,11 @@ def fetch_hydrus_metadata_by_url(payload: Dict[str, Any]) -> Dict[str, Any]:
if isinstance(raw_hashes, list):
for item in raw_hashes:
try:
normalized = _normalize_hash(item)
norm_hash = _normalize_hash(item)
except ValueError:
continue
if normalized:
response_hashes_list.append(normalized)
if norm_hash:
response_hashes_list.append(norm_hash)
raw_ids = response.get("file_ids") or response.get("file_id")
if isinstance(raw_ids, list):
for item in raw_ids:
@@ -2510,12 +2510,13 @@ def fetch_hydrus_metadata_by_url(payload: Dict[str, Any]) -> Dict[str, Any]:
continue
status_hash = entry.get("hash") or entry.get("file_hash")
if status_hash:
norm_status: Optional[str] = None
try:
normalized = _normalize_hash(status_hash)
norm_status = _normalize_hash(status_hash)
except ValueError:
normalized = None
if normalized:
response_hashes_list.append(normalized)
pass
if norm_status:
response_hashes_list.append(norm_status)
status_id = entry.get("file_id") or entry.get("fileid")
if status_id is not None:
try:

3
API/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
"""Medeia API helpers that power external integrations."""
__all__ = []

View File

@@ -55,6 +55,7 @@ def _db_retry(max_attempts: int = 6, base_sleep: float = 0.1):
return _decorator
# Try to import optional dependencies
mutagen: Any
try:
import mutagen
except ImportError:
@@ -72,12 +73,12 @@ try:
METADATA_AVAILABLE = True
except ImportError:
_read_sidecar_metadata = None
_derive_sidecar_path = None
write_tags = None
write_tags_to_file = None
embed_metadata_in_file = None
read_tags_from_file = None
_read_sidecar_metadata = None # type: ignore
_derive_sidecar_path = None # type: ignore
write_tags = None # type: ignore
write_tags_to_file = None # type: ignore
embed_metadata_in_file = None # type: ignore
read_tags_from_file = None # type: ignore
METADATA_AVAILABLE = False
# Media extensions to index
@@ -219,7 +220,7 @@ class API_folder_store:
"""
self.library_root = expand_path(library_root).resolve()
self.db_path = self.library_root / self.DB_NAME
self.connection: Optional[sqlite3.Connection] = None
self.connection: sqlite3.Connection = None # type: ignore
# Use the shared lock
self._db_lock = self._shared_db_lock
mm_debug(f"[folder-db] init: root={self.library_root} db={self.db_path}")
@@ -3818,7 +3819,7 @@ def migrate_all(library_root: Path,
db),
}
finally:
if should_close:
if should_close and db is not None:
db.close()