diff --git a/bazarr/api.py b/bazarr/api.py index fe86280aa..7221a52df 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -97,7 +97,8 @@ class Episodes(Resource): row_count = database.execute("SELECT COUNT(*) as count FROM table_episodes WHERE sonarrSeriesId=?", (seriesId,), only_one=True)['count'] if seriesId: - result = database.execute("SELECT * FROM table_episodes WHERE sonarrSeriesId=?", (seriesId,)) + result = database.execute("SELECT * FROM table_episodes WHERE sonarrSeriesId=? ORDER BY season DESC, " + "episode DESC", (seriesId,)) else: return "Series ID not provided", 400 for item in result: diff --git a/bazarr/main.py b/bazarr/main.py index 9b59f39ec..241fd3543 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -57,7 +57,7 @@ from list_subtitles import store_subtitles, store_subtitles_movie, series_scan_s from get_subtitle import download_subtitle, series_download_subtitles, movies_download_subtitles, \ manual_search, manual_download_subtitle, manual_upload_subtitle from utils import history_log, history_log_movie, get_sonarr_version, get_radarr_version -from helper import path_replace_reverse, path_replace_reverse_movie +from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie from scheduler import * from notifier import send_notifications, send_notifications_movie from subliminal_patch.extensions import provider_registry as provider_manager @@ -1481,12 +1481,14 @@ def remove_subtitles(): sonarrEpisodeId = request.form.get('sonarrEpisodeId') try: - os.remove(subtitlesPath) + os.remove(path_replace(subtitlesPath)) result = language_from_alpha3(language) + " subtitles deleted from disk." history_log(0, sonarrSeriesId, sonarrEpisodeId, result, language=alpha2_from_alpha3(language)) except OSError as e: logging.exception('BAZARR cannot delete subtitles file: ' + subtitlesPath) - store_subtitles(path_replace_reverse(episodePath), episodePath) + store_subtitles(episodePath, path_replace(episodePath)) + + return '' @app.route('/remove_subtitles_movie', methods=['POST']) diff --git a/views/episodes.html b/views/episodes.html index fbc99e2fd..e7c617280 100644 --- a/views/episodes.html +++ b/views/episodes.html @@ -107,7 +107,7 @@ url: "{{ url_for('api.series') }}?id={{id}}", }) .done(function( data ) { - var seriesDetails = data.data[0]; + seriesDetails = data.data[0]; $('#seriesFanart').css('background-image', "url('{{ url_for('image_proxy', url='MediaCover/'+id+'/fanart.jpg') }}')"); $('#seriesPoster').attr("src","{{ url_for('image_proxy', url='MediaCover/'+id+'/poster-250.jpg') }}"); $('#seriesTitle').text(seriesDetails['title']); @@ -159,18 +159,22 @@ }, {"data": "episode"}, {"data": "title"}, - {"data": "subtitles", + {"data": null, "render": function (data) { - if (data !== 'None') { + if (data.subtitles !== 'None') { var languages = ''; - data.forEach(appendFunc); + data.subtitles.forEach(appendFunc); return languages; } else { return null; } function appendFunc(value) { - languages = languages + '' + value[0].code2 + ' '; + if (value[1] === null) { + languages = languages + '' + value[0].code2 + ' '; + } else { + languages = languages + '' + value[0].code2 + ' '; + } } } }, @@ -193,6 +197,34 @@ {"data": "title"} ] }); + + $('#episodes').on('click', '.remove_subtitles', function(e){ + e.preventDefault() + const values = { + episodePath: $(this).attr("data-episodePath"), + language: $(this).attr("data-language"), + subtitlesPath: $(this).attr("data-subtitlesPath"), + sonarrSeriesId: seriesDetails['sonarrSeriesId'], + sonarrEpisodeId: $(this).attr("data-sonarrEpisodeId"), + tvdbid: seriesDetails['tvdbId'] + }; + var cell = $(this).closest('td'); + $.ajax({ + url: "{{ url_for('remove_subtitles') }}", + type: "POST", + dataType: "json", + data: values, + beforeSend: function() { + cell.html('