From 83dfb18ccb300b706bfb0505233d36b73db0f15a Mon Sep 17 00:00:00 2001 From: panni Date: Wed, 27 Feb 2019 22:12:29 +0100 Subject: [PATCH] get_languages: return a set of babelfish Language objects; use code3 by default --- bazarr/get_languages.py | 14 ++++++++++++-- bazarr/list_subtitles.py | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bazarr/get_languages.py b/bazarr/get_languages.py index 7dc281bb7..29031387a 100644 --- a/bazarr/get_languages.py +++ b/bazarr/get_languages.py @@ -5,6 +5,7 @@ import sqlite3 import pycountry from get_args import args +from subzero.language import Language def load_language_in_db(): @@ -108,11 +109,20 @@ def alpha3_from_language(lang): return result -def get_languages(kind="code2"): +def get_language_set(kind="code3"): db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = db.cursor() c.execute('''SELECT ?, name FROM table_settings_languages WHERE enabled = 1''', (kind,)) - return c.fetchall() + language_set = set() + + for lang in c.fetchall(): + # fixme: currently only works with kind=code3 + if lang == 'pob': + language_set.add(Language('por', 'BR')) + else: + language_set.add(Language(lang)) + + return language_set if __name__ == '__main__': diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index 67bff459e..745f52312 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -16,7 +16,7 @@ from bs4 import UnicodeDammit from itertools import islice from get_args import args -from get_languages import alpha2_from_alpha3, get_languages +from get_languages import alpha2_from_alpha3, get_language_set from config import settings from helper import path_replace, path_replace_movie, path_replace_reverse, \ path_replace_reverse_movie @@ -56,7 +56,7 @@ def store_subtitles(file): try: # fixme: set subliminal_patch.core.CUSTOM_PATHS to a list of absolute folders or subfolders to support # subtitles outside the media file folder - subtitles = search_external_subtitles(file, languages=get_languages(kind="code3"), + subtitles = search_external_subtitles(file, languages=get_language_set(), only_one=settings.general.getboolean('single_language')) except Exception as e: logging.exception("BAZARR unable to index external subtitles.") @@ -140,7 +140,7 @@ def store_subtitles_movie(file): # subtitles outside the media file folder brazilian_portuguese = [".pt-br", ".pob", "pb"] try: - subtitles = search_external_subtitles(file, languages=get_languages(kind="code3"), + subtitles = search_external_subtitles(file, languages=get_language_set(), only_one=settings.general.getboolean('single_language')) except Exception as e: logging.exception("BAZARR unable to index external subtitles.")