From a198250cca9273df098a34fb271f83106d596d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sat, 21 Mar 2020 09:24:32 -0400 Subject: [PATCH] WIP --- bazarr/main.py | 112 +------- views/_main.html | 2 +- views/settingsradarr.html | 574 +++++++++++++++++++++++--------------- views/settingssonarr.html | 211 ++++++++++++-- 4 files changed, 558 insertions(+), 341 deletions(-) diff --git a/bazarr/main.py b/bazarr/main.py index 76d34a469..52c85ae7c 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -16,8 +16,8 @@ import ast import hashlib import warnings import queueconfig -import platform import apprise +import requests from get_args import args @@ -38,13 +38,12 @@ from get_languages import load_language_in_db, language_from_alpha3, language_fr from flask import make_response, request, redirect, abort, render_template, Response, session, flash, url_for, \ send_file, stream_with_context -from get_providers import get_providers, get_providers_auth, list_throttled_providers from get_series import * from get_episodes import * from get_movies import * -from utils import history_log, history_log_movie, get_sonarr_version, get_radarr_version from scheduler import Scheduler +from check_update import check_and_apply_update from subliminal_patch.extensions import provider_registry as provider_manager from functools import wraps @@ -173,6 +172,7 @@ def logout(): def shutdown(): doShutdown() + def doShutdown(): try: server.stop() @@ -598,16 +598,19 @@ def settingssonarr(): return render_template('settingssonarr.html') +@app.route('/settingsradarr/') +@login_required +def settingsradarr(): + return render_template('settingsradarr.html') + + @app.route('/check_update') @login_required def check_update(): - - ref = request.environ['HTTP_REFERER'] - if not args.no_update: check_and_apply_update() - redirect(ref) + return '', 200 @app.route('/systemtasks') @@ -640,21 +643,6 @@ def systemreleases(): return render_template('systemreleases.html') -@app.route('/logs') -@login_required -def get_logs(): - - logs = [] - with io.open(os.path.join(args.config_dir, 'log', 'bazarr.log'), encoding='UTF-8') as file: - for line in file.readlines(): - lin = [] - lin = line.split('|') - logs.append(lin) - logs.reverse() - - return dict(data=logs) - - def configured(): database.execute("UPDATE system SET configured = 1") @@ -719,6 +707,7 @@ def api_movies_history(): return dict(subtitles=history_subs) +@app.route('/test_url', methods=['GET']) @app.route('/test_url//', methods=['GET']) @login_required def test_url(protocol, url): @@ -742,87 +731,10 @@ def test_notification(protocol, provider): apobj.notify( title='Bazarr test notification', - body=('Test notification') + body='Test notification' ) -@app.route('/notifications') -@login_required -def notifications(): - if queueconfig.notifications: - test = queueconfig.notifications - return queueconfig.notifications.read() or '' - else: - return abort(400) - - -@app.route('/running_tasks') -@login_required -def running_tasks_list(): - - return dict(tasks=scheduler.get_running_tasks()) - - -@app.route('/episode_history/') -@login_required -def episode_history(no): - - episode_history = database.execute("SELECT action, timestamp, language, provider, score FROM table_history " - "WHERE sonarrEpisodeId=? ORDER BY timestamp DESC", (no,)) - for item in episode_history: - item['timestamp'] = "
" + \ - pretty.date(datetime.fromtimestamp(item['timestamp'])) + "
" - if item['language']: - item['language'] = language_from_alpha2(item['language']) - else: - item['language'] = "undefined" - if item['score']: - item['score'] = str(round((int(item['score']) * 100 / 360), 2)) + "%" - - return dict(data=episode_history) - - -@app.route('/movie_history/') -@login_required -def movie_history(no): - - movie_history = database.execute("SELECT action, timestamp, language, provider, score FROM table_history_movie " - "WHERE radarrId=? ORDER BY timestamp DESC", (no,)) - for item in movie_history: - if item['action'] == 0: - item['action'] = "
" - elif item['action'] == 1: - item['action'] = "
" - elif item['action'] == 2: - item['action'] = "
" - elif item['action'] == 3: - item['action'] = "
" - elif item['action'] == 4: - item['action'] = "
" - - item['timestamp'] = "
" + \ - pretty.date(datetime.fromtimestamp(item['timestamp'])) + "
" - if item['language']: - item['language'] = language_from_alpha2(item['language']) - else: - item['language'] = "undefined" - if item['score']: - item['score'] = str(round((int(item['score']) * 100 / 120), 2)) + '%' - - return dict(data=movie_history) - - # Mute DeprecationWarning warnings.simplefilter("ignore", DeprecationWarning) # Mute Insecure HTTPS requests made to Sonarr and Radarr diff --git a/views/_main.html b/views/_main.html index 557aa23b3..3aab1b70b 100644 --- a/views/_main.html +++ b/views/_main.html @@ -187,7 +187,7 @@ diff --git a/views/settingsradarr.html b/views/settingsradarr.html index a0501a9e8..d7b13d94a 100644 --- a/views/settingsradarr.html +++ b/views/settingsradarr.html @@ -1,248 +1,380 @@ -
Connection settings
-
-
-
-
- +{% extends '_main.html' %} + +{% block title %}Radarr - Bazarr{% endblock %} + +{% block page_head %} + +{% endblock page_head %} + +{% block bcleft %} +
+ -
-
-
- - +
Save
+ +
+{% endblock bcleft %} + +{% block bcright %} + +{% endblock bcright %} + +{% block body %} +
+
+

Use Radarr

+
+
+
+ Enabled +
+
+
-
+
-
-
- -
-
-
-
- +
+

Host

+
+
+
+ Hostname or IP Address +
+
+
-
- -
- -
-
- -
-
-
-
- +
+
+
+ Port Number +
+
+
-
- -
- -
-
- -
-
-
- -
-
- -
- -
-
- -
-
-
- - -
-
-
- -
-
- -
-
-
-
- +
+
+
+ URL Base +
+
+
-
- + + -
-
- -
-
-
- - +

+
+
+ +
+
+ +
+
+

Options


@@ -116,17 +125,119 @@

-

PAth Mapping

+

Path Mappings


- +
+
-
+ +

+ + + + + + {% endblock body %} {% block tail %} @@ -157,6 +268,8 @@ formdata.set($(this).prop('id'), $(this).prop('checked')); }); + formdata.append('settings-general-path_mappings', JSON.stringify(table.rows().data().toArray())); + $.ajax({ url: "{{ url_for('api.savesettings') }}", data: formdata, @@ -174,34 +287,94 @@ }); }); - table = $('#path_mapping').DataTable({ - data: [["/tvsonarr", "/tvbazarr"]], + var path_mapping = jQuery.makeArray({{ settings.general.path_mappings|safe }}) + path_mapping = $.grep(path_mapping, function(v) { + return v[0] !== "" || v[1] !== ""; + }); + + var table = $('#path_mapping').DataTable({ + data: path_mapping, columns: [{ - title: "Path for Sonarr", - type: "text" - }, { - title: "Path for Bazarr", - type: "text" - }], - dom: 'Bfrtip', // Needs button container - select: 'single', + title: "Path for Sonarr", + type: "text" + }, + { + title: "Path for Bazarr", + type: "text" + }], + dom: 'Bfrtip', + select: { + style: 'single' + }, + language: { + zeroRecords: 'No Path Mappings' + }, + searching: false, + ordering: false, + lengthChange: true, responsive: true, - altEditor: true, // Enable altEditor + paging: false, + info: false, buttons: [{ text: 'Add', - name: 'add' // do not change name + action: function () { + $('#addModal').modal('show'); + } }, { - extend: 'selected', // Bind to Selected row + extend: 'selected', text: 'Edit', - name: 'edit' // do not change name + action: function () { + $('#edit_path_sonarr').val(table.row( { selected: true } ).data()[0]); + $('#edit_path_bazarr').val(table.row( { selected: true } ).data()[1]); + $('#editModal').modal('show'); + } }, { - extend: 'selected', // Bind to Selected row + extend: 'selected', text: 'Delete', - name: 'delete' // do not change name + action: function () { + $('#deleteModal').modal('show'); + } }] }); + + $('#add_save_button').on('click', function(e) { + e.preventDefault(); + table.row.add([ $('#add_path_sonarr').val(), $('#add_path_bazarr').val()]).draw(); + $('#add_path_sonarr').val(''); + $('#add_path_bazarr').val(''); + $('#addModal').modal('hide'); + }); + + $('#edit_save_button').on('click', function(e) { + e.preventDefault(); + table.row( { selected: true } ).data([ $('#edit_path_sonarr').val(), $('#edit_path_bazarr').val()]); + $('#editModal').modal('hide'); + }); + + $('#delete_yes_button').on('click', function(e) { + e.preventDefault(); + table.row( { selected: true } ).remove().draw(); + $('#deleteModal').modal('hide'); + }); + + $('#test_sonarr_connection').on('click', function() { + if ($('#settings-sonarr-ssl').is(':checked')) { + var protocol = 'https'; + } else { + var protocol = 'http'; + } + var sonarr_url = $('#settings-sonarr-ip').val() + ":" + $('#settings-sonarr-port').val() + $('#settings-sonarr-base_url').val().replace(/\/$/, "") + "/api/system/status?apikey=" + $('#settings-sonarr-apikey').val(); + + $.getJSON("{{ url_for('test_url') }}/" + protocol + "/" + encodeURIComponent(sonarr_url), function (data) { + if (data.status) { + $('#test_sonarr_span').text('Test Successful: Sonarr v' + data.version).css('color', 'green'); + } else { + $('#test_sonarr_span').text('Test Failed').css('color', 'red'); + } + }); + }); }); {% endblock tail %}