Dockerized media library scanner for NAS drives. Identifies movies and series from filenames, fetches posters via the public IMDB suggestion API (no key required), and exposes a dark-themed web UI with multilingual search support. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
import os
|
|
import logging
|
|
from dataclasses import dataclass, field
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@dataclass
|
|
class NasConfig:
|
|
index: int
|
|
name: str
|
|
container_path: str
|
|
|
|
|
|
@dataclass
|
|
class Settings:
|
|
db_host: str
|
|
db_port: int
|
|
db_name: str
|
|
db_user: str
|
|
db_password: str
|
|
scan_interval_hours: int
|
|
video_extensions: frozenset[str]
|
|
nas_list: list[NasConfig]
|
|
|
|
@property
|
|
def db_url(self) -> str:
|
|
return (
|
|
f"mysql://{self.db_user}:{self.db_password}"
|
|
f"@{self.db_host}:{self.db_port}/{self.db_name}"
|
|
"?charset=utf8mb4"
|
|
)
|
|
|
|
|
|
def _discover_nas() -> list[NasConfig]:
|
|
"""Detect mounted NAS volumes inside the container (/nas/nas1, /nas/nas2, …)."""
|
|
nas_base = "/nas"
|
|
entries: list[NasConfig] = []
|
|
idx = 1
|
|
while True:
|
|
container_path = f"{nas_base}/nas{idx}"
|
|
if not os.path.isdir(container_path):
|
|
break
|
|
# Attempt to read the name from env (set by generate-compose.py indirectly via NAS_X)
|
|
env_key = f"NAS_{idx}"
|
|
raw = os.getenv(env_key, "")
|
|
if raw and "|" in raw:
|
|
name = raw.split("|", 1)[0].strip()
|
|
else:
|
|
name = f"NAS {idx}"
|
|
entries.append(NasConfig(index=idx, name=name, container_path=container_path))
|
|
idx += 1
|
|
if not entries:
|
|
logger.warning("No NAS volumes found at %s/nasX — scanner will have nothing to scan", nas_base)
|
|
return entries
|
|
|
|
|
|
def load_settings() -> Settings:
|
|
raw_ext = os.getenv("VIDEO_EXTENSIONS", ".mkv,.mp4,.avi,.m4v,.mov,.wmv,.ts,.m2ts,.iso")
|
|
extensions = frozenset(e.strip().lower() for e in raw_ext.split(",") if e.strip())
|
|
|
|
return Settings(
|
|
db_host=os.getenv("DB_HOST", "db"),
|
|
db_port=int(os.getenv("DB_PORT", "3306")),
|
|
db_name=os.getenv("DB_NAME", "mediatracker"),
|
|
db_user=os.getenv("DB_USER", "mediatracker"),
|
|
db_password=os.getenv("DB_PASSWORD", "changeme_db"),
|
|
scan_interval_hours=int(os.getenv("SCAN_INTERVAL_HOURS", "6")),
|
|
video_extensions=extensions,
|
|
nas_list=_discover_nas(),
|
|
)
|