feat & Bugfix: layout en rename (year)
This commit is contained in:
@@ -83,6 +83,53 @@ class FileDiscoveryService:
|
||||
"items": files,
|
||||
}
|
||||
|
||||
def list_folders(
|
||||
self,
|
||||
root_id: str,
|
||||
subpath: str = "",
|
||||
limit: int = 500,
|
||||
) -> dict:
|
||||
root = self._get_root_by_id(root_id)
|
||||
target = self._resolve_target(root["path"], subpath)
|
||||
|
||||
folders = []
|
||||
if not target.exists():
|
||||
return {
|
||||
"root_id": root["id"],
|
||||
"root_path": str(root["path"]),
|
||||
"subpath": subpath,
|
||||
"limit": limit,
|
||||
"items": folders,
|
||||
}
|
||||
if not target.is_dir():
|
||||
raise ValueError("resolved target is not a directory")
|
||||
|
||||
for entry in target.iterdir():
|
||||
if len(folders) >= limit:
|
||||
break
|
||||
if not entry.is_dir():
|
||||
continue
|
||||
try:
|
||||
relative_to_root = entry.resolve().relative_to(root["path"])
|
||||
except ValueError:
|
||||
continue
|
||||
folders.append(
|
||||
{
|
||||
"name": entry.name,
|
||||
"subpath": str(relative_to_root),
|
||||
"path": str(entry),
|
||||
}
|
||||
)
|
||||
|
||||
folders.sort(key=lambda x: x["name"].lower())
|
||||
return {
|
||||
"root_id": root["id"],
|
||||
"root_path": str(root["path"]),
|
||||
"subpath": subpath,
|
||||
"limit": limit,
|
||||
"items": folders,
|
||||
}
|
||||
|
||||
def _load_allowed_extensions(self) -> set[str]:
|
||||
raw = os.getenv("ALLOWED_EXTENSIONS", "").strip()
|
||||
if raw:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
@@ -410,6 +411,7 @@ class SessionService:
|
||||
or "Unknown Series"
|
||||
)
|
||||
year = episode.get("year") or "0000"
|
||||
series = self._normalize_series_name(series, year)
|
||||
title = episode.get("title") or "Untitled"
|
||||
|
||||
season_raw = episode.get("season_number") or episode.get("season") or 0
|
||||
@@ -449,6 +451,16 @@ class SessionService:
|
||||
"items": previews,
|
||||
}
|
||||
|
||||
def _normalize_series_name(self, series: str, year: int | str) -> str:
|
||||
text = str(series or "").strip()
|
||||
year_str = str(year or "").strip()
|
||||
if not text or not year_str:
|
||||
return text
|
||||
|
||||
# Strip trailing " (YEAR)" to avoid duplicate year in the template output.
|
||||
pattern = re.compile(rf"\s*\({re.escape(year_str)}\)\s*$")
|
||||
return pattern.sub("", text).strip()
|
||||
|
||||
def execute_rename(self, session_id: str, confirm: bool) -> dict:
|
||||
if not confirm:
|
||||
raise ValueError("confirm=true is required to execute rename")
|
||||
|
||||
Reference in New Issue
Block a user