pull/884/head
Louis Vézina 5 years ago
parent f9ba0b0fb8
commit 025ecb941c

@ -1,7 +1,6 @@
from __future__ import absolute_import from __future__ import absolute_import
from collections import deque from collections import deque
import json import json
import time
class EventStream: class EventStream:
@ -26,7 +25,7 @@ class EventStream:
:type movie: str :type movie: str
""" """
msg = {"type": type, "action": action, "series": series, "episode": episode, "movie": movie} msg = {"type": type, "action": action, "series": series, "episode": episode, "movie": movie}
self.queue.append("retry: 1000\ndata:" + json.dumps(msg) + "\n\n") self.queue.append("data:" + json.dumps(msg) + "\n\n")
def read(self): def read(self):
""" """
@ -35,11 +34,8 @@ class EventStream:
""" """
while True: while True:
if self.queue: while self.queue:
return self.queue.popleft() yield self.queue.popleft()
else:
return ':'
time.sleep(0.1)
event_stream = EventStream() event_stream = EventStream()

@ -326,14 +326,15 @@ def movies_full_scan_subtitles():
def series_scan_subtitles(no): def series_scan_subtitles(no):
episodes = database.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId=?", (no,)) episodes = database.execute("SELECT path FROM table_episodes WHERE sonarrSeriesId=? ORDER BY sonarrEpisodeId",
(no,))
for episode in episodes: for episode in episodes:
store_subtitles(episode['path'], path_replace(episode['path'])) store_subtitles(episode['path'], path_replace(episode['path']))
def movies_scan_subtitles(no): def movies_scan_subtitles(no):
movies = database.execute("SELECT path FROM table_movies WHERE radarrId=?", (no,)) movies = database.execute("SELECT path FROM table_movies WHERE radarrId=? ORDER BY radarrId", (no,))
for movie in movies: for movie in movies:
store_subtitles_movie(movie['path'], path_replace_movie(movie['path'])) store_subtitles_movie(movie['path'], path_replace_movie(movie['path']))

@ -252,6 +252,8 @@
<script src="{{ url_for('static',filename='datatables/dataTables.responsive.min.js') }}"></script> <script src="{{ url_for('static',filename='datatables/dataTables.responsive.min.js') }}"></script>
<script src="{{ url_for('static',filename='plugins/datatables.net-bs4/js/dataTables.bootstrap4.min.js') }}"></script> <script src="{{ url_for('static',filename='plugins/datatables.net-bs4/js/dataTables.bootstrap4.min.js') }}"></script>
<script src="{{ url_for('static',filename='js/custom.js') }}"></script> <script src="{{ url_for('static',filename='js/custom.js') }}"></script>
<!-- Polyfill for older browsers without native support for the HTML5 EventSource API. -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=EventSource"></script>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
@ -261,8 +263,15 @@
$('[data-toggle="tooltip"]').tooltip({html: true}); $('[data-toggle="tooltip"]').tooltip({html: true});
}); });
var events = new EventSource('{{ url_for('api.events') }}'); events = new EventSource('{{ url_for('api.events') }}');
events.onmessage = function (event) {
// Handler for when the stream is opened (either the first time or after a reconnect).
events.addEventListener('open', function(event) {
console.log('Stream is open');
}, false);
// Handler for new messages.
events.addEventListener('message', event => {
var event_json = JSON.parse(event.data); var event_json = JSON.parse(event.data);
if (event_json.series === {{id}}) { if (event_json.series === {{id}}) {
if (event_json.type === 'series' && event_json.action === 'update' && event_json.episode == null) { if (event_json.type === 'series' && event_json.action === 'update' && event_json.episode == null) {
@ -302,7 +311,19 @@
} }
} }
} }
}; }, false);
// Handler for a dropped connection or the server closing the connection.
events.addEventListener('error', function(event) {
switch (event.target.readyState) {
case EventSource.CONNECTING:
console.log('Reconnecting...');
break;
case EventSource.CLOSED:
console.log('Connection failed, will not reconnect');
break;
}
}, false);
function BadgesAjax() { function BadgesAjax() {
$.ajax({ $.ajax({
@ -328,6 +349,10 @@
}) })
} }
}); });
$(window).on('beforeunload', function() {
events.close();
});
</script> </script>
{% endblock tail_js %} {% endblock tail_js %}
{% block tail %} {% block tail %}

Loading…
Cancel
Save