From 613e033b48bac9db873208f5893bbab2c506fbb3 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 24 Jan 2016 16:12:28 +0100 Subject: [PATCH] Fix playing trailers directly via Plex Companion --- resources/lib/PlexAPI.py | 2 +- resources/lib/downloadutils.py | 2 +- resources/lib/entrypoint.py | 15 ++++++++++++--- resources/lib/playbackutils.py | 2 +- resources/lib/plexbmchelper/settings.py | 8 ++++++++ resources/lib/userclient.py | 10 ++++------ 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index df77ae07..fd894fd2 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -802,7 +802,7 @@ class PlexAPI(): 'X-Plex-Client-Platform': self.platform, 'X-Plex-Device-Name': self.deviceName, 'X-Plex-Platform': self.addonName, - 'X-Plex-Platform-Version': 'no idea', + 'X-Plex-Platform-Version': 'unknown', 'X-Plex-Model': 'unknown', 'X-Plex-Product': self.addonName, 'X-Plex-Version': self.plexversion, diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 913cce98..83a8ab75 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -68,7 +68,7 @@ class DownloadUtils(): def setToken(self, token): # Reserved for userclient only self.token = token - self.logMsg("Set token: %s" % token, 2) + self.logMsg("Set token: xxxxxxx", 2) def setSSL(self, ssl, sslclient): # Reserved for userclient only diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index fd6eea93..87e3b39d 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -40,6 +40,7 @@ def plexCompanion(fullurl, resume=None): except IndexError: # No matches found, url not like: # http://192.168.0.2:32400/library/metadata/243480 + utils.logMsg("plexCompanion", "Could not parse url: %s" % fullurl, -1) return False # TODO: direct play an URL # Initialize embydb @@ -47,11 +48,19 @@ def plexCompanion(fullurl, resume=None): embycursor = embyconn.cursor() emby = embydb_functions.Embydb_Functions(embycursor) # Get dbid using itemid - dbid = emby.getItem_byId(itemid)[0] + # Works only for library items, not e.g. for trailers + try: + dbid = emby.getItem_byId(itemid)[0] + except TypeError: + # Trailers and the like + dbid = None embyconn.close() # Fix resume timing if resume: - resume = round(float(resume) / 1000.0, 6) + if resume == '0': + resume = None + else: + resume = round(float(resume) / 1000.0, 6) # Start playing item = PlexAPI.PlexAPI().GetPlexMetadata(itemid) pbutils.PlaybackUtils(item).play(itemid, dbid, seektime=resume) @@ -77,7 +86,7 @@ def resetAuth(): "Plex might lock your account if you fail to log in too many times. " "Proceed anyway?")) if resp == 1: - utils.logMsg("EMBY", "Reset login attempts.", 1) + utils.logMsg("PLEX", "Reset login attempts.", 1) utils.window('emby_serverStatus', value="Auth") else: xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)') diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index 0c8b3c30..d21bbb99 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -178,7 +178,7 @@ class PlaybackUtils(): playlist.add(additionalPlayurl, additionalListItem, index=currentPosition) self.pl.verifyPlaylist() currentPosition += 1 - i = i + 1 + i += 1 API.setPartNumber(0) if dummyPlaylist: diff --git a/resources/lib/plexbmchelper/settings.py b/resources/lib/plexbmchelper/settings.py index 9307a3b8..1aef4944 100644 --- a/resources/lib/plexbmchelper/settings.py +++ b/resources/lib/plexbmchelper/settings.py @@ -25,6 +25,14 @@ plexbmc = xbmcaddon.Addon('plugin.video.plexkodiconnect') settings['debug'] = utils.settings('companionDebugging') settings['gdm_debug'] = utils.settings('companionGDMDebugging') +# Transform 'true' into True because of the way Kodi's file settings work +kodiSettingsList = ['debug', 'gdm_debug'] +for entry in kodiSettingsList: + if settings[entry] == 'true': + settings[entry] = True + else: + settings[entry] = False + settings['client_name'] = plexbmc.getSetting('deviceName') # XBMC web server settings diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index d9f3f469..a045ee62 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -151,15 +151,13 @@ class UserClient(threading.Thread): if not s_token: # Save access token if it's missing from settings utils.settings('accessToken', value=w_token) - self.logMsg( - "Returning accessToken from WINDOW for username: %s accessToken: %s" - % (username, w_token), 2) + self.logMsg("Returning accessToken from WINDOW for username: %s " + "accessToken: xxxxx" % username, 2) return w_token # Verify the settings elif s_token: - self.logMsg( - "Returning accessToken from SETTINGS for username: %s accessToken: %s" - % (username, s_token), 2) + self.logMsg("Returning accessToken from SETTINGS for username: %s " + "accessToken: xxxxx" % username, 2) utils.window('emby_accessToken%s' % username, value=s_token) return s_token else: