From 70393b1b8600351a72d44a9ff76a6c626b562d13 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Fri, 19 Feb 2016 16:10:19 +0100 Subject: [PATCH] Fix URL tokens --- resources/lib/PlexAPI.py | 14 +++++++++++++- resources/lib/itemtypes.py | 2 +- resources/lib/playutils.py | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 860c48eb..34781e58 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -1773,7 +1773,7 @@ class API(): episode = item['index'] return key, title, season, episode - def addPlexCredentialsToUrl(self, url, arguments={}): + def addPlexHeadersToUrl(self, url, arguments={}): """ Takes an URL and optional arguments (also to be URL-encoded); returns an extended URL with e.g. the Plex token included. @@ -1788,6 +1788,18 @@ class API(): url = "%s&%s" % (url, urlencode(xargs)) return url + def addPlexCredentialsToUrl(self, url): + """ + Returns an extended URL with the Plex token included as 'X-Plex-Token=' + + url may or may not already contain a '?' + """ + if '?' not in url: + url = "%s?X-Plex-Token=%s" % (url, self.token) + else: + url = "%s&X-Plex-Token=%s" % (url, self.token) + return url + def GetPlayQueueItemID(self): """ Returns current playQueueItemID for the item. diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index e3645d32..43864b82 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -1859,7 +1859,7 @@ class Music(Items): paths = "%s%s" % (self.server, item[0][0].attrib.get('key')) paths = paths.rsplit('/', 1) path = paths[0] + '/' - filename = paths[1] + '?X-Plex-Token=ihfViFUqqJf1vWrchnA9' + filename = API.addPlexCredentialsToUrl(paths[1]) # else: # path = "plugin://plugin.audio.plexkodiconnect.music/" # filename = API.getKey() diff --git a/resources/lib/playutils.py b/resources/lib/playutils.py index 9c6a68d6..f60bac12 100644 --- a/resources/lib/playutils.py +++ b/resources/lib/playutils.py @@ -391,7 +391,7 @@ class PlayUtils(): url = "%s/library/streams/%s" \ % (self.server, selectSubsIndex) - url = self.API.addPlexCredentialsToUrl(url) + url = self.API.addPlexHeadersToUrl(url) self.logMsg("Downloadable sub: %s: %s" % (selectSubsIndex, url), 1) listitem.setSubtitles([url]) else: