You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

from couchpotato.core.helpers.encoding import tryUrlencode
from couchpotato.core.helpers.variable import splitString
14 years ago
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
import base64
log = CPLog(__name__)
class XBMC(Notification):
listen_to = ['renamer.after']
def notify(self, message = '', data = {}, listener = None):
if self.isDisabled(): return
14 years ago
hosts = splitString(self.conf('host'))
successful = 0
for host in hosts:
if self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host):
successful += 1
if self.send({'command': 'ExecBuiltIn', 'parameter': 'XBMC.updatelibrary(video)'}, host):
successful += 1
return successful == len(hosts) * 2
14 years ago
def send(self, command, host):
url = 'http://%s/xbmcCmds/xbmcHttp/?%s' % (host, tryUrlencode(command))
14 years ago
14 years ago
headers = {}
if self.conf('password'):
14 years ago
headers = {
'Authorization': "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('password')))[:-1]
}
14 years ago
try:
self.urlopen(url, headers = headers, show_error = False)
except:
14 years ago
log.error("Couldn't sent command to XBMC")
14 years ago
return False
log.info('XBMC notification to %s successful.', host)
14 years ago
return True