1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-24 16:52:06 +00:00

Removed dependency on Pillow(PIL) module and added button to check Soanrr and Radarr connection settings #80

This commit is contained in:
morpheus65535 2018-09-12 23:17:46 -04:00
parent 98d5efb95e
commit ae108adcb0
2 changed files with 168 additions and 29 deletions

View file

@ -62,16 +62,12 @@ bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), 'views/')
bottle.debug(True)
bottle.TEMPLATES.clear()
from json import dumps
import itertools
import operator
import requests
import pretty
from datetime import datetime, timedelta
from PIL import Image
from io import BytesIO
from fdsend import send_file
import urllib
import math
import ast
import hashlib
@ -159,15 +155,14 @@ def image_proxy(url):
apikey = get_sonarr_settings()[4]
url_image = url_sonarr_short + '/' + url + '?apikey=' + apikey
try:
img_pil = Image.open(BytesIO(requests.get(url_sonarr + '/api' + url_image.split(url_sonarr)[1], timeout=15, verify=False).content))
image_buffer = BytesIO(requests.get(url_sonarr + '/api' + url_image.split(url_sonarr)[1], timeout=15, verify=False).content)
except:
return None
else:
img_buffer = BytesIO()
img_pil.tobytes()
img_pil.save(img_buffer, img_pil.format)
img_buffer.seek(0)
return send_file(img_buffer, ctype=img_pil.format)
image_buffer.seek(0)
bytes = image_buffer.read()
response.set_header('Content-type', 'image/jpeg')
return bytes
@route(base_url + 'image_proxy_movies/<url:path>', method='GET')
@custom_auth_basic(check_credentials)
@ -177,16 +172,15 @@ def image_proxy_movies(url):
apikey = get_radarr_settings()[4]
try:
url_image = (url_radarr_short + '/' + url + '?apikey=' + apikey).replace('/fanart.jpg', '/banner.jpg')
img_pil = Image.open(BytesIO(requests.get(url_radarr + '/api' + url_image.split(url_radarr)[1], timeout=15, verify=False).content))
image_buffer = BytesIO(requests.get(url_radarr + '/api' + url_image.split(url_radarr)[1], timeout=15, verify=False).content)
except:
url_image = url_radarr_short + '/' + url + '?apikey=' + apikey
img_pil = Image.open(BytesIO(requests.get(url_radarr + '/api' + url_image.split(url_radarr)[1], timeout=15, verify=False).content))
img_buffer = BytesIO()
img_pil.tobytes()
img_pil.save(img_buffer, img_pil.format)
img_buffer.seek(0)
return send_file(img_buffer, ctype=img_pil.format)
image_buffer = BytesIO(requests.get(url_radarr + '/api' + url_image.split(url_radarr)[1], timeout=15, verify=False).content)
else:
image_buffer.seek(0)
bytes = image_buffer.read()
response.set_header('Content-type', 'image/jpeg')
return bytes
@route(base_url)
@ -1587,6 +1581,17 @@ def api_history():
c.close()
return dict(subtitles=data)
@route(base_url + 'test_url/<url:path>', method='GET')
@custom_auth_basic(check_credentials)
def test_url(url):
try:
result = requests.get(url).json()['version']
except:
return dict(status=False, version=result)
else:
return dict(status=True, version=result)
logging.info('Bazarr is started and waiting for request on http://' + str(ip) + ':' + str(port) + str(base_url))
run(host=ip, port=port, server='waitress')
logging.info('Bazarr has been stopped.')

View file

@ -569,6 +569,23 @@
<div class="ui dividing header">Connection settings</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Settings validation:</label>
</div>
<div class="two wide column">
<button id="sonarr_validate" class="test ui blue button" type="button">
Test
</button>
</div>
<div class="seven wide column">
<div id="sonarr_validated" class="ui read-only checkbox">
<input id="sonarr_validated_checkbox" type="checkbox">
<label id="sonarr_validation_result">Not tested recently</label>
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Hostname or IP address</label>
@ -576,7 +593,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_sonarr_ip" type="text" value="{{settings_sonarr[0]}}">
<input id="settings_sonarr_ip" name="settings_sonarr_ip" class="sonarr_config" type="text" value="{{settings_sonarr[0]}}">
</div>
</div>
</div>
@ -594,7 +611,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_sonarr_port" type="text" value="{{settings_sonarr[1]}}">
<input id="settings_sonarr_port" name="settings_sonarr_port" class="sonarr_config" type="text" value="{{settings_sonarr[1]}}">
</div>
</div>
</div>
@ -611,7 +628,7 @@
</div>
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_sonarr_baseurl" type="text" value="{{settings_sonarr[2]}}">
<input id="settings_sonarr_baseurl" name="settings_sonarr_baseurl" class="sonarr_config" type="text" value="{{settings_sonarr[2]}}">
</div>
</div>
<div class="collapsed center aligned column">
@ -627,7 +644,7 @@
</div>
<div class="one wide column">
<div id="sonarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings_sonarr[3]}}>
<input name="settings_sonarr_ssl" type="checkbox">
<input id="settings_sonarr_ssl" name="settings_sonarr_ssl" type="checkbox">
<label></label>
</div>
</div>
@ -640,7 +657,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_sonarr_apikey" type="text" value="{{settings_sonarr[4]}}">
<input id="settings_sonarr_apikey" name="settings_sonarr_apikey" class="sonarr_config" type="text" value="{{settings_sonarr[4]}}">
</div>
</div>
</div>
@ -678,6 +695,23 @@
<div class="ui dividing header">Connection settings</div>
<div class="twelve wide column">
<div class="ui grid">
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Settings validation:</label>
</div>
<div class="two wide column">
<button id="radarr_validate" class="test ui blue button" type="button">
Test
</button>
</div>
<div class="seven wide column">
<div id="radarr_validated" class="ui read-only checkbox">
<input id="radarr_validated_checkbox" type="checkbox">
<label id="radarr_validation_result">Not tested recently</label>
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Hostname or IP address</label>
@ -685,7 +719,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_radarr_ip" type="text" value="{{settings_radarr[0]}}">
<input id="settings_radarr_ip" name="settings_radarr_ip" type="text" class="radarr_config" value="{{settings_radarr[0]}}">
</div>
</div>
</div>
@ -703,7 +737,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_radarr_port" type="text" value="{{settings_radarr[1]}}">
<input id="settings_radarr_port" name="settings_radarr_port" type="text" class="radarr_config" value="{{settings_radarr[1]}}">
</div>
</div>
</div>
@ -720,7 +754,7 @@
</div>
<div class="five wide column">
<div class="ui fluid input">
<input name="settings_radarr_baseurl" type="text" value="{{settings_radarr[2]}}">
<input id="settings_radarr_baseurl" name="settings_radarr_baseurl" type="text" class="radarr_config" value="{{settings_radarr[2]}}">
</div>
</div>
<div class="collapsed center aligned column">
@ -736,7 +770,7 @@
</div>
<div class="one wide column">
<div id="radarr_ssl_div" class="ui toggle checkbox" data-ssl={{settings_radarr[3]}}>
<input name="settings_radarr_ssl" type="checkbox">
<input id="settings_radarr_ssl" name="settings_radarr_ssl" type="checkbox">
<label></label>
</div>
</div>
@ -749,7 +783,7 @@
<div class="five wide column">
<div class='field'>
<div class="ui fluid input">
<input name="settings_radarr_apikey" type="text" value="{{settings_radarr[4]}}">
<input id="settings_radarr_apikey" name="settings_radarr_apikey" type="text" class="radarr_config" value="{{settings_radarr[4]}}">
</div>
</div>
</div>
@ -1230,7 +1264,7 @@
.tab()
;
$('a:not(.tabs), button:not(.cancel)').click(function(){
$('a:not(.tabs), button:not(.cancel, .test)').click(function(){
$('#loader').addClass('active');
})
@ -1333,6 +1367,9 @@
$('#settings_use_sonarr').checkbox({
onChecked: function() {
$("#sonarr_tab").removeClass('disabled');
$('#sonarr_validated').checkbox('uncheck');
$('.form').form('validate form');
$('#loader').removeClass('active');
},
onUnchecked: function() {
$("#sonarr_tab").addClass('disabled');
@ -1350,6 +1387,9 @@
$('#settings_use_radarr').checkbox({
onChecked: function() {
$("#radarr_tab").removeClass('disabled');
$('#sonarr_validated').checkbox('uncheck');
$('.form').form('validate form');
$('#loader').removeClass('active');
},
onUnchecked: function() {
$("#radarr_tab").addClass('disabled');
@ -1560,6 +1600,14 @@
}
]
},
sonarr_validated_checkbox : {
depends: 'settings_general_use_sonarr',
rules : [
{
type : 'checked'
}
]
},
settings_sonarr_ip : {
depends: 'settings_general_use_sonarr',
rules : [
@ -1590,6 +1638,14 @@
}
]
},
radarr_validated_checkbox : {
depends: 'settings_general_use_radarr',
rules : [
{
type : 'checked'
}
]
},
settings_radarr_ip : {
depends: 'settings_general_use_radarr',
rules : [
@ -1676,4 +1732,82 @@
$('.form').form('validate form');
$('#loader').removeClass('active');
})
$('#sonarr_validate').click(function() {
if ($('#sonarr_ssl_div').checkbox('is checked')) {
sonarr_url = 'https://';
} else {
sonarr_url = 'http://';
}
sonarr_url += $('#settings_sonarr_ip').val() + ":" + $('#settings_sonarr_port').val() + "/" + $('#settings_sonarr_baseurl').val().replace(/^\/|\/$/g, '') + "/api/system/status?apikey=" + $('#settings_sonarr_apikey').val();
$.getJSON("{{base_url}}test_url/" + encodeURIComponent(sonarr_url), function (data) {
if (data.status) {
$('#sonarr_validated').checkbox('check');
$('#sonarr_validation_result').text('Test successful: Sonarr v' + data.version).css('color', 'green');
$('.form').form('validate form');
$('#loader').removeClass('active');
} else {
$('#sonarr_validated').checkbox('uncheck');
$('#sonarr_validation_result').text('Test failed').css('color', 'red');
$('.form').form('validate form');
$('#loader').removeClass('active');
}
});
})
$('.sonarr_config').keyup(function() {
$('#sonarr_validated').checkbox('uncheck');
$('#sonarr_validation_result').text('You must test your Sonarr connection settings before saving settings.').css('color', 'red');
$('.form').form('validate form');
$('#loader').removeClass('active');
})
$('#settings_sonarr_ssl').change(function() {
$('#sonarr_validated').checkbox('uncheck');
$('#sonarr_validation_result').text('You must test your Sonarr connection settings before saving settings.').css('color', 'red');
$('.form').form('validate form');
$('#loader').removeClass('active');
})
$("#sonarr_validated").checkbox('check');
$('#radarr_validate').click(function() {
if ($('#radarr_ssl_div').checkbox('is checked')) {
radarr_url = 'https://';
} else {
radarr_url = 'http://';
}
radarr_url += $('#settings_radarr_ip').val() + ":" + $('#settings_radarr_port').val() + "/" + $('#settings_radarr_baseurl').val().replace(/^\/|\/$/g, '') + "/api/system/status?apikey=" + $('#settings_radarr_apikey').val();
$.getJSON("{{base_url}}test_url/" + encodeURIComponent(radarr_url), function (data) {
if (data.status) {
$('#radarr_validated').checkbox('check');
$('#radarr_validation_result').text('Test successful: Radarr v' + data.version).css('color', 'green');
$('.form').form('validate form');
$('#loader').removeClass('active');
} else {
$('#radarr_validated').checkbox('uncheck');
$('#radarr_validation_result').text('Test failed').css('color', 'red');
$('.form').form('validate form');
$('#loader').removeClass('active');
}
});
})
$('.radarr_config').keyup(function() {
$('#radarr_validated').checkbox('uncheck');
$('#radarr_validation_result').text('You must test your Sonarr connection settings before saving settings.').css('color', 'red');
$('.form').form('validate form');
$('#loader').removeClass('active');
})
$('#settings_radarr_ssl').change(function() {
$('#radarr_validated').checkbox('uncheck');
$('#radarr_validation_result').text('You must test your Sonarr connection settings before saving settings.').css('color', 'red');
$('.form').form('validate form');
$('#loader').removeClass('active');
})
$("#radarr_validated").checkbox('check');
</script>