From 1568b6ffb3ac5883a7b452c85841478055b8f1fd Mon Sep 17 00:00:00 2001 From: Seth Kingry Date: Wed, 3 Feb 2016 14:06:58 -0500 Subject: [PATCH 1/2] updates to how Plex token is grabbed and libraries are updated --- sickbeard/notifiers/plex.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/sickbeard/notifiers/plex.py b/sickbeard/notifiers/plex.py index d3242456d6..564492f92b 100644 --- a/sickbeard/notifiers/plex.py +++ b/sickbeard/notifiers/plex.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . +import base64 import urllib import urllib2 import sickbeard @@ -169,35 +170,34 @@ def update_library(self, ep_obj=None, host=None, username=None, password=None): if username and password: logger.log(u"PLEX: fetching credentials for Plex user: " + username, logger.DEBUG) - url = "https://plex.tv/users/sign_in.xml" - req = urllib2.Request(url, data="") - pw_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() - pw_mgr.add_password(None, url, username, password) + req = urllib2.Request("https://plex.tv/users/sign_in.xml", data="") + authheader = "Basic %s" % base64.encodestring('%s:%s' % (username, password))[:-1] + req.add_header("Authorization", authheader) req.add_header("X-Plex-Product", "Sick Beard 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.ERROR) + try: - response = sickbeard.helpers.getURL(req, throw_exc=True) - auth_tree = etree.fromstring(response) + 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) + logger.log(u"PLEX: Error parsing token from plex.tv response: " + ex(e), logger.ERROR) url = "http://%s/library/sections%s" % (sickbeard.PLEX_SERVER_HOST, token_arg) try: - xml_tree = etree.fromstring(sickbeard.helpers.getURL(url)) - media_container = xml_tree.getroot() + data = sickbeard.helpers.getURL(url) + xml_tree = etree.fromstring(data) except IOError, e: logger.log(u"PLEX: Error while trying to contact Plex Media Server: " + ex(e), logger.ERROR) return False - sections = media_container.findall('.//Directory') + sections = xml_tree.findall('Directory') if not sections: logger.log(u"PLEX: Plex Media Server not running on: " + sickbeard.PLEX_SERVER_HOST, logger.MESSAGE) return False @@ -206,7 +206,7 @@ def update_library(self, ep_obj=None, host=None, username=None, password=None): if section.attrib['type'] == "show": url = "http://%s/library/sections/%s/refresh%s" % (sickbeard.PLEX_SERVER_HOST, section.attrib['key'], token_arg) if sickbeard.helpers.getURLFileLike(url) is None: - logger.log(u"PLEX: Error updating library section for Plex Media Server", logger.ERROR) + logger.log(u"PLEX: Error updating library section for Plex Media Server", logger.ERROR) return False return True From 419fbf208c8f3dfd66e860742a7b674bd89b386b Mon Sep 17 00:00:00 2001 From: Seth Kingry Date: Wed, 3 Feb 2016 15:56:01 -0500 Subject: [PATCH 2/2] adding pid file to the gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 94504ab57b..f90317506d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ sickbeard.db* autoProcessTV/autoProcessTV.cfg server.crt server.key +sickbeard.pid* # SB Test Related # ###################### @@ -40,4 +41,4 @@ desktop.ini ehthumbs.db Thumbs.db .directory -*~ \ No newline at end of file +*~