Switched to the actual episodes audio language instead of series audio profile language.

This commit is contained in:
Louis Vézina 2020-08-20 10:19:34 -04:00
parent 88452468cf
commit ebde79a8cd
7 changed files with 38 additions and 19 deletions

View File

@ -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,

View File

@ -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'],

View File

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

View File

@ -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, "

View File

@ -113,6 +113,7 @@
<th></th>
<th>Episode</th>
<th>Title</th>
<th>Audio Language</th>
<th>Existing Subtitles</th>
<th>Missing Subtitles</th>
<th>Manual Search</th>
@ -232,7 +233,7 @@
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 text-right">
Audio Language
Audio Profile
</div>
<div class="form-group col-sm-8 pl-sm-0">
<span id="edit_audio_language_span"></span>
@ -579,6 +580,9 @@
}
}
},
{
data: 'audio_language.name'
},
{
data: null,
render: function (data) {
@ -629,7 +633,7 @@
data: null,
render: function (data) {
if (data.desired_languages !== '[]') {
return '<a href="" class="upload_subtitle badge badge-secondary" data-episodePath="' + data.mapped_path + '" data-sceneName"' + data.scene_name + '" data-sonarrSeriesId="' + seriesDetails['sonarrSeriesId'] + '" data-sonarrEpisodeId="' + data.sonarrEpisodeId + '" data-season="' + data.season + '" data-episode="' + data.episode + '" data-episode_title="' + data.title + '"><i class="fas fa-cloud-upload-alt"></i></a>';
return '<a href="" class="upload_subtitle badge badge-secondary" data-episodePath="' + data.mapped_path + '" data-sceneName"' + data.scene_name + '" data-sonarrSeriesId="' + seriesDetails['sonarrSeriesId'] + '" data-sonarrEpisodeId="' + data.sonarrEpisodeId + '" data-season="' + data.season + '" data-episode="' + data.episode + '" data-episode_title="' + data.title + '" data-audio_language="' + data.audio_language.name + '"><i class="fas fa-cloud-upload-alt"></i></a>';
} else {
return ''
}
@ -876,7 +880,7 @@
$('#upload_sonarrSeriesId').val($(this).data("sonarrseriesid"));
$('#upload_sonarrEpisodeId').val($(this).data("sonarrepisodeid"));
$('#upload_title').val($(this).data("episode_title"));
$('#upload_audioLanguage').val(seriesDetails['audio_language']['name']);
$('#upload_audioLanguage').val($(this).data("audio_language"));
$('#manual_language_select').empty();
$.each(enabledLanguages, function (i, item) {

View File

@ -22,7 +22,7 @@
<tr>
<th>Name</th>
<th>Path Exist</th>
<th>Audio Language</th>
<th>Audio Profile</th>
<th>Subtitles Languages</th>
<th>Hearing-Impaired</th>
<th>Forced</th>
@ -46,7 +46,7 @@
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 text-right">
Audio Language
Audio Profile
</div>
<div class="form-group col-sm-8 pl-sm-0">
<span id="edit_audio_language_span"></span>

View File

@ -16,7 +16,7 @@
<tr>
<th></th>
<th>Name</th>
<th>Audio Language</th>
<th>Audio Profile</th>
<th>Subtitles Languages</th>
<th>Hearing-Impaired</th>
<th>Forced</th>