Advanced option for XBMC to only update first in list

Thanks @cliffordwhansen
This commit is contained in:
Ruud
2013-06-15 22:17:23 +02:00
parent 9bf006f4d3
commit ca9a78eea4
2 changed files with 42 additions and 9 deletions
@@ -31,6 +31,13 @@ config = [{
'default': '',
'type': 'password',
},
{
'name': 'only_first',
'default': 0,
'type': 'bool',
'advanced': True,
'description': 'Only update the first host when movie snatched, useful for synced XBMC',
},
{
'name': 'on_snatch',
'default': 0,
+35 -9
View File
@@ -1,8 +1,10 @@
from couchpotato.core.helpers.variable import splitString
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
from urllib2 import URLError
import base64
import json
import socket
import traceback
import urllib
@@ -20,19 +22,30 @@ class XBMC(Notification):
hosts = splitString(self.conf('host'))
successful = 0
max_successful = 0
for host in hosts:
if self.use_json_notifications.get(host) is None:
self.getXBMCJSONversion(host, message = message)
if self.use_json_notifications.get(host):
response = self.request(host, [
calls = [
('GUI.ShowNotification', {'title': self.default_title, 'message': message, 'image': self.getNotificationImage('small')}),
('VideoLibrary.Scan', {}),
])
]
if not self.conf('only_first') or hosts.index(host) == 0:
calls.append(('VideoLibrary.Scan', {}))
max_successful += len(calls)
response = self.request(host, calls)
else:
response = self.notifyXBMCnoJSON(host, {'title':self.default_title, 'message':message})
response += self.request(host, [('VideoLibrary.Scan', {})])
if not self.conf('only_first') or hosts.index(host) == 0:
response += self.request(host, [('VideoLibrary.Scan', {})])
max_successful += 1
max_successful += 1
try:
for result in response:
@@ -44,7 +57,7 @@ class XBMC(Notification):
except:
log.error('Failed parsing results: %s', traceback.format_exc())
return successful == len(hosts) * 2
return successful == max_successful
def getXBMCJSONversion(self, host, message = ''):
@@ -53,7 +66,7 @@ class XBMC(Notification):
# XBMC JSON-RPC version request
response = self.request(host, [
('JSONRPC.Version', {})
])
])
for result in response:
if (result.get('result') and type(result['result']['version']).__name__ == 'int'):
# only v2 and v4 return an int object
@@ -138,7 +151,7 @@ class XBMC(Notification):
# <li>Error:<message>
# </html>
#
response = self.urlopen(server, headers = headers)
response = self.urlopen(server, headers = headers, timeout = 3, show_error = False)
if 'OK' in response:
log.debug('Returned from non-JSON-type request %s: %s', (host, response))
@@ -149,6 +162,13 @@ class XBMC(Notification):
# manually fake expected response array
return [{'result': 'Error'}]
except URLError, e:
if isinstance(e.reason, socket.timeout):
log.info('Couldn\'t send request to XBMC, assuming it\'s turned off')
return [{'result': 'Error'}]
else:
log.error('Failed sending non-JSON-type request to XBMC: %s', traceback.format_exc())
return [{'result': 'Error'}]
except:
log.error('Failed sending non-JSON-type request to XBMC: %s', traceback.format_exc())
return [{'result': 'Error'}]
@@ -177,11 +197,17 @@ class XBMC(Notification):
try:
log.debug('Sending request to %s: %s', (host, data))
rdata = self.urlopen(server, headers = headers, params = data, multipart = True)
response = json.loads(rdata)
response = self.getJsonData(server, headers = headers, params = data, timeout = 3, show_error = False)
log.debug('Returned from request %s: %s', (host, response))
return response
except URLError, e:
if isinstance(e.reason, socket.timeout):
log.info('Couldn\'t send request to XBMC, assuming it\'s turned off')
return []
else:
log.error('Failed sending request to XBMC: %s', traceback.format_exc())
return []
except:
log.error('Failed sending request to XBMC: %s', traceback.format_exc())
return []