From 8d9ac66cd77557ef105378767da3e56b775a61e5 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 26 Jun 2016 18:22:26 +0200 Subject: [PATCH] Preparation for companion playlist skipping - Unicode issues from JSON responses --- resources/lib/plexbmchelper/functions.py | 39 +++++++++++++++++++++++- resources/lib/plexbmchelper/listener.py | 9 +++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/resources/lib/plexbmchelper/functions.py b/resources/lib/plexbmchelper/functions.py index c2451058..14b3112f 100644 --- a/resources/lib/plexbmchelper/functions.py +++ b/resources/lib/plexbmchelper/functions.py @@ -4,7 +4,8 @@ import string import xbmc -from utils import logging +from utils import logging, tryDecode +import embydb_functions as embydb def xbmc_photo(): @@ -121,6 +122,21 @@ class jsonClass(): return result + def skipTo(self, plexId, typus): + self.logMsg('players: %s' % self.getPlayers()) + # playlistId = self.getPlaylistId(tryDecode(xbmc_type(typus))) + # playerId = self. + with embydb.GetEmbyDB() as emby_db: + embydb_item = emby_db.getItem_byId(plexId) + try: + dbid = embydb_item[0] + mediatype = embydb_item[4] + except TypeError: + self.logMsg('Couldnt find item %s in Kodi db' % plexId, 1) + return + self.logMsg('plexid: %s, kodi id: %s, type: %s' + % (plexId, dbid, mediatype)) + def getPlexHeaders(self): h = { "Content-type": "text/xml", @@ -156,6 +172,27 @@ class jsonClass(): ret[player['type']] = player return ret + def getPlaylistId(self, typus): + """ + typus: one of the Kodi types, e.g. audio or video + + Returns None if nothing was found + """ + for playlist in self.getPlaylists(): + if playlist.get('type') == typus: + return playlist.get('playlistid') + + def getPlaylists(self): + """ + Returns a list, e.g. + [ + {u'playlistid': 0, u'type': u'audio'}, + {u'playlistid': 1, u'type': u'video'}, + {u'playlistid': 2, u'type': u'picture'} + ] + """ + return self.jsonrpc('Playlist.GetPlaylists') + def getPlayerIds(self): ret = [] for player in self.getPlayers().values(): diff --git a/resources/lib/plexbmchelper/listener.py b/resources/lib/plexbmchelper/listener.py index c43ba4da..6e7f5275 100644 --- a/resources/lib/plexbmchelper/listener.py +++ b/resources/lib/plexbmchelper/listener.py @@ -83,10 +83,11 @@ class MyHandler(BaseHTTPRequestHandler): params = {} for key in paramarrays: params[key] = paramarrays[key][0] + self.logMsg("remote request_path: %s" % request_path, 2) self.logMsg("params received from remote: %s" % params, 2) self.subMgr.updateCommandID(self.headers.get('X-Plex-Client-Identifier', self.client_address[0]), params.get('commandID', False)) if request_path=="version": - self.response("PleXBMC Helper Remote Redirector: Running\r\nVersion: %s" % self.settings['version']) + self.response("PlexKodiConnect Plex Companion: Running\r\nVersion: %s" % self.settings['version']) elif request_path=="verify": result=self.js.jsonrpc("ping") self.response("XBMC JSON connection test:\r\n"+result) @@ -197,6 +198,10 @@ class MyHandler(BaseHTTPRequestHandler): for playerid in self.js.getPlayerIds(): self.js.jsonrpc("Player.GoTo", {"playerid":playerid, "to":"previous"}) self.subMgr.notify() + elif request_path == "player/playback/skipTo": + self.js.skipTo(params.get('key').rsplit('/', 1)[1], + params.get('type')) + self.subMgr.notify() elif request_path == "player/navigation/moveUp": self.response(getOKMsg(), self.js.getPlexHeaders()) self.js.jsonrpc("Input.Up") @@ -218,6 +223,8 @@ class MyHandler(BaseHTTPRequestHandler): elif request_path == "player/navigation/back": self.response(getOKMsg(), self.js.getPlexHeaders()) self.js.jsonrpc("Input.Back") + else: + self.logMsg('Unknown request path: %s' % request_path, -1) # elif 'player/mirror/details' in request_path: # # Detailed e.g. Movie information page was opened # # CURRENTLY NOT POSSIBLE DUE TO KODI RESTRICTIONS