diff --git a/bazarr/SSE.py b/bazarr/SSE.py index d7777e6e9..f37d6fe42 100644 --- a/bazarr/SSE.py +++ b/bazarr/SSE.py @@ -16,15 +16,17 @@ class EventStream: """ :param type: The type of element. :type type: str - :param type: The series id. - :type type: str - :param type: The episode id. - :type type: str - :param type: The movie id. - :type type: str + :param action: The action type of element from insert, update, delete. + :type action: str + :param series: The series id. + :type series: str + :param episode: The episode id. + :type episode: str + :param movie: The movie id. + :type movie: str """ msg = {"type": type, "action": action, "series": series, "episode": episode, "movie": movie} - self.queue.append("data:" + json.dumps(msg) + "\n\n") + self.queue.append("retry: 1000\ndata:" + json.dumps(msg) + "\n\n") def read(self): """ diff --git a/bazarr/get_series.py b/bazarr/get_series.py index dda3de622..8ac978260 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -149,7 +149,7 @@ def update_series(): database.execute('''UPDATE table_shows SET ''' + query.keys_update + ''' WHERE sonarrSeriesId = ?''', query.values + (updated_series['sonarrSeriesId'],)) - event_stream.write(type='series', series=updated_series['sonarrSeriesId']) + event_stream.write(type='series', action='update', series=updated_series['sonarrSeriesId']) # Insert new series in DB for added_series in series_to_add: @@ -163,7 +163,7 @@ def update_series(): logging.debug('BAZARR unable to insert this series into the database:', path_replace(added_series['path'])) - event_stream.write(type='series', series=added_series['sonarrSeriesId']) + event_stream.write(type='series', action='insert', series=added_series['sonarrSeriesId']) logging.debug('BAZARR All series synced from Sonarr into database.') diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index 21dcf913d..fac0b16d0 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -105,7 +105,7 @@ def store_subtitles(original_path, reversed_path): logging.debug('BAZARR ended subtitles indexing for this file: ' + reversed_path) - event_stream.write(type='episode', series=episode['sonarrSeriesId'], episode=episode['sonarrEpisodeId']) + event_stream.write(type='episode', action='update', series=episode['sonarrSeriesId'], episode=episode['sonarrEpisodeId']) return actual_subtitles @@ -178,7 +178,7 @@ def store_subtitles_movie(original_path, reversed_path): logging.debug('BAZARR ended subtitles indexing for this file: ' + reversed_path) - event_stream.write(type='movie', movie=movie['radarrId']) + event_stream.write(type='movie', action='update', movie=movie['radarrId']) return actual_subtitles diff --git a/bazarr/main.py b/bazarr/main.py index f7d7d8cc0..7660d3211 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -791,23 +791,15 @@ def movie(no): @app.route('/scan_disk/', methods=['GET']) @login_required def scan_disk(no): - - ref = request.environ['HTTP_REFERER'] - series_scan_subtitles(no) - - redirect(ref) + return '', 200 @app.route('/scan_disk_movie/', methods=['GET']) @login_required def scan_disk_movie(no): - - ref = request.environ['HTTP_REFERER'] - movies_scan_subtitles(no) - - redirect(ref) + return '', 200 @app.route('/search_missing_subtitles/', methods=['GET']) @@ -1812,11 +1804,6 @@ def movie_history(no): return dict(data=movie_history) -@app.route('/event') -def event(): - return Response(event_stream.read(), mimetype="text/event-stream") - - # Don't put any route under this one @app.route('/api/help') def api_help(): diff --git a/views/_main.html b/views/_main.html index e79920c5e..f67b3e3cc 100644 --- a/views/_main.html +++ b/views/_main.html @@ -264,37 +264,43 @@ var events = new EventSource('{{ url_for('api.events') }}'); events.onmessage = function (event) { var event_json = JSON.parse(event.data); - if (event_json.type === 'episode') { - var rowId = $('#episodes').DataTable().row('#row_'+event_json.episode); - if (rowId.length) { - $.ajax({ - url: "{{ url_for('api.episodes') }}?seriesid="+event_json.series+"&episodeid="+event_json.episode, - async: true, - success: function (data) { - $('#episodes').DataTable().row(rowId).data(data.data[0]); - $('[data-toggle="tooltip"]').tooltip({html: true}); - } - }) - } - } - if (event_json.type === 'series') { - if (event_json.series === {{id}}) { + if (event_json.series === {{id}}) { + if (event_json.type === 'series' && event_json.action === 'update' && event_json.episode == null) { seriesDetailsRefresh(); } - /* - var rowId = $('#episodes').DataTable().row('#row_'+event_json.episode); - if (rowId.length) { + + if (event_json.type === 'episode' && event_json.action === 'insert') { $.ajax({ - url: "{{ url_for('api.episodes') }}?seriesid="+event_json.series+"&episodeid="+event_json.episode, - async: true, - success: function (data) { - $('#episodes').DataTable().row(rowId).data(data.data[0]); - $('[data-toggle="tooltip"]').tooltip({html: true}); - } - }) + url: "{{ url_for('api.episodes') }}?seriesid=" + event_json.series + "&episodeid=" + event_json.episode, + async: true, + success: function (data) { + if (data.data.length) { + $('#episodes').DataTable().row.add(data.data[0]).draw(); + $('[data-toggle="tooltip"]').tooltip({html: true}); + } + } + }) + } else if (event_json.type === 'episode' && event_json.action === 'update') { + var rowId = $('#episodes').DataTable().row('#row_' + event_json.episode); + if (rowId.length) { + $.ajax({ + url: "{{ url_for('api.episodes') }}?seriesid=" + event_json.series + "&episodeid=" + event_json.episode, + async: true, + success: function (data) { + if (data.data.length) { + $('#episodes').DataTable().row(rowId).data(data.data[0]); + $('[data-toggle="tooltip"]').tooltip({html: true}); + } + } + }) + } + } else if (event_json.type === 'episode' && event_json.action === 'delete') { + var rowId = $('#episodes').DataTable().row('#row_' + event_json.episode); + if (rowId.length) { + $('#episodes').DataTable().row(rowId).remove().draw(); + $('[data-toggle="tooltip"]').tooltip({html: true}); + } } - - */ } }; diff --git a/views/episodes.html b/views/episodes.html index 620e0511c..6872f951a 100644 --- a/views/episodes.html +++ b/views/episodes.html @@ -38,11 +38,11 @@ {% block bcleft %}
@@ -51,7 +51,7 @@ {% block bcright %}
@@ -245,7 +245,7 @@ {"data": "title"}, {"data": null, "render": function (data) { - if (data.subtitles !== 'None') { + if (data.subtitles !== null) { var languages = ''; data.subtitles.forEach(appendFunc); return languages; @@ -264,7 +264,7 @@ }, {"data": null, "render": function (data) { - if (data.missing_subtitles !== 'None') { + if (data.missing_subtitles !== null) { var languages = ''; data.missing_subtitles.forEach(appendFunc); return languages; @@ -528,6 +528,20 @@ }); }); + $('#scan_button').on('click', function(e){ + e.preventDefault(); + $.ajax({ + url: "{{ url_for('scan_disk', no=id) }}", + type: 'GET', + beforeSend: function() { + $('#scan_button').addClass('fa-spin'); + }, + complete: function() { + $('#scan_button').removeClass('fa-spin'); + } + }); + }); + $('#uploadModal').on('hidden.bs.modal', function () { $(this).find('form')[0].reset(); }); @@ -555,7 +569,7 @@ $('#seriesFileCount').text(seriesDetails['episodeFileCount'] + ' files'); var languages = ''; - if (seriesDetails['languages'] !== 'None') { + if (seriesDetails['languages'] !== null) { seriesDetails['languages'].forEach(appendFunc); }