mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-16 23:11:27 +00:00
135 lines
4.7 KiB
Python
135 lines
4.7 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
|
|
def _csv_env(name: str, default: str = "") -> tuple[str, ...]:
|
|
value = os.getenv(name, default)
|
|
return tuple(
|
|
part.strip().lower()
|
|
for part in value.split(",")
|
|
if part.strip()
|
|
)
|
|
|
|
|
|
def _list_env(name: str, default: str = "") -> tuple[str, ...]:
|
|
value = os.getenv(name, default)
|
|
return tuple(
|
|
part.strip()
|
|
for part in value.split(",")
|
|
if part.strip()
|
|
)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Settings:
|
|
meili_url: str = os.getenv("MEILI_URL", "http://127.0.0.1:7700").rstrip("/")
|
|
meili_master_key: str = os.getenv("MEILI_MASTER_KEY", "change-me-now")
|
|
meili_index: str = os.getenv("MEILI_INDEX", "jellyfin_scenes")
|
|
hybrid_semantic_ratio: float = float(os.getenv("HYBRID_SEMANTIC_RATIO", "0.80"))
|
|
|
|
model_id: str = os.getenv("MODEL_ID", "google/siglip2-base-patch16-224")
|
|
device: str = os.getenv("DEVICE", "cuda")
|
|
batch_size: int = int(os.getenv("BATCH_SIZE", "8"))
|
|
|
|
ollama_url: str = os.getenv("OLLAMA_URL", "http://127.0.0.1:11434").rstrip("/")
|
|
caption_general_model: str = os.getenv(
|
|
"CAPTION_GENERAL_MODEL",
|
|
os.getenv(
|
|
"CAPTION_MODEL",
|
|
"huihui_ai/qwen3-vl-abliterated:4b-instruct-q4_K_M",
|
|
),
|
|
)
|
|
caption_specialist_model: str = os.getenv(
|
|
"CAPTION_SPECIALIST_MODEL",
|
|
"aha2025/llama-joycaption-beta-one-hf-llava:Q4_K_M",
|
|
)
|
|
caption_timeout_seconds: int = int(os.getenv("CAPTION_TIMEOUT_SECONDS", "180"))
|
|
caption_max_tokens: int = int(os.getenv("CAPTION_MAX_TOKENS", "120"))
|
|
caption_prompt_file: Path = Path(
|
|
os.getenv("CAPTION_PROMPT_FILE", "./data/caption_prompt.txt")
|
|
).expanduser().resolve()
|
|
caption_specialist_prompt_file: Path = Path(
|
|
os.getenv(
|
|
"CAPTION_SPECIALIST_PROMPT_FILE",
|
|
"./data/caption_prompt_specialist.txt",
|
|
)
|
|
).expanduser().resolve()
|
|
|
|
caption_router_enabled: bool = os.getenv(
|
|
"CAPTION_ROUTER_ENABLED", "true"
|
|
).strip().lower() not in {"0", "false", "no", "off"}
|
|
caption_router_model: str = os.getenv(
|
|
"CAPTION_ROUTER_MODEL", "Falconsai/nsfw_image_detection"
|
|
)
|
|
caption_router_device: str = os.getenv(
|
|
"CAPTION_ROUTER_DEVICE", os.getenv("DEVICE", "cuda")
|
|
)
|
|
caption_router_batch_size: int = int(
|
|
os.getenv("CAPTION_ROUTER_BATCH_SIZE", "32")
|
|
)
|
|
caption_router_threshold: float = float(
|
|
os.getenv("CAPTION_ROUTER_THRESHOLD", "0.50")
|
|
)
|
|
caption_router_context_seconds: float = float(
|
|
os.getenv("CAPTION_ROUTER_CONTEXT_SECONDS", "6")
|
|
)
|
|
|
|
jellyfin_url: str = os.getenv("JELLYFIN_URL", "").rstrip("/")
|
|
jellyfin_api_key: str = os.getenv("JELLYFIN_API_KEY", "")
|
|
jellyfin_library: str = os.getenv("JELLYFIN_LIBRARY", "")
|
|
jellyfin_libraries: tuple[str, ...] = _list_env("JELLYFIN_LIBRARIES")
|
|
jellyfin_exclude_libraries: tuple[str, ...] = _list_env(
|
|
"JELLYFIN_EXCLUDE_LIBRARIES"
|
|
)
|
|
jellyfin_trickplay_width: int = int(os.getenv("JELLYFIN_TRICKPLAY_WIDTH", "320"))
|
|
jellyfin_fallback_interval_seconds: float = float(
|
|
os.getenv("JELLYFIN_FALLBACK_INTERVAL_SECONDS", "10")
|
|
)
|
|
jellyfin_timeout_seconds: int = int(os.getenv("JELLYFIN_TIMEOUT_SECONDS", "60"))
|
|
jellyfin_specialist_tags: tuple[str, ...] = _csv_env(
|
|
"JELLYFIN_SPECIALIST_TAGS"
|
|
)
|
|
jellyfin_force_specialist_tag: str = os.getenv(
|
|
"JELLYFIN_FORCE_SPECIALIST_TAG", "scene-search:specialist"
|
|
).strip().lower()
|
|
jellyfin_force_general_tag: str = os.getenv(
|
|
"JELLYFIN_FORCE_GENERAL_TAG", "scene-search:general"
|
|
).strip().lower()
|
|
jellyfin_skip_tag: str = os.getenv(
|
|
"JELLYFIN_SKIP_TAG", "scene-search:skip"
|
|
).strip().lower()
|
|
jellyfin_tag_context: bool = os.getenv(
|
|
"JELLYFIN_TAG_CONTEXT", "true"
|
|
).strip().lower() not in {"0", "false", "no", "off"}
|
|
|
|
scene_api_host: str = os.getenv("SCENE_API_HOST", "127.0.0.1")
|
|
scene_api_port: int = int(os.getenv("SCENE_API_PORT", "8097"))
|
|
scene_api_key: str = os.getenv("SCENE_API_KEY", "")
|
|
|
|
data_dir: Path = Path(os.getenv("DATA_DIR", "./data")).resolve()
|
|
|
|
@property
|
|
def db_path(self) -> Path:
|
|
return self.data_dir / "scenes.sqlite3"
|
|
|
|
@property
|
|
def thumbs_dir(self) -> Path:
|
|
return self.data_dir / "thumbs"
|
|
|
|
@property
|
|
def jellyfin_cache_dir(self) -> Path:
|
|
return self.data_dir / "jellyfin"
|
|
|
|
|
|
settings = Settings()
|
|
settings.data_dir.mkdir(parents=True, exist_ok=True)
|
|
settings.thumbs_dir.mkdir(parents=True, exist_ok=True)
|
|
settings.jellyfin_cache_dir.mkdir(parents=True, exist_ok=True)
|