diff --git a/bazarr/api.py b/bazarr/api.py index c61da14bf..a40fd6e3a 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -462,6 +462,11 @@ class Episodes(Resource): # Add Datatables rowId item.update({"DT_RowId": 'row_' + str(item['sonarrEpisodeId'])}) + # Parse audio language + item.update({"audio_language": {"name": item['audio_language'], + "code2": alpha2_from_language(item['audio_language']) or None, + "code3": alpha3_from_language(item['audio_language']) or None}}) + # Parse subtitles if item['subtitles']: item.update({"subtitles": ast.literal_eval(item['subtitles'])}) @@ -540,8 +545,8 @@ class EpisodesSubtitlesDownload(Resource): title = request.form.get('title') providers_list = get_providers() providers_auth = get_providers_auth() - audio_language = database.execute("SELECT audio_language FROM table_shows WHERE sonarrSeriesId=?", - (sonarrSeriesId,), only_one=True)['audio_language'] + audio_language = database.execute("SELECT audio_language FROM table_episodes WHERE sonarrEpisodeId=?", + (sonarrEpisodeId,), only_one=True)['audio_language'] try: result = download_subtitle(episodePath, language, audio_language, hi, forced, providers_list, providers_auth, sceneName, @@ -609,8 +614,8 @@ class EpisodesSubtitlesManualDownload(Resource): sonarrEpisodeId = request.form.get('sonarrEpisodeId') title = request.form.get('title') providers_auth = get_providers_auth() - audio_language = database.execute("SELECT audio_language FROM table_shows WHERE sonarrSeriesId=?", - (sonarrSeriesId,), only_one=True)['audio_language'] + audio_language = database.execute("SELECT audio_language FROM table_episodes WHERE sonarrEpisodeId=?", + (sonarrEpisodeId,), only_one=True)['audio_language'] try: result = manual_download_subtitle(episodePath, language, audio_language, hi, forced, subtitle, diff --git a/bazarr/database.py b/bazarr/database.py index 15e9c2d60..5046f9974 100644 --- a/bazarr/database.py +++ b/bazarr/database.py @@ -99,6 +99,7 @@ def db_upgrade(): ['table_episodes', 'video_codec', 'text'], ['table_episodes', 'audio_codec', 'text'], ['table_episodes', 'episode_file_id', 'integer'], + ['table_episodes', 'audio_language', 'text'], ['table_movies', 'sortTitle', 'text'], ['table_movies', 'year', 'text'], ['table_movies', 'alternativeTitles', 'text'], diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index d9e485422..1e303a8f5 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -85,6 +85,13 @@ def sync_episodes(): videoCodec = None audioCodec = None + audio_language = None + if 'language' in episode['episodeFile'] and len(episode['episodeFile']['language']): + item = episode['episodeFile']['language'] + if isinstance(item, dict): + if 'name' in item: + audio_language = item['name'] + # Add episodes in sonarr to current episode list current_episodes_sonarr.append(episode['id']) @@ -101,7 +108,8 @@ def sync_episodes(): 'resolution': resolution, 'video_codec': videoCodec, 'audio_codec': audioCodec, - 'episode_file_id': episode['episodeFile']['id']}) + 'episode_file_id': episode['episodeFile']['id'], + 'audio_language': audio_language}) else: episodes_to_add.append({'sonarrSeriesId': episode['seriesId'], 'sonarrEpisodeId': episode['id'], @@ -115,7 +123,8 @@ def sync_episodes(): 'resolution': resolution, 'video_codec': videoCodec, 'audio_codec': audioCodec, - 'episode_file_id': episode['episodeFile']['id']}) + 'episode_file_id': episode['episodeFile']['id'], + 'audio_language': audio_language}) # Remove old episodes from DB removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) @@ -131,7 +140,7 @@ def sync_episodes(): episode_in_db_list = [] episodes_in_db = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, " "scene_name, monitored, format, resolution, video_codec, audio_codec, " - "episode_file_id FROM table_episodes") + "episode_file_id, audio_language FROM table_episodes") for item in episodes_in_db: episode_in_db_list.append(item) diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py index b30d5a911..4ac1fc120 100644 --- a/bazarr/get_subtitle.py +++ b/bazarr/get_subtitle.py @@ -641,7 +641,7 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type def series_download_subtitles(no): episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, monitored, " "table_episodes.sonarrEpisodeId, table_episodes.scene_name, table_shows.tags, " - "table_shows.seriesType FROM table_episodes INNER JOIN table_shows on " + "table_shows.seriesType, table_episodes.audio_language FROM table_episodes INNER JOIN table_shows on " "table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE " "table_episodes.sonarrSeriesId=? and missing_subtitles!='[]'", (no,)) episodes_details = filter_exclusions(episodes_details, 'series') @@ -650,7 +650,7 @@ def series_download_subtitles(no): return series_details = database.execute( - "SELECT hearing_impaired, audio_language, title, forced FROM table_shows WHERE sonarrSeriesId=?", + "SELECT hearing_impaired, title, forced FROM table_shows WHERE sonarrSeriesId=?", (no,), only_one=True) if not series_details: logging.debug("BAZARR no series with that sonarrSeriesId can be found in database:", str(no)) @@ -667,7 +667,7 @@ def series_download_subtitles(no): if language is not None: result = download_subtitle(path_mappings.path_replace(episode['path']), str(alpha3_from_alpha2(language.split(':')[0])), - series_details['audio_language'], + episode['audio_language'], series_details['hearing_impaired'], "True" if len(language.split(':')) > 1 else "False", providers_list, @@ -697,7 +697,7 @@ def episode_download_subtitles(no): episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, monitored, " "table_episodes.sonarrEpisodeId, table_episodes.scene_name, table_shows.tags, " "table_shows.hearing_impaired, table_shows.title, table_shows.sonarrSeriesId, " - "table_shows.forced, table_shows.audio_language, table_shows.seriesType FROM " + "table_shows.forced, table_episodes.audio_language, table_shows.seriesType FROM " "table_episodes LEFT JOIN table_shows on table_episodes.sonarrSeriesId = " "table_shows.sonarrSeriesId WHERE sonarrEpisodeId=?", (no,)) episodes_details = filter_exclusions(episodes_details, 'series') @@ -792,7 +792,7 @@ def movies_download_subtitles(no): def wanted_download_subtitles(path, l, count_episodes): episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, " "table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, " - "table_shows.hearing_impaired, table_shows.audio_language, table_episodes.scene_name," + "table_shows.hearing_impaired, table_episodes.audio_language, table_episodes.scene_name," "table_episodes.failedAttempts, table_shows.title, table_shows.forced " "FROM table_episodes LEFT JOIN table_shows on " "table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId " @@ -1071,7 +1071,7 @@ def upgrade_subtitles(): if settings.general.getboolean('use_sonarr'): upgradable_episodes = database.execute("SELECT table_history.video_path, table_history.language, " "table_history.score, table_shows.hearing_impaired, " - "table_shows.audio_language, table_episodes.scene_name, table_episodes.title," + "table_episodes.audio_language, table_episodes.scene_name, table_episodes.title," "table_episodes.sonarrSeriesId, table_episodes.sonarrEpisodeId," "MAX(table_history.timestamp) as timestamp, table_episodes.monitored, " "table_shows.languages, table_shows.forced, table_shows.tags, " diff --git a/views/episodes.html b/views/episodes.html index 9d6995ae1..0fa3509e9 100644 --- a/views/episodes.html +++ b/views/episodes.html @@ -113,6 +113,7 @@