mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-21 00:14:02 +01:00
Cleaned LMS error reporting.
Even upon successful rescan, the code would throw a keyerror back. Not certain why, but LMS sends some really weird unicode JSON back as its result, unlike XBMC, so having response[0]['result'] will always throw back a keyerror. Removing the key, however, and just asking the return to find 'result' works fine.
This commit is contained in:
+5
-11
@@ -247,10 +247,10 @@ class LMS:
|
|||||||
self.hosts = headphones.LMS_HOST
|
self.hosts = headphones.LMS_HOST
|
||||||
|
|
||||||
def _sendjson(self, host):
|
def _sendjson(self, host):
|
||||||
data = {'id': 1, 'method': 'slim.request', 'params': ["",["rescan"]]} #Had a lot of trouble with simplejson, but this works.
|
data = {'id': 1, 'method': 'slim.request', 'params': ["",["rescan"]]}
|
||||||
data = simplejson.JSONEncoder().encode(data)
|
data = simplejson.JSONEncoder().encode(data)
|
||||||
|
|
||||||
content = {'Content-Type': 'application/json', 'Content-Length': len(data)}
|
content = {'Content-Type': 'application/json'}
|
||||||
|
|
||||||
req = urllib2.Request(host+'/jsonrpc.js', data, content)
|
req = urllib2.Request(host+'/jsonrpc.js', data, content)
|
||||||
|
|
||||||
@@ -261,21 +261,15 @@ class LMS:
|
|||||||
return
|
return
|
||||||
|
|
||||||
response = simplejson.JSONDecoder().decode(handle.read())
|
response = simplejson.JSONDecoder().decode(handle.read())
|
||||||
server_result = simplejson.dumps(response)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return response[0]['result']
|
return response['result']
|
||||||
except:
|
except:
|
||||||
logger.warn('LMS returned error: %s' % response[0]['error'])
|
logger.warn('LMS returned error: %s' % response['error'])
|
||||||
return
|
return
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
hosts = [x.strip() for x in self.hosts.split(',')]
|
||||||
#Send the ["rescan"] command to an LMS server.
|
|
||||||
#Note that the command must be prefixed with the 'player' that the command is aimed at,
|
|
||||||
#But with this being a request for the server to update its library, the player is blank, so ""
|
|
||||||
|
|
||||||
hosts = [x.strip() for x in self.hosts.split(',')]
|
|
||||||
|
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
logger.info('Sending library rescan command to LMS @ '+host)
|
logger.info('Sending library rescan command to LMS @ '+host)
|
||||||
|
|||||||
Reference in New Issue
Block a user