From 3ed863a3beebede0ab76e86c4f1c7f6e5320acd8 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Mon, 18 Mar 2024 19:07:38 -0400 Subject: [PATCH] Upgrade routine and settings UI --- bazarr/app/database.py | 25 ++++++++++++++++++ bazarr/main.py | 3 ++- .../src/components/forms/ProfileEditForm.tsx | 26 ++++++++++++------- frontend/src/types/api.d.ts | 2 +- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/bazarr/app/database.py b/bazarr/app/database.py index c2a97987d..7c1663b67 100644 --- a/bazarr/app/database.py +++ b/bazarr/app/database.py @@ -497,3 +497,28 @@ def convert_list_to_clause(arr: list): return f"({','.join(str(x) for x in arr)})" else: return "" + + +def upgrade_languages_profile_hi_values(): + for languages_profile in (database.execute( + select( + TableLanguagesProfiles.profileId, + TableLanguagesProfiles.name, + TableLanguagesProfiles.cutoff, + TableLanguagesProfiles.items, + TableLanguagesProfiles.mustContain, + TableLanguagesProfiles.mustNotContain, + TableLanguagesProfiles.originalFormat) + ))\ + .all(): + items = json.loads(languages_profile.items) + for language in items: + if language['hi'] == "True": + language['hi'] = "only" + elif language['hi'] == "False": + language['hi'] = "also" + database.execute( + update(TableLanguagesProfiles) + .values({"items": json.dumps(items)}) + .where(TableLanguagesProfiles.profileId == languages_profile.profileId) + ) diff --git a/bazarr/main.py b/bazarr/main.py index 15af61e97..631c4a028 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -36,7 +36,7 @@ else: # there's missing embedded packages after a commit check_if_new_update() -from app.database import System, database, update, migrate_db, create_db_revision # noqa E402 +from app.database import System, database, update, migrate_db, create_db_revision, upgrade_languages_profile_hi_values # noqa E402 from app.notifier import update_notifier # noqa E402 from languages.get_languages import load_language_in_db # noqa E402 from app.signalr_client import sonarr_signalr_client, radarr_signalr_client # noqa E402 @@ -48,6 +48,7 @@ if args.create_db_revision: stop_bazarr(EXIT_NORMAL) else: migrate_db(app) + upgrade_languages_profile_hi_values() configure_proxy_func() diff --git a/frontend/src/components/forms/ProfileEditForm.tsx b/frontend/src/components/forms/ProfileEditForm.tsx index 874f5b8a6..ea81e0252 100644 --- a/frontend/src/components/forms/ProfileEditForm.tsx +++ b/frontend/src/components/forms/ProfileEditForm.tsx @@ -38,12 +38,16 @@ const defaultCutoffOptions: SelectorOption[] = [ const subtitlesTypeOptions: SelectorOption[] = [ { - label: "Normal or hearing-impaired", - value: "normal", + label: "Normal only", + value: "never", + }, + { + label: "Hearing-impaired only", + value: "hi_only", }, { - label: "Hearing-impaired required", - value: "hi", + label: "Normal or hearing-impaired", + value: "hi_also", }, { label: "Forced (foreign part only)", @@ -131,7 +135,7 @@ const ProfileEditForm: FunctionComponent = ({ language, // eslint-disable-next-line camelcase audio_exclude: "False", - hi: "False", + hi: "Also", forced: "False", }; @@ -181,10 +185,12 @@ const ProfileEditForm: FunctionComponent = ({ const selectValue = useMemo(() => { if (item.forced === "True") { return "forced"; - } else if (item.hi === "True") { - return "hi"; - } else { - return "normal"; + } else if (item.hi === "also") { + return "hi_also"; + } else if (item.hi === "only") { + return "hi_only"; + } else if (item.hi === "never") { + return "never"; } }, [item.forced, item.hi]); @@ -196,7 +202,7 @@ const ProfileEditForm: FunctionComponent = ({ if (value) { action.mutate(index, { ...item, - hi: value === "hi" ? "True" : "False", + hi: value, forced: value === "forced" ? "True" : "False", }); } diff --git a/frontend/src/types/api.d.ts b/frontend/src/types/api.d.ts index 069be3029..b2ea266fb 100644 --- a/frontend/src/types/api.d.ts +++ b/frontend/src/types/api.d.ts @@ -28,7 +28,7 @@ declare namespace Language { id: number; audio_exclude: PythonBoolean; forced: PythonBoolean; - hi: PythonBoolean; + hi: string; language: CodeType; }