diff --git a/bazarr.py b/bazarr.py index e92349fb2..1a6911803 100644 --- a/bazarr.py +++ b/bazarr.py @@ -125,7 +125,7 @@ def series(): offset = (int(page) - 1) * 15 max_page = (missing_count / 15) + 1 - c.execute("SELECT tvdbId, title, path_substitution(path), languages, hearing_impaired, sonarrSeriesId, poster FROM table_shows ORDER BY title ASC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT tvdbId, title, path_substitution(path), languages, hearing_impaired, sonarrSeriesId, poster, audio_language FROM table_shows ORDER BY title ASC LIMIT 15 OFFSET ?", (offset,)) data = c.fetchall() c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1") languages = c.fetchall() diff --git a/get_series.py b/get_series.py index 13e383c62..cf0b0f4ce 100644 --- a/get_series.py +++ b/get_series.py @@ -6,6 +6,8 @@ from get_general_settings import * from get_sonarr_settings import * def update_series(): + get_profile_list() + # Open database connection db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'), timeout=30) c = db.cursor() @@ -16,14 +18,12 @@ def update_series(): # Get shows data from Sonarr url_sonarr_api_series = url_sonarr + "/api/series?apikey=" + apikey_sonarr r = requests.get(url_sonarr_api_series) - shows_list = [] # Get current shows in DB current_shows_db = c.execute('SELECT tvdbId FROM table_shows').fetchall() current_shows_db_list = [x[0] for x in current_shows_db] current_shows_sonarr = [] - # Parsing data returned from Sonarr for show in r.json(): try: overview = unicode(show['overview']) @@ -43,9 +43,10 @@ def update_series(): current_shows_sonarr.append(show['tvdbId']) # Update or insert shows list in database table - result = c.execute('''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ? WHERE tvdbid = ?''', (show["title"],show["path"],show["tvdbId"],show["id"],overview,poster,fanart,show["tvdbId"])) - if result.rowcount == 0: - c.execute('''INSERT INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart) VALUES (?,?,?,(SELECT languages FROM table_shows WHERE tvdbId = ?),(SELECT `hearing_impaired` FROM table_shows WHERE tvdbId = ?), ?, ?, ?, ?)''', (show["title"],show["path"],show["tvdbId"],show["tvdbId"],show["tvdbId"],show["id"],overview,poster,fanart)) + try: + c.execute('''INSERT INTO table_shows(title, path, tvdbId, languages,`hearing_impaired`, sonarrSeriesId, overview, poster, fanart, `audio_language`) VALUES (?,?,?,(SELECT languages FROM table_shows WHERE tvdbId = ?),(SELECT `hearing_impaired` FROM table_shows WHERE tvdbId = ?), ?, ?, ?, ?, ?)''', (show["title"], show["path"], show["tvdbId"], show["tvdbId"], show["tvdbId"], show["id"], overview, poster, fanart, profile_id_to_language(show['qualityProfileId']))) + except: + c.execute('''UPDATE table_shows SET title = ?, path = ?, tvdbId = ?, sonarrSeriesId = ?, overview = ?, poster = ?, fanart = ?, `audio_language` = ? WHERE tvdbid = ?''', (show["title"],show["path"],show["tvdbId"],show["id"],overview,poster,fanart,profile_id_to_language(show['qualityProfileId']),show["tvdbId"])) # Delete shows not in Sonarr anymore deleted_items = [] @@ -59,3 +60,19 @@ def update_series(): # Close database connection db.close() + +def get_profile_list(): + # Get profiles data from Sonarr + url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr + profiles_json = requests.get(url_sonarr_api_series) + global profiles_list + profiles_list = [] + + # Parsing data returned from Sonarr + for profile in profiles_json.json(): + profiles_list.append([profile['id'], profile['language'].capitalize()]) + +def profile_id_to_language(id): + for profile in profiles_list: + if id == profile[0]: + return profile[1] \ No newline at end of file diff --git a/update_db.py b/update_db.py index 2ac69dd92..7b757e187 100644 --- a/update_db.py +++ b/update_db.py @@ -19,7 +19,12 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) c.execute('UPDATE table_settings_providers SET password=""') except: pass - + + try: + c.execute('alter table table_shows add column "audio_language" "text"') + except: + pass + # Commit change to db db.commit() diff --git a/views/series.tpl b/views/series.tpl index 124e64939..01ef165df 100644 --- a/views/series.tpl +++ b/views/series.tpl @@ -88,7 +88,8 @@ Name Path - Language + Audio language + Subtitles language Hearing-impaired @@ -102,6 +103,7 @@ {{row[2]}} + {{row[7]}} %subs_languages = ast.literal_eval(str(row[3])) %if subs_languages is not None: @@ -120,7 +122,7 @@ end end %> -
+
@@ -174,7 +176,15 @@
- + +
+
+
+
+
+
+
+