get_languages: return a set of babelfish Language objects; use code3 by default

pull/489/head
panni 6 years ago
parent 8a1baa2d24
commit 83dfb18ccb

@ -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__':

@ -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.")

Loading…
Cancel
Save