From 9398789fb7249530901e419faee545d40384c975 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Sat, 13 Feb 2021 09:59:43 -0500 Subject: [PATCH] Added defaults languages migration. --- bazarr/database.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bazarr/database.py b/bazarr/database.py index aa7c033bf..26b28f3b8 100644 --- a/bazarr/database.py +++ b/bazarr/database.py @@ -168,10 +168,29 @@ def db_upgrade(): "cutoff INTEGER, items TEXT NOT NULL)") if not lang_table_exist: + series_default = [] + for language in ast.literal_eval(settings.general.serie_default_language): + if settings.general.serie_default_forced == 'Both': + series_default.append([language, 'True', settings.general.serie_default_hi]) + series_default.append([language, 'False', settings.general.serie_default_hi]) + else: + series_default.append([language, settings.general.serie_default_forced, + settings.general.serie_default_hi]) + + movies_default = [] + for language in ast.literal_eval(settings.general.movie_default_language): + if settings.general.movie_default_forced == 'Both': + movies_default.append([language, 'True', settings.general.movie_default_hi]) + movies_default.append([language, 'False', settings.general.movie_default_hi]) + else: + movies_default.append([language, settings.general.movie_default_forced, + settings.general.movie_default_hi]) + profiles_to_create = database.execute("SELECT DISTINCT languages, hearing_impaired, forced " "FROM (SELECT languages, hearing_impaired, forced FROM table_shows " "UNION ALL SELECT languages, hearing_impaired, forced FROM table_movies) " "a WHERE languages NOT null and languages NOT IN ('None', '[]')") + for profile in profiles_to_create: profile_items = [] languages_list = ast.literal_eval(profile['languages']) @@ -184,6 +203,7 @@ def db_upgrade(): else: profile_items.append({'id': i, 'language': language, 'forced': profile['forced'], 'hi': profile['hearing_impaired'], 'audio_exclude': 'False'}) + # Create profiles new_profile_name = profile['languages'] + ' (' + profile['hearing_impaired'] + '/' + profile['forced'] + ')' database.execute("INSERT INTO table_languages_profiles (name, cutoff, items) VALUES(" @@ -198,6 +218,22 @@ def db_upgrade(): "forced = ?", (created_profile_id, profile['languages'], profile['hearing_impaired'], profile['forced'])) + # Save new defaults + profile_items_list = [] + for item in profile_items: + profile_items_list.append([item['language'], item['forced'], item['hi']]) + try: + if created_profile_id and profile_items_list == series_default: + settings.general.serie_default_profile = str(created_profile_id) + except: + pass + + try: + if created_profile_id and profile_items_list == movies_default: + settings.general.movie_default_profile = str(created_profile_id) + except: + pass + # null languages, forced and hearing_impaired for all series and movies database.execute("UPDATE table_shows SET languages = null, forced = null, hearing_impaired = null") database.execute("UPDATE table_movies SET languages = null, forced = null, hearing_impaired = null")