feat: flat design Sunset Glitch + download manager + settings + recommendations overhaul
- Sunset Glitch color palette applied to all templates - Font Awesome icons throughout UI - Download manager with parallel queue and progress tracking - Settings page with dynamic configuration - Recommendations router enhanced with scoring - Local vendor libs (Alpine.js, HTMX) for offline support - Auto test suite with screenshots - Series releases list component - New download model
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""Application settings routes for Ohm Stream Downloader API"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Any, Optional
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response
|
||||
from fastapi.templating import Jinja2Templates
|
||||
@@ -13,10 +15,74 @@ from app.routers.router_auth import get_current_user_from_token, get_optional_us
|
||||
from app.providers import get_anime_providers, get_series_providers
|
||||
from app.providers_manager import providers_manager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/api/settings", tags=["settings"])
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
def _compute_auto_weights(download_dir: str) -> Dict[str, Any]:
|
||||
"""Analyze downloaded files to compute anime vs series ratio.
|
||||
|
||||
Uses filename conventions:
|
||||
- Series: contains "Saison" or "Season" keywords
|
||||
- Anime: everything else in the downloads folder
|
||||
Returns dict with counts and computed weights.
|
||||
"""
|
||||
base = Path(download_dir)
|
||||
if not base.exists():
|
||||
return {"anime_count": 0, "series_count": 0, "anime_weight": 1, "series_weight": 1, "total": 0}
|
||||
|
||||
anime_count = 0
|
||||
series_count = 0
|
||||
|
||||
for f in base.rglob("*"):
|
||||
if not f.is_file():
|
||||
continue
|
||||
if f.suffix.lower() not in (".mp4", ".mkv", ".avi", ".wmv", ".flv", ".mov"):
|
||||
continue
|
||||
|
||||
name = f.stem.lower()
|
||||
# Heuristic: series TV files often have "Saison" or "Season" + number
|
||||
# Anime files rarely use this format (they use "Episode" or "S01E01")
|
||||
import re
|
||||
if re.search(r'(?:saison|season)\s*\d+', name):
|
||||
series_count += 1
|
||||
else:
|
||||
anime_count += 1
|
||||
|
||||
total = anime_count + series_count
|
||||
if total == 0:
|
||||
return {"anime_count": 0, "series_count": 0, "anime_weight": 1, "series_weight": 1, "total": 0}
|
||||
|
||||
# Compute weights: proportional to download count, minimum 1
|
||||
if anime_count == 0:
|
||||
aw, sw = 0, 1
|
||||
elif series_count == 0:
|
||||
aw, sw = 1, 0
|
||||
else:
|
||||
# Keep weights small (max 5) for reasonable interleaving
|
||||
ratio = anime_count / series_count
|
||||
if ratio >= 4:
|
||||
aw, sw = 4, 1
|
||||
elif ratio >= 2:
|
||||
aw, sw = 2, 1
|
||||
elif ratio >= 1:
|
||||
aw, sw = 1, 1
|
||||
elif ratio >= 0.5:
|
||||
aw, sw = 1, 2
|
||||
else:
|
||||
aw, sw = 1, 4
|
||||
|
||||
return {
|
||||
"anime_count": anime_count,
|
||||
"series_count": series_count,
|
||||
"anime_weight": aw,
|
||||
"series_weight": sw,
|
||||
"total": total,
|
||||
}
|
||||
|
||||
|
||||
@router.get("", response_model=AppSettings)
|
||||
async def get_settings(
|
||||
current_user: User = Depends(get_current_user_from_token),
|
||||
@@ -44,6 +110,9 @@ async def get_settings(
|
||||
anime_enabled=getattr(settings_obj, 'anime_enabled', True),
|
||||
series_enabled=getattr(settings_obj, 'series_enabled', True),
|
||||
download_dir=getattr(settings_obj, 'download_dir', 'downloads'),
|
||||
content_weight_mode=getattr(settings_obj, 'content_weight_mode', 'auto'),
|
||||
content_weight_anime=getattr(settings_obj, 'content_weight_anime', 2),
|
||||
content_weight_series=getattr(settings_obj, 'content_weight_series', 1),
|
||||
)
|
||||
|
||||
|
||||
@@ -86,6 +155,12 @@ async def update_settings(
|
||||
settings_obj.series_enabled = update_data.series_enabled
|
||||
if update_data.download_dir is not None:
|
||||
settings_obj.download_dir = update_data.download_dir
|
||||
if update_data.content_weight_mode is not None:
|
||||
settings_obj.content_weight_mode = update_data.content_weight_mode
|
||||
if update_data.content_weight_anime is not None:
|
||||
settings_obj.content_weight_anime = update_data.content_weight_anime
|
||||
if update_data.content_weight_series is not None:
|
||||
settings_obj.content_weight_series = update_data.content_weight_series
|
||||
|
||||
session.add(settings_obj)
|
||||
session.commit()
|
||||
@@ -98,6 +173,34 @@ async def update_settings(
|
||||
return settings_obj
|
||||
|
||||
|
||||
@router.get("/content-weight")
|
||||
async def get_content_weight(
|
||||
current_user: User = Depends(get_current_user_from_token),
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
"""Get current effective content weights (auto-computed or manual)"""
|
||||
statement = select(AppSettingsTable).where(
|
||||
AppSettingsTable.user_id == current_user.id
|
||||
)
|
||||
settings_obj = session.exec(statement).first()
|
||||
download_dir = getattr(settings_obj, 'download_dir', 'downloads') if settings_obj else 'downloads'
|
||||
mode = getattr(settings_obj, 'content_weight_mode', 'auto') if settings_obj else 'auto'
|
||||
|
||||
if mode == "auto":
|
||||
weights = _compute_auto_weights(download_dir)
|
||||
weights["mode"] = "auto"
|
||||
return weights
|
||||
else:
|
||||
return {
|
||||
"mode": "manual",
|
||||
"anime_weight": getattr(settings_obj, 'content_weight_anime', 2),
|
||||
"series_weight": getattr(settings_obj, 'content_weight_series', 1),
|
||||
"anime_count": None,
|
||||
"series_count": None,
|
||||
"total": None,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/providers/availability")
|
||||
async def get_providers_availability(
|
||||
current_user: User = Depends(get_current_user_from_token),
|
||||
|
||||
Reference in New Issue
Block a user