From b8a4afc923d0333fdecd214a8861543bb05ecc72 Mon Sep 17 00:00:00 2001 From: mmccurdy07 Date: Fri, 13 Feb 2015 23:28:15 +1000 Subject: [PATCH 1/2] Update the Plex notifier from a port at midgetspy/sickbeard. --- CHANGES.md | 1 + sickbeard/notifiers/plex.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9b9f030a..b62178fd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,6 +39,7 @@ * Remove defunct boxcar notifier * Add sound selection for boxcar2 notifier * Change boxcar2 notifier to use updated api scheme +* Update the Plex notifier from a port at midgetspy/sickbeard [develop changelog] * Change uT params from unicode to str.format as magnet URLs worked but sending files in POST bodies failed diff --git a/sickbeard/notifiers/plex.py b/sickbeard/notifiers/plex.py index d6ab265b..4eeafe41 100644 --- a/sickbeard/notifiers/plex.py +++ b/sickbeard/notifiers/plex.py @@ -91,7 +91,7 @@ class PLEXNotifier: logger.log(u"PLEX: Warning: Couldn't contact Plex at " + fixStupidEncodings(url) + " " + ex(e), logger.WARNING) return False - def _notify(self, message, title="SickGear", host=None, username=None, password=None, force=False): + def _notify_pmc(self, message, title="SickGear", host=None, username=None, password=None, force=False): """Internal wrapper for the notify_snatch and notify_download functions Args: @@ -154,7 +154,7 @@ class PLEXNotifier: self._notify_pmc(update_text + new_version, title) def test_notify(self, host, username, password): - return self._notify("This is a test notification from SickGear", "Test", host, username, password, force=True) + return self._notify_pmc("This is a test notification from SickGear", "Test", host, username, password, force=True) def update_library(self, ep_obj=None, host=None, username=None, password=None): """Handles updating the Plex Media Server host via HTTP API @@ -187,24 +187,24 @@ class PLEXNotifier: 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 + authheader = "Basic %s" % base64.encodestring('%s:%s' % (username, password))[:-1] req.add_header("Authorization", authheader) - req.add_header("X-Plex-Client-Identifier", "Sick-Beard-Notifier") + req.add_header("X-Plex-Device-Name", "SickGear") + req.add_header("X-Plex-Product", "SickGear Notifier") + req.add_header("X-Plex-Client-Identifier", "5f48c063eaf379a565ff56c9bb2b401e") + req.add_header("X-Plex-Version", "1.0") 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 urllib2.URLError as e: + logger.log(u"PLEX: Error fetching credentials from from plex.tv for user %s: %s" % (username, ex(e)), logger.MESSAGE) + 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: From 47f1c8eaaf177a473d70294cb4091afba9d7b71f Mon Sep 17 00:00:00 2001 From: JackDandy Date: Sat, 14 Feb 2015 02:28:24 +0000 Subject: [PATCH 2/2] Add support for multiple server hosts to Plex server notifier. Add support for multiple server hosts to the updated Plex server notifier. Change Plex Media Server settings section for multi server(s) and improve the layout in the config/notifications page. Add logic to Plex notifier to update a single server where its TV section path matches the downloaded show. All server libraries are updated if no single server has a download path match. Change the ui notifications to show the Plex Media Server(s) actioned for library updating. Fix issue where PMS text wasn't initialised on the config/notifications page and added info about Plex clients. Add ability to test Plex Server(s) on config/notifications page. --- CHANGES.md | 7 + .../default/config_notifications.tmpl | 218 ++++++++++-------- gui/slick/js/configNotifications.js | 43 +++- sickbeard/notifiers/plex.py | 170 ++++++++------ sickbeard/postProcessor.py | 2 +- sickbeard/webserve.py | 43 ++-- 6 files changed, 289 insertions(+), 194 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b62178fd..6869e671 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,6 +40,13 @@ * Add sound selection for boxcar2 notifier * Change boxcar2 notifier to use updated api scheme * Update the Plex notifier from a port at midgetspy/sickbeard +* Add support for multiple server hosts to the updated Plex server notifier +* Change Plex Media Server settings section for multi server(s) and improve the layout in the config/notifications page +* Add logic to Plex notifier to update a single server where its TV section path matches the downloaded show. All server + libraries are updated if no single server has a download path match. +* Change the ui notifications to show the Plex Media Server(s) actioned for library updating +* Fix issue where PMS text wasn't initialised on the config/notifications page and added info about Plex clients +* Add ability to test Plex Server(s) on config/notifications page [develop changelog] * Change uT params from unicode to str.format as magnet URLs worked but sending files in POST bodies failed diff --git a/gui/slick/interfaces/default/config_notifications.tmpl b/gui/slick/interfaces/default/config_notifications.tmpl index 0802f65f..7b8fff43 100644 --- a/gui/slick/interfaces/default/config_notifications.tmpl +++ b/gui/slick/interfaces/default/config_notifications.tmpl @@ -1,4 +1,5 @@ #import sickbeard +#import re #from sickbeard.helpers import anon_url #set global $title = 'Config - Notifications' @@ -30,7 +31,7 @@
- +

XBMC

@@ -110,7 +111,7 @@

only send library updates to the first active host ?

-
+
- +
@@ -160,103 +161,120 @@

Plex Media Server

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.

+

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

-
- +
+
+ +
+
+ +
-
- + +
+
+ +
+
+
+ +
+ +
+
Click below to test Plex server(s)
+ + +
 
+
+
-
- -
-
- -
-
- - -
-
- - - -
-
- - -
-
- - -
-
Click below to test.
- - + +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+
Click below to test Plex client(s)
+ + +

Note: some Plex clients do not support notifications e.g. Plexapp for Samsung TVs

+
+
@@ -365,9 +383,9 @@ + - +
- +
@@ -430,7 +448,7 @@ @@ -446,8 +464,8 @@
- - + +
@@ -563,7 +581,7 @@
- +
@@ -576,7 +594,7 @@ @@ -587,7 +605,7 @@ @@ -1172,7 +1190,7 @@
- +
@@ -1350,7 +1368,7 @@   method in which to download episodes for new show's. -
+
-
-
+
+