diff --git a/CHANGES.md b/CHANGES.md index 32abbd97..2243c5a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,9 @@ * Add TVRage network name standardization * Change some provider images. Add a few new images * Remove redundant Coming Eps template code used in the old UI -* Change update plex notifier (port from SickBeard) +* Change update Plex notifier (port from SickBeard) +* Change Plex notifications to allow authenticated library updates (port from mmccurdy07/Sick-Beard) +* Change Config/Notifications/Plex logo and description (adapted port from mmccurdy07/Sick-Beard) [develop changelog] diff --git a/gui/slick/images/notifiers/plex.png b/gui/slick/images/notifiers/plex.png index 1d97ad22..f630f9b2 100644 Binary files a/gui/slick/images/notifiers/plex.png and b/gui/slick/images/notifiers/plex.png differ diff --git a/gui/slick/interfaces/default/config_notifications.tmpl b/gui/slick/interfaces/default/config_notifications.tmpl index 750ae36a..79589cc6 100644 --- a/gui/slick/interfaces/default/config_notifications.tmpl +++ b/gui/slick/interfaces/default/config_notifications.tmpl @@ -159,7 +159,7 @@

Plex Media Server

-

Experience your media on a visually stunning, easy to use interface on your Mac connected to your TV. Your media library has never looked this good!

+

Plex organizes all of your personal media, wherever you keep it, so you can enjoy it on any device

For sending notifications to Plex Home Theater (PHT) clients, use the XBMC notifier with port 3005.

@@ -222,12 +222,12 @@
Click below to test.
diff --git a/sickbeard/notifiers/plex.py b/sickbeard/notifiers/plex.py index 7adc7653..d6ab265b 100644 --- a/sickbeard/notifiers/plex.py +++ b/sickbeard/notifiers/plex.py @@ -156,7 +156,7 @@ class PLEXNotifier: def test_notify(self, host, username, password): return self._notify("This is a test notification from SickGear", "Test", host, username, password, force=True) - def update_library(self, ep_obj=None): + def update_library(self, ep_obj=None, host=None, username=None, password=None): """Handles updating the Plex Media Server host via HTTP API Plex Media Server currently only supports updating the whole video library and not a specific path. @@ -166,14 +166,47 @@ class PLEXNotifier: """ + # fill in omitted parameters + if not host: + host = sickbeard.PLEX_SERVER_HOST + if not username: + username = sickbeard.PLEX_USERNAME + if not password: + password = sickbeard.PLEX_PASSWORD + if sickbeard.USE_PLEX and sickbeard.PLEX_UPDATE_LIBRARY: if not sickbeard.PLEX_SERVER_HOST: logger.log(u"PLEX: No Plex Media Server host specified, check your settings", logger.DEBUG) return False - logger.log(u"PLEX: Updating library for the Plex Media Server host: " + sickbeard.PLEX_SERVER_HOST, logger.MESSAGE) + logger.log(u"PLEX: Updating library for the Plex Media Server host: " + host, logger.MESSAGE) - url = "http://%s/library/sections" % sickbeard.PLEX_SERVER_HOST + # if username and password were provided, fetch the auth token from plex.tv + token_arg = "" + if username and password: + + logger.log(u"PLEX: fetching credentials for Plex user: " + username, logger.DEBUG) + req = urllib2.Request("https://plex.tv/users/sign_in.xml", data="") + base64string = base64.encodestring('%s:%s' % (username, password))[:-1] + authheader = "Basic %s" % base64string + req.add_header("Authorization", authheader) + req.add_header("X-Plex-Client-Identifier", "Sick-Beard-Notifier") + + try: + response = urllib2.urlopen(req) + except urllib2.URLError, e: + logger.log(u"PLEX: Error fetching credentials from from plex.tv for user %s: %s" % (username, ex(e)), logger.MESSAGE) + return False + + try: + auth_tree = etree.parse(response) + token = auth_tree.findall(".//authentication-token")[0].text + token_arg = "?X-Plex-Token=" + token + except (ValueError, IndexError) as e: + logger.log(u"PLEX: Error parsing plex.tv response: " + ex(e), logger.MESSAGE) + return False + + url = "http://%s/library/sections%s" % (sickbeard.PLEX_SERVER_HOST, token_arg) try: xml_tree = etree.parse(urllib.urlopen(url)) media_container = xml_tree.getroot() @@ -188,7 +221,7 @@ class PLEXNotifier: for section in sections: if section.attrib['type'] == "show": - url = "http://%s/library/sections/%s/refresh" % (sickbeard.PLEX_SERVER_HOST, section.attrib['key']) + url = "http://%s/library/sections/%s/refresh%s" % (sickbeard.PLEX_SERVER_HOST, section.attrib['key'], token_arg) try: urllib.urlopen(url) except Exception, e: