From 9cb4d8842c7036ec25c3cba20e8526761ccc1e38 Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 11 Jun 2012 10:52:28 +0200 Subject: [PATCH] Notify plex and use default ports. fix #392 --- .../core/notifications/plex/__init__.py | 5 ++-- couchpotato/core/notifications/plex/main.py | 27 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/notifications/plex/__init__.py b/couchpotato/core/notifications/plex/__init__.py index 6714aba9..f908cbb2 100644 --- a/couchpotato/core/notifications/plex/__init__.py +++ b/couchpotato/core/notifications/plex/__init__.py @@ -17,8 +17,9 @@ config = [{ }, { 'name': 'host', - 'default': 'localhost:32400', - 'description': 'Default should be on localhost:32400', + 'default': 'localhost', + 'description': 'Default should be on localhost', + 'advanced': True, }, ], } diff --git a/couchpotato/core/notifications/plex/main.py b/couchpotato/core/notifications/plex/main.py index 72fdef17..ec0f869c 100644 --- a/couchpotato/core/notifications/plex/main.py +++ b/couchpotato/core/notifications/plex/main.py @@ -1,4 +1,5 @@ from couchpotato.core.event import addEvent +from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.logger import CPLog from couchpotato.core.notifications.base import Notification @@ -11,13 +12,14 @@ log = CPLog(__name__) class Plex(Notification): def __init__(self): + super(Plex, self).__init__() addEvent('renamer.after', self.addToLibrary) def addToLibrary(self, group = {}): if self.isDisabled(): return log.info('Sending notification to Plex') - hosts = [cleanHost(x.strip()) for x in self.conf('host').split(",")] + hosts = [cleanHost(x.strip() + ':32400') for x in self.conf('host').split(",")] for host in hosts: @@ -40,3 +42,26 @@ class Plex(Notification): return False return True + + def notify(self, message = '', data = {}, listener = None): + if self.isDisabled(): return + + for host in [x.strip() + ':3000' for x in self.conf('host').split(",")]: + self.send({'command': 'ExecBuiltIn', 'parameter': 'Notification(CouchPotato, %s)' % message}, host) + + return True + + def send(self, command, host): + + url = 'http://%s/xbmcCmds/xbmcHttp/?%s' % (host, tryUrlencode(command)) + + headers = {} + + try: + self.urlopen(url, headers = headers, show_error = False) + except: + log.error("Couldn't sent command to Plex") + return False + + log.info('Plex notification to %s successful.' % host) + return True