Preparation for companion playlist skipping

- Unicode issues from JSON responses
This commit is contained in:
tomkat83 2016-06-26 18:22:26 +02:00
parent fd1a44f15f
commit 8d9ac66cd7
2 changed files with 46 additions and 2 deletions

View file

@ -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():

View file

@ -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