diff --git a/api/main.py b/api/main.py index d86e34c..709e43b 100644 --- a/api/main.py +++ b/api/main.py @@ -138,13 +138,22 @@ async def configure( if user_data.streaming_provider: user_data.streaming_provider.password = None + # Prepare catalogs based on user preferences or default order + sorted_catalogs = sorted( + zip(const.CATALOG_ID_DATA, const.CATALOG_NAME_DATA), + key=lambda x: user_data.selected_catalogs.index(x[0]) + if x[0] in user_data.selected_catalogs + else len(user_data.selected_catalogs), + ) + return TEMPLATES.TemplateResponse( "html/configure.html", { "request": request, "user_data": user_data.model_dump(), - "catalogs": zip(const.CATALOG_ID_DATA, const.CATALOG_NAME_DATA), + "catalogs": sorted_catalogs, "resolutions": const.RESOLUTIONS, + "sorting_options": const.TORRENT_SORTING_PRIORITY, }, ) diff --git a/db/schemas.py b/db/schemas.py index 497e706..924146a 100644 --- a/db/schemas.py +++ b/db/schemas.py @@ -95,6 +95,9 @@ class UserData(BaseModel): selected_resolutions: list[str | None] = Field(default=const.RESOLUTIONS) enable_catalogs: bool = True max_size: int | str | float = math.inf + max_streams_per_resolution: int = 3 + show_full_torrent_name: bool = False + torrent_sorting_priority: list[str] = Field(default=const.TORRENT_SORTING_PRIORITY) @model_validator(mode="after") def validate_selected_resolutions(self) -> "UserData": @@ -118,6 +121,13 @@ class UserData(BaseModel): return int(v) raise ValueError("Invalid max_size") + @field_validator("torrent_sorting_priority", mode="after") + def validate_torrent_sorting_priority(cls, v): + for priority in v: + if priority not in const.TORRENT_SORTING_PRIORITY: + raise ValueError("Invalid priority") + return v + class Config: extra = "ignore" diff --git a/resources/html/configure.html b/resources/html/configure.html index d9dde8e..402ee20 100644 --- a/resources/html/configure.html +++ b/resources/html/configure.html @@ -107,8 +107,8 @@