diff --git a/couchpotato/core/notifications/xbmc/__init__.py b/couchpotato/core/notifications/xbmc/__init__.py index a4808458..e3c467ce 100644 --- a/couchpotato/core/notifications/xbmc/__init__.py +++ b/couchpotato/core/notifications/xbmc/__init__.py @@ -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, diff --git a/couchpotato/core/notifications/xbmc/main.py b/couchpotato/core/notifications/xbmc/main.py index 925cb80a..ad6fa605 100755 --- a/couchpotato/core/notifications/xbmc/main.py +++ b/couchpotato/core/notifications/xbmc/main.py @@ -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): #