mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-19 00:03:36 +00:00
Persist last Jellyfin index report
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .config import settings
|
||||
|
||||
|
||||
def report_path() -> Path:
|
||||
return settings.data_dir / "last-index-report.json"
|
||||
|
||||
|
||||
def save_index_report(report: dict[str, Any]) -> None:
|
||||
path = report_path()
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
tmp = path.with_suffix(path.suffix + ".tmp")
|
||||
tmp.write_text(
|
||||
json.dumps(report, ensure_ascii=False, indent=2),
|
||||
encoding="utf-8",
|
||||
)
|
||||
tmp.replace(path)
|
||||
|
||||
|
||||
def load_index_report() -> dict[str, Any]:
|
||||
path = report_path()
|
||||
if not path.is_file():
|
||||
return {
|
||||
"available": False,
|
||||
"items": [],
|
||||
"summary": {},
|
||||
}
|
||||
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError):
|
||||
return {
|
||||
"available": False,
|
||||
"items": [],
|
||||
"summary": {},
|
||||
}
|
||||
|
||||
if not isinstance(data, dict):
|
||||
return {
|
||||
"available": False,
|
||||
"items": [],
|
||||
"summary": {},
|
||||
}
|
||||
|
||||
data.setdefault("available", True)
|
||||
data.setdefault("items", [])
|
||||
data.setdefault("summary", {})
|
||||
return data
|
||||
Reference in New Issue
Block a user