mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 00:43:37 +00:00
Merge pull request #700 from JackDandy/feature/AddDiscoverEmby
Add button 'Discover' Emby server to notifications.
This commit is contained in:
commit
3a2466a0b3
5 changed files with 69 additions and 13 deletions
|
@ -77,6 +77,7 @@
|
|||
* Add FileList torrent provider
|
||||
* Add provider Anizb
|
||||
* Change TorrentDay to use its 2.x interface
|
||||
* Add button 'Discover' Emby server to notifications
|
||||
|
||||
|
||||
### 0.11.11 (2016-04-05 19:20:00 UTC)
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
<span class="component-title">Host(s) running Emby</span>
|
||||
<span class="component-desc">
|
||||
<input type="text" name="emby_host" id="emby_host" value="$sickbeard.EMBY_HOST" class="form-control input-sm input250">
|
||||
<input type="button" class="btn" value="Discover" id="discover-emby">
|
||||
<div class="clear-left"><p>IP:Port [, IP:Port] (e.g. 192.168.0.1:8096, 192.168.1.2:8096)</p></div>
|
||||
</span>
|
||||
</label>
|
||||
|
|
|
@ -37,30 +37,46 @@
|
|||
});
|
||||
});
|
||||
|
||||
$('#discover-emby').click(function () {
|
||||
$(this).prop('disabled', !0);
|
||||
$('#emby_host,#emby_apikey').removeClass('warning');
|
||||
$('#testEMBY-result').html(loading);
|
||||
$.get(sbRoot + '/home/discover_emby')
|
||||
.done(function (data) {
|
||||
var result = 'Unable to discover a server, is one running?';
|
||||
if ('' != data) {
|
||||
$('#emby_host').val(data);
|
||||
result = 'Server found.';
|
||||
}
|
||||
$('#testEMBY-result').html(result);
|
||||
$('#discover-emby').prop('disabled', !1);
|
||||
});
|
||||
});
|
||||
|
||||
$('#testEMBY').click(function () {
|
||||
var emby_host = $('#emby_host').val();
|
||||
var emby_apikey = $('#emby_apikey').val();
|
||||
if (!emby_host || !emby_apikey) {
|
||||
var host$ = $('#emby_host'), host = $.trim(host$.val());
|
||||
var apikey$ = $('#emby_apikey'), apikey = $.trim(apikey$.val());
|
||||
if (!host || !apikey) {
|
||||
$('#testEMBY-result').html('Please fill out the necessary fields above.');
|
||||
if (!emby_host) {
|
||||
$('#emby_host').addClass('warning');
|
||||
if (!host) {
|
||||
host$.addClass('warning');
|
||||
} else {
|
||||
$('#emby_host').removeClass('warning');
|
||||
host$.removeClass('warning');
|
||||
}
|
||||
if (!emby_apikey) {
|
||||
$('#emby_apikey').addClass('warning');
|
||||
if (!apikey) {
|
||||
apikey$.addClass('warning');
|
||||
} else {
|
||||
$('#emby_apikey').removeClass('warning');
|
||||
apikey$.removeClass('warning');
|
||||
}
|
||||
return;
|
||||
}
|
||||
$('#emby_host, #emby_apikey').removeClass('warning');
|
||||
$(this).prop('disabled', true);
|
||||
$('#emby_host,#emby_apikey').removeClass('warning');
|
||||
$(this).prop('disabled', !0);
|
||||
$('#testEMBY-result').html(loading);
|
||||
$.get(sbRoot + '/home/testEMBY', {'host': emby_host, 'apikey': emby_apikey})
|
||||
$.get(sbRoot + '/home/testEMBY', {'host': host, 'apikey': apikey})
|
||||
.done(function (data) {
|
||||
$('#testEMBY-result').html(data);
|
||||
$('#testEMBY').prop('disabled', false);
|
||||
$('#testEMBY').prop('disabled', !1);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
import sickbeard
|
||||
from sickbeard import logger
|
||||
from socket import socket, AF_INET, SOCK_DGRAM, SOL_SOCKET, SO_REUSEADDR, SO_BROADCAST, SHUT_RDWR
|
||||
from lib import simplejson as json
|
||||
|
||||
|
||||
class EmbyNotifier:
|
||||
|
@ -114,6 +116,35 @@ class EmbyNotifier:
|
|||
self.response = dict(status_code=r.status_code, ok=r.ok)
|
||||
return r
|
||||
|
||||
@staticmethod
|
||||
def _discover_server():
|
||||
cs = socket(AF_INET, SOCK_DGRAM)
|
||||
mb_listen_port = 7359
|
||||
|
||||
cs.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
|
||||
cs.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
|
||||
cs.settimeout(10)
|
||||
result, sock_issue = '', None
|
||||
for server in ('EmbyServer', 'MediaBrowserServer'):
|
||||
bufr = 'who is %s?' % server
|
||||
try:
|
||||
assert len(bufr) == cs.sendto(bufr, ('255.255.255.255', mb_listen_port)), \
|
||||
'Not all data sent through the socket'
|
||||
message, host = cs.recvfrom(1024)
|
||||
if message:
|
||||
logger.log('%s found at %s: udp query response (%s)' % (server, host[0], message))
|
||||
result = ('{"Address":' not in message and message.split('|')[1] or
|
||||
json.loads(message).get('Address', ''))
|
||||
if result:
|
||||
break
|
||||
except AssertionError:
|
||||
sock_issue = True
|
||||
except Exception:
|
||||
pass
|
||||
if not sock_issue:
|
||||
cs.shutdown(SHUT_RDWR)
|
||||
return result
|
||||
|
||||
def _check_config(self, hosts=None, apikeys=None):
|
||||
|
||||
from sickbeard.helpers import starify
|
||||
|
@ -148,6 +179,9 @@ class EmbyNotifier:
|
|||
# Public functions
|
||||
##############################################################################
|
||||
|
||||
def discover_server(self):
|
||||
return self._discover_server()
|
||||
|
||||
def test_notify(self, host, apikey):
|
||||
|
||||
self.test_mode = True
|
||||
|
|
|
@ -776,6 +776,10 @@ class Home(MainHandler):
|
|||
else:
|
||||
return 'Error sending tweet'
|
||||
|
||||
@staticmethod
|
||||
def discover_emby():
|
||||
return notifiers.emby_notifier.discover_server()
|
||||
|
||||
def testEMBY(self, host=None, apikey=None):
|
||||
self.set_header('Cache-Control', 'max-age=0,no-cache,no-store')
|
||||
|
||||
|
|
Loading…
Reference in a new issue