feat: add NFO scan after rescan and year caching

- Add nfo_scan_after_rescan config option (default: true)
- Implement year caching in AniworldLoader and EnhancedAniWorldLoader
- Make get_year abstract method in base provider
- Run NFO validation/creation after scheduled rescan completes
- Add _YearDict cache to avoid re-extracting year from HTML
This commit is contained in:
2026-06-05 18:15:41 +02:00
parent 8b21f1243f
commit e74b04c1ee
10 changed files with 839 additions and 35 deletions

View File

@@ -11,7 +11,7 @@ from __future__ import annotations
import logging
from datetime import datetime, timedelta, timezone
from typing import List, Optional
from typing import Dict, List, Optional
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.cron import CronTrigger
@@ -261,6 +261,9 @@ class SchedulerService:
"auto_download_after_rescan": (
self._config.auto_download_after_rescan if self._config else False
),
"nfo_scan_after_rescan": (
self._config.nfo_scan_after_rescan if self._config else True
),
"last_run": (
self._last_scan_time.isoformat()
if self._last_scan_time
@@ -375,7 +378,19 @@ class SchedulerService:
# 1. Main library rescan
await self._run_rescan()
# 2. Auto-download (if enabled)
# 2. NFO scan (if enabled)
if self._config and self._config.nfo_scan_after_rescan:
try:
nfo_result = await self._run_nfo_scan()
await self._broadcast("nfo_scan_started", {
"created": nfo_result.get("created", 0),
"updated": nfo_result.get("updated", 0),
})
except Exception as exc:
logger.error("NFO scan failed: %s", exc, exc_info=True)
await self._broadcast("nfo_scan_error", {"error": str(exc)})
# 3. Auto-download (if enabled)
if self._config and self._config.auto_download_after_rescan:
try:
queued = await self._run_auto_download()
@@ -419,6 +434,24 @@ class SchedulerService:
await anime_service.rescan()
logger.info("anime_service.rescan() completed")
async def _run_nfo_scan(self) -> Dict[str, Any]:
"""Run NFO validation and creation across all series."""
from src.server.services.nfo_scan_service import get_nfo_scan_service
from src.server.utils.dependencies import get_anime_service
anime_service = get_anime_service()
nfo_scan_service = get_nfo_scan_service()
logger.info("Starting NFO scan...")
result = await nfo_scan_service.scan_all(anime_service)
logger.info(
"NFO scan completed: created=%d updated=%d errors=%d",
result.get("created", 0),
result.get("updated", 0),
result.get("errors_count", 0),
)
return result
async def _run_auto_download(self) -> int:
"""Queue and start downloads for all series with missing episodes."""
from src.server.models.download import EpisodeIdentifier