pull/884/head
Louis Vézina 5 years ago
parent 8543ee1b7a
commit df90c6e722

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

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

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

@ -791,23 +791,15 @@ def movie(no):
@app.route('/scan_disk/<int:no>', 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/<int:no>', 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/<int:no>', 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():

@ -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) {
if (event_json.series === {{id}}) {
if (event_json.type === 'series' && event_json.action === 'update' && event_json.episode == null) {
seriesDetailsRefresh();
}
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]);
if (data.data.length) {
$('#episodes').DataTable().row.add(data.data[0]).draw();
$('[data-toggle="tooltip"]').tooltip({html: true});
}
})
}
}
if (event_json.type === 'series') {
if (event_json.series === {{id}}) {
seriesDetailsRefresh();
}
/*
})
} 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});
}
}
}
};

@ -38,11 +38,11 @@
{% block bcleft %}
<div class="">
<button class="btn btn-outline">
<div><i class="fas fa-sync align-top text-themecolor text-center font-20" aria-hidden="true"></i></div>
<div><i class="fas fa-sync align-top text-themecolor text-center font-20" id="scan_button" aria-hidden="true"></i></div>
<div class="align-bottom text-themecolor small text-center">Scan Disk</div>
</button>
<button class="btn btn-outline">
<div><i class="fas fa-search align-top text-themecolor text-center font-20" aria-hidden="true"></i></div>
<div><i class="fas fa-search align-top text-themecolor text-center font-20" id="search_button" aria-hidden="true"></i></div>
<div class="align-bottom text-themecolor small text-center">Search</div>
</button>
</div>
@ -51,7 +51,7 @@
{% block bcright %}
<div class="d-flex m-t-5 justify-content-end">
<button class="btn btn-outline">
<div><i class="fas fa-wrench align-top text-themecolor text-center font-20" aria-hidden="true"></i></div>
<div><i class="fas fa-wrench align-top text-themecolor text-center font-20" id="edit_button" aria-hidden="true"></i></div>
<div class="align-bottom text-themecolor small text-center">Edit Series</div>
</button>
</div>
@ -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);
}

Loading…
Cancel
Save