diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 3e1258a2..55f0eae9 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -907,6 +907,10 @@ Password of your Plex client API (blank for none) +
+ + Plex Token (for use with Plex Home) +
diff --git a/headphones/config.py b/headphones/config.py index 6ae02086..bc499fce 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -175,6 +175,7 @@ _CONFIG_DEFINITIONS = { 'PLEX_SERVER_HOST': (str, 'Plex', ''), 'PLEX_UPDATE': (int, 'Plex', 0), 'PLEX_USERNAME': (str, 'Plex', ''), + 'PLEX_TOKEN': (str, 'Plex', ''), 'PREFERRED_BITRATE': (str, 'General', ''), 'PREFERRED_BITRATE_ALLOW_LOSSLESS': (int, 'General', 0), 'PREFERRED_BITRATE_HIGH_BUFFER': (int, 'General', 0), diff --git a/headphones/notifiers.py b/headphones/notifiers.py index 24d83b91..6a2978d8 100644 --- a/headphones/notifiers.py +++ b/headphones/notifiers.py @@ -316,6 +316,7 @@ class Plex(object): self.client_hosts = headphones.CONFIG.PLEX_CLIENT_HOST self.username = headphones.CONFIG.PLEX_USERNAME self.password = headphones.CONFIG.PLEX_PASSWORD + self.token = headphones.CONFIG.PLEX_TOKEN def _sendhttp(self, host, command): @@ -354,13 +355,15 @@ class Plex(object): for host in hosts: logger.info('Sending library update command to Plex Media Server@ ' + host) url = "%s/library/sections" % host - try: - xml_sections = minidom.parse(urllib.urlopen(url)) - except IOError, e: - logger.warn("Error while trying to contact Plex Media Server: %s" % e) - return False + if self.token: + params = {'X-Plex-Token': self.token} + else: + params = False + + r = request.request_minidom(url, params=params) + + sections = r.getElementsByTagName('Directory') - sections = xml_sections.getElementsByTagName('Directory') if not sections: logger.info(u"Plex Media Server not running on: " + host) return False @@ -368,11 +371,7 @@ class Plex(object): for s in sections: if s.getAttribute('type') == "artist": url = "%s/library/sections/%s/refresh" % (host, s.getAttribute('key')) - try: - urllib.urlopen(url) - except Exception as e: - logger.warn("Error updating library section for Plex Media Server: %s" % e) - return False + request.request_response(url, params=params) def notify(self, artist, album, albumartpath): @@ -862,4 +861,4 @@ class Email(object): except Exception, e: logger.warn('Error sending Email: %s' % e) - return False \ No newline at end of file + return False diff --git a/headphones/webserve.py b/headphones/webserve.py index 280d1376..164895db 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1121,6 +1121,7 @@ class WebInterface(object): "plex_client_host": headphones.CONFIG.PLEX_CLIENT_HOST, "plex_username": headphones.CONFIG.PLEX_USERNAME, "plex_password": headphones.CONFIG.PLEX_PASSWORD, + "plex_token": headphones.CONFIG.PLEX_TOKEN, "plex_update": checked(headphones.CONFIG.PLEX_UPDATE), "plex_notify": checked(headphones.CONFIG.PLEX_NOTIFY), "nma_enabled": checked(headphones.CONFIG.NMA_ENABLED), @@ -1432,6 +1433,12 @@ class WebInterface(object): result = pushover.notify("hooray!", "This is a test") return str(result) + @cherrypy.expose + def testPlex(self): + logger.info(u"Testing plex updates") + plex = notifiers.Plex() + plex.update() + class Artwork(object): @cherrypy.expose def index(self):