pull/884/head
Louis Vézina 5 years ago
parent e562d5e7bb
commit c2de011fad

@ -44,6 +44,16 @@ class Badges(Resource):
return jsonify(result)
class Languages(Resource):
def get(self):
enabled = request.args.get('enabled')
if enabled.lower() in ['true', '1']:
result = database.execute("SELECT * FROM table_settings_languages WHERE enabled=1")
else:
result = database.execute("SELECT * FROM table_settings_languages")
return jsonify(result)
class Series(Resource):
def get(self):
start = request.args.get('start') or 0
@ -96,6 +106,41 @@ class Series(Resource):
return jsonify(draw=draw, recordsTotal=row_count, recordsFiltered=row_count, data=result)
def post(self):
seriesId = request.args.get('seriesid')
lang = request.form.getlist('languages')
if len(lang) > 0:
pass
else:
lang = 'None'
single_language = settings.general.getboolean('single_language')
if single_language:
if str(lang) == "['None']":
lang = 'None'
else:
lang = str(lang)
else:
if str(lang) == "['']":
lang = '[]'
hi = request.form.get('hearing_impaired')
forced = request.form.get('forced')
if hi == "on":
hi = "True"
else:
hi = "False"
result = database.execute("UPDATE table_shows SET languages=?, hearing_impaired=?, forced=? WHERE "
"sonarrSeriesId=?", (str(lang), hi, forced, seriesId))
list_missing_subtitles(no=seriesId)
return '', 204
class Episodes(Resource):
def get(self):
start = request.args.get('start') or 0
@ -317,6 +362,20 @@ class EpisodesSubtitlesUpload(Resource):
return '', 204
class EpisodesScanDisk(Resource):
def get(self):
seriesid = request.args.get('seriesid')
series_scan_subtitles(seriesid)
return '', 200
class EpisodesSearchMissing(Resource):
def get(self):
seriesid = request.args.get('seriesid')
series_download_subtitles(seriesid)
return '', 200
class Movies(Resource):
def get(self):
start = request.args.get('start') or 0
@ -622,6 +681,7 @@ class WantedMovies(Resource):
api.add_resource(Badges, '/badges')
api.add_resource(Languages, '/languages')
api.add_resource(Series, '/series')
api.add_resource(Episodes, '/episodes')
api.add_resource(EpisodesSubtitlesDelete, '/episodes_subtitles_delete')
@ -629,6 +689,8 @@ api.add_resource(EpisodesSubtitlesDownload, '/episodes_subtitles_download')
api.add_resource(EpisodesSubtitlesManualSearch, '/episodes_subtitles_manual_search')
api.add_resource(EpisodesSubtitlesManualDownload, '/episodes_subtitles_manual_download')
api.add_resource(EpisodesSubtitlesUpload, '/episodes_subtitles_upload')
api.add_resource(EpisodesScanDisk, '/episodes_scan_disk')
api.add_resource(EpisodesSearchMissing, '/episodes_search_missing')
api.add_resource(Movies, '/movies')
api.add_resource(HistorySeries, '/history_series')
api.add_resource(HistoryMovies, '/history_movies')

@ -12,6 +12,7 @@ from config import settings, url_sonarr
from helper import path_replace
from list_subtitles import list_missing_subtitles, store_subtitles, series_full_scan_subtitles
from get_subtitle import episode_download_subtitles
from websocket_handler import event_stream
def update_all_episodes():
@ -128,7 +129,11 @@ def sync_episodes():
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
for removed_episode in removed_episodes:
episode_to_delete = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId FROM table_episodes WHERE "
"sonarrEpisodeId=?", (removed_episode,), only_one=True)
database.execute("DELETE FROM table_episodes WHERE sonarrEpisodeId=?", (removed_episode,))
event_stream.write(type='episode', action='delete', series=episode_to_delete['sonarrSeriesId'],
episode=episode_to_delete['sonarrEpisodeId'])
# Update existing episodes in DB
episode_in_db_list = []
@ -157,6 +162,8 @@ def sync_episodes():
''')''', query.values)
if result > 0:
altered_episodes.append([added_episode['sonarrEpisodeId'], added_episode['path']])
event_stream.write(type='episode', action='insert', series=added_episode['sonarrSeriesId'],
episode=added_episode['sonarrEpisodeId'])
else:
logging.debug('BAZARR unable to insert this episode into the database:',
path_replace(added_episode['path']))

@ -232,12 +232,16 @@ def list_missing_subtitles(no=None, epno=None):
else:
actual_subtitles_list.append(item[0])
missing_subtitles = list(set(desired_subtitles) - set(actual_subtitles_list))
missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles['sonarrEpisodeId']]))
missing_subtitles_global.append(tuple([str(missing_subtitles), episode_subtitles['sonarrEpisodeId'],
episode_subtitles['sonarrSeriesId']]))
for missing_subtitles_item in missing_subtitles_global:
database.execute("UPDATE table_episodes SET missing_subtitles=? WHERE sonarrEpisodeId=?",
(missing_subtitles_item[0], missing_subtitles_item[1]))
event_stream.write(type='episode', action='update', series=missing_subtitles_item[2],
episode=missing_subtitles_item[1])
def list_missing_subtitles_movies(no=None):
if no is not None:

@ -84,6 +84,8 @@ def configure_logging(debug=False):
logging.getLogger("subzero").setLevel(logging.DEBUG)
logging.getLogger("git").setLevel(logging.DEBUG)
logging.getLogger("apprise").setLevel(logging.DEBUG)
logging.getLogger("engineio.server").setLevel(logging.DEBUG)
logging.getLogger("socketio.server").setLevel(logging.DEBUG)
logging.debug('Bazarr version: %s', os.environ["BAZARR_VERSION"])
logging.debug('Bazarr branch: %s', settings.general.branch)
logging.debug('Operating system: %s', platform.platform())
@ -94,6 +96,8 @@ def configure_logging(debug=False):
logging.getLogger("subliminal").setLevel(logging.CRITICAL)
logging.getLogger("subliminal_patch").setLevel(logging.CRITICAL)
logging.getLogger("subzero").setLevel(logging.ERROR)
logging.getLogger("engineio.server").setLevel(logging.ERROR)
logging.getLogger("socketio.server").setLevel(logging.ERROR)
logging.getLogger("enzyme").setLevel(logging.CRITICAL)
logging.getLogger("guessit").setLevel(logging.WARNING)

@ -564,44 +564,6 @@ def search_json(query):
return dict(items=search_list)
@app.route('/edit_series/<int:no>', methods=['POST'])
@login_required
def edit_series(no):
ref = request.environ['HTTP_REFERER']
lang = request.form.getlist('languages')
if len(lang) > 0:
pass
else:
lang = 'None'
single_language = settings.general.getboolean('single_language')
if single_language:
if str(lang) == "['None']":
lang = 'None'
else:
lang = str(lang)
else:
if str(lang) == "['']":
lang = '[]'
hi = request.form.get('hearing_impaired')
forced = request.form.get('forced')
if hi == "on":
hi = "True"
else:
hi = "False"
result = database.execute("UPDATE table_shows SET languages=?, hearing_impaired=?, forced=? WHERE "
"sonarrSeriesId=?", (str(lang), hi, forced, no))
list_missing_subtitles(no=no)
redirect(ref)
@app.route('/edit_serieseditor', methods=['POST'])
@login_required
def edit_serieseditor():
@ -753,13 +715,6 @@ def movie(no):
current_port=settings.general.port)
@app.route('/scan_disk/<int:no>', methods=['GET'])
@login_required
def scan_disk(no):
series_scan_subtitles(no)
return '', 200
@app.route('/scan_disk_movie/<int:no>', methods=['GET'])
@login_required
def scan_disk_movie(no):
@ -767,17 +722,6 @@ def scan_disk_movie(no):
return '', 200
@app.route('/search_missing_subtitles/<int:no>', methods=['GET'])
@login_required
def search_missing_subtitles(no):
ref = request.environ['HTTP_REFERER']
add_job(series_download_subtitles, args=[no], name=('search_missing_subtitles_' + str(no)))
redirect(ref)
@app.route('/search_missing_subtitles_movie/<int:no>', methods=['GET'])
@login_required
def search_missing_subtitles_movie(no):
@ -1419,12 +1363,8 @@ def get_logs():
@app.route('/execute/<taskid>')
@login_required
def execute_task(taskid):
ref = request.environ['HTTP_REFERER']
execute_now(taskid)
redirect(ref)
return '', 200
@app.route('/remove_subtitles_movie', methods=['POST'])

@ -33,6 +33,7 @@
href="{{ url_for('static',filename='datatables/responsive.dataTables.min.css') }}">
<link rel="stylesheet" type="text/css"
href="{{ url_for('static',filename='plugins/datatables.net-bs4/css/dataTables.bootstrap4.min.css') }}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
{% endblock head_css %}
{% block head %}
@ -252,6 +253,7 @@
<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/socket.io.js') }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>
<script>
$(document).ready(function () {
@ -261,48 +263,11 @@
$('[data-toggle="tooltip"]').tooltip({html: true});
});
var events = io.connect();
events.on('event', function(event) {
var event_json = JSON.parse(event);
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) {
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});
}
}
}
events = io.connect({
'reconnection': true,
'reconnectionDelay': 1000,
'reconnectionDelayMax' : 5000,
'reconnectionAttempts': 5
});
function BadgesAjax() {

@ -37,12 +37,12 @@
{% block bcleft %}
<div class="">
<button class="btn btn-outline">
<div><i class="fas fa-sync align-top text-themecolor text-center font-20" id="scan_button" aria-hidden="true"></i></div>
<button class="btn btn-outline" id="scan_button">
<div><i class="fas fa-sync align-top text-themecolor text-center font-20" 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" id="search_button" aria-hidden="true"></i></div>
<button class="btn btn-outline" id="search_button">
<div><i class="fas fa-search align-top text-themecolor text-center font-20" aria-hidden="true"></i></div>
<div class="align-bottom text-themecolor small text-center">Search</div>
</button>
</div>
@ -50,8 +50,8 @@
{% 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" id="edit_button" aria-hidden="true"></i></div>
<button class="btn btn-outline" id="edit_button">
<div><i class="fas fa-wrench align-top text-themecolor text-center font-20" aria-hidden="true"></i></div>
<div class="align-bottom text-themecolor small text-center">Edit Series</div>
</button>
</div>
@ -158,18 +158,18 @@
Language
</div>
<div class="form-group col-sm-8 pl-sm-0">
<select class="custom-select" id="manual_language_select" name="language"></select>
<select class="selectpicker" id="manual_language_select" name="language"></select>
</div>
</div>
<div class="row">
<div class="col-sm-2 text-right">
Forced
</div>
<div class="form-group col-sm-8 pl-sm-0">
<div class="custom-control custom-checkbox pl-sm-0">
<div class="form-group col-sm-1 pl-sm-0">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="forced_checkbox" name="forced">
<label class="custom-control-label" for="forced_checkbox">test</label>
</div>
<span class="custom-control-label" for="forced_checkbox"></span>
</label>
</div>
</div>
<div class="row">
@ -199,6 +199,70 @@
</div>
</div>
</div>
<div id="editModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><span id="edit_series_title_span"></span></h5><br>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form class="form" name="edit_form" id="edit_form">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 text-right">
Audio Language
</div>
<div class="form-group col-sm-8 pl-sm-0">
<span id="edit_audio_language_span"></span>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
Subtitles Language(s)
</div>
<div class="form-group col-sm-8 pl-sm-0">
<select class="selectpicker" id="edit_languages_select" name="languages" multiple data-live-search="true"></select>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
Hearing-Impaired
</div>
<div class="form-group col-sm-1 pl-sm-0">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="hi_checkbox" name="hi">
<span class="custom-control-label" for="hi_checkbox"></span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-3 text-right">
Forced
</div>
<div class="form-group col-sm-8 pl-sm-0">
<select class="selectpicker" id="edit_forced_select" name="forced">
<option value="False">False</option>
<option value="True">True</option>
<option value="Both">Both</option>
</select>
</div>
</div>
</div>
<input type="hidden" id="edit_sonarrSeriesId" name="sonarrSeriesId" value="" />
</div>
<div class="modal-footer">
<button type="submit" id="edit_save_button" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>
</form>
</div>
</div>
</div>
{% endblock body %}
{% block tail %}
@ -212,6 +276,8 @@
});
seriesDetailsRefresh();
getLanguages();
getEnabledLanguages();
var table = $('#episodes').DataTable({
"processing": true,
@ -420,12 +486,12 @@
let i;
let text = '<div class="dropdown"><div class="btn-group dropdown"><button class="btn btn-secondary btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fas fa-check-circle" style="color: green;"></i> '+array_matches.length+'</button><div class="dropdown-menu" aria-labelledby="dropdownMenuButton">';
for (i = 0; i < array_matches.length; i++) {
text += '<a class="dropdown-item" href="#">' + array_matches[i] + '</a>';
text += '<a class="dropdown-item disabled" href="#">' + array_matches[i] + '</a>';
}
text += '</div>';
text += '<div class="dropdown"><button class="btn btn-secondary btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fas fa-times-circle" style="color: red;"></i> '+array_dont_matches.length+'</button><div class="dropdown-menu" aria-labelledby="dropdownMenuButton">';
for (i = 0; i < array_dont_matches.length; i++) {
text += '<a class="dropdown-item" href="#">' + array_dont_matches[i] + '</a>';
text += '<a class="dropdown-item disabled" href="#">' + array_dont_matches[i] + '</a>';
}
text += '</div></div></div>';
return text;
@ -495,16 +561,11 @@
$('#upload_sonarrEpisodeId').val($(this).data("sonarrepisodeid"));
$('#upload_title').val($(this).data("episode_title"));
var languages = Array.from(seriesDetails['languages']);
var is_pb = languages.includes('pb');
var is_pt = languages.includes('pt');
$.each(languages, function (i, item) {
$('#manual_language_select').append($('<option>', {
value: item.code2,
text : item.name
}));
$('#manual_language_select').empty();
$.each(enabledLanguages, function (i, item) {
$('#manual_language_select').append('<option value="'+item.code2+'">'+item.name+'</option>');
});
$("#manual_language_select").selectpicker("refresh");
$('#uploadModal')
.modal({
@ -531,13 +592,70 @@
$('#scan_button').on('click', function(e){
e.preventDefault();
$.ajax({
url: "{{ url_for('scan_disk', no=id) }}",
url: "{{ url_for('api.episodesscandisk', seriesid=id) }}",
type: 'GET',
beforeSend: function() {
$('#scan_button').find("i").addClass('fa-spin');
},
complete: function() {
$('#scan_button').find("i").removeClass('fa-spin');
}
});
});
$('#search_button').on('click', function(e){
e.preventDefault();
$.ajax({
url: "{{ url_for('api.episodessearchmissing', seriesid=id) }}",
type: 'GET',
beforeSend: function() {
$('#scan_button').addClass('fa-spin');
$('#search_button').find("i").addClass('fa-spin');
},
complete: function() {
$('#scan_button').removeClass('fa-spin');
$('#search_button').find("i").removeClass('fa-spin');
}
});
});
$('#edit_button').on('click', function(e){
e.preventDefault();
$("#edit_series_title_span").html(seriesDetails['title']);
$("#edit_audio_language_span").text(seriesDetails['audio_language']['name']);
$('#edit_sonarrSeriesId').val(seriesDetails['sonarrSeriesId']);
$('#edit_languages_select').empty();
$.each(enabledLanguages, function (i, item) {
$('#edit_languages_select').append('<option value="'+item.code2+'">'+item.name+'</option>');
});
$("#edit_languages_select").selectpicker("refresh");
var selected_languages = Array();
$.each(Array.from(seriesDetails['languages']), function (i, item) {
selected_languages.push(item.code2);
});
$('#edit_languages_select').selectpicker('val', selected_languages);
$('#hi_checkbox').prop('checked', (seriesDetails['hearing_impaired'] === 'True'));
$('#edit_forced_select').val(seriesDetails['forced']).change();
$('#editModal')
.modal({
focus: false
});
});
$('#edit_form').on('submit', function(e){
e.preventDefault();
var formdata = new FormData(document.getElementById("edit_form"));
$.ajax({
url: "{{ url_for('api.series') }}?seriesid={{id}}",
data: formdata,
processData: false,
contentType: false,
type: 'POST',
success: function(){
seriesDetailsRefresh();
$('#editModal').modal('hide');
}
});
});
@ -545,6 +663,48 @@
$('#uploadModal').on('hidden.bs.modal', function () {
$(this).find('form')[0].reset();
});
events.on('event', function(event) {
var event_json = JSON.parse(event);
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,
success: function (data) {
if (data.data.length) {
$('#episodes').DataTable().rows.add(data.data);
$('#episodes').DataTable().columns.adjust().draw(false);
$('[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,
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();
$('#episodes').DataTable().columns.adjust().draw(false);
$('[data-toggle="tooltip"]').tooltip({html: true});
}
}
}
});
});
function seriesDetailsRefresh() {
@ -581,6 +741,28 @@
$('#seriesHearingImpaired').text('Hearing-Impaired: ' + seriesDetails['hearing_impaired']);
$('#seriesForced').text('Forced: ' + seriesDetails['forced']);
$('#seriesDescription').text(seriesDetails['overview']);
$('[data-toggle="tooltip"]').tooltip({html: true});
});
}
function getLanguages() {
$.ajax({
url: "{{ url_for('api.languages') }}?enabled=false",
async: false,
success:function(data) {
availableLanguages = data;
}
});
}
function getEnabledLanguages() {
$.ajax({
url: "{{ url_for('api.languages') }}?enabled=true",
async: false,
success:function(data) {
enabledLanguages = data;
}
});
}
</script>

@ -86,25 +86,11 @@
},
{
"data": "hearing_impaired",
"className": "dt-center",
"render": function (data) {
if (data === 'False') {
return '<i class="far fa-square"></i>';
} else if (data === 'True') {
return '<i class="far fa-check-square"></i>';
}
}
"className": "dt-center"
},
{
"data": "forced",
"className": "dt-center",
"render": function (data) {
if (data === 'False') {
return '<i class="far fa-square"></i>';
} else if (data === 'True') {
return '<i class="far fa-check-square"></i>';
}
}
"className": "dt-center"
},
{
"data": null,

Loading…
Cancel
Save