Enable skipping for Plex Companion
This commit is contained in:
parent
a8b7bf7871
commit
38d5d64f2c
2 changed files with 24 additions and 23 deletions
|
@ -2,9 +2,12 @@
|
||||||
import logging
|
import logging
|
||||||
from re import compile as re_compile
|
from re import compile as re_compile
|
||||||
|
|
||||||
|
from xbmc import Player
|
||||||
|
|
||||||
from utils import JSONRPC
|
from utils import JSONRPC
|
||||||
import plexdb_functions as plexdb
|
|
||||||
from variables import ALEXA_TO_COMPANION
|
from variables import ALEXA_TO_COMPANION
|
||||||
|
from playqueue import Playqueue
|
||||||
|
from PlexFunctions import GetPlexKeyNumber
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -17,7 +20,6 @@ REGEX_PLAYQUEUES = re_compile(r'''/playQueues/(\d+)$''')
|
||||||
|
|
||||||
def getPlayers():
|
def getPlayers():
|
||||||
info = JSONRPC("Player.GetActivePlayers").execute()['result'] or []
|
info = JSONRPC("Player.GetActivePlayers").execute()['result'] or []
|
||||||
log.debug('players: %s' % JSONRPC("Player.GetActivePlayers").execute())
|
|
||||||
ret = {}
|
ret = {}
|
||||||
for player in info:
|
for player in info:
|
||||||
player['playerid'] = int(player['playerid'])
|
player['playerid'] = int(player['playerid'])
|
||||||
|
@ -69,19 +71,24 @@ def millisToTime(t):
|
||||||
'milliseconds': millis}
|
'milliseconds': millis}
|
||||||
|
|
||||||
|
|
||||||
def skipTo(self, plexId, typus):
|
def skipTo(params):
|
||||||
# playlistId = self.getPlaylistId(tryDecode(xbmc_type(typus)))
|
# Does not seem to be implemented yet
|
||||||
# playerId = self.
|
playQueueItemID = params.get('playQueueItemID', 'not available')
|
||||||
with plexdb.Get_Plex_DB() as plex_db:
|
library, plex_id = GetPlexKeyNumber(params.get('key'))
|
||||||
plexdb_item = plex_db.getItem_byId(plexId)
|
log.debug('Skipping to playQueueItemID %s, plex_id %s'
|
||||||
try:
|
% (playQueueItemID, plex_id))
|
||||||
dbid = plexdb_item[0]
|
found = True
|
||||||
mediatype = plexdb_item[4]
|
playqueues = Playqueue()
|
||||||
except TypeError:
|
for (player, ID) in getPlayers().iteritems():
|
||||||
log.info('Couldnt find item %s in Kodi db' % plexId)
|
playqueue = playqueues.get_playqueue_from_type(player)
|
||||||
return
|
for i, item in enumerate(playqueue.items):
|
||||||
log.debug('plexid: %s, kodi id: %s, type: %s'
|
if item.ID == playQueueItemID or item.plex_id == plex_id:
|
||||||
% (plexId, dbid, mediatype))
|
break
|
||||||
|
else:
|
||||||
|
log.debug('Item not found to skip to')
|
||||||
|
found = False
|
||||||
|
if found:
|
||||||
|
Player().play(playqueue.kodi_pl, None, False, i)
|
||||||
|
|
||||||
|
|
||||||
def convert_alexa_to_companion(dictionary):
|
def convert_alexa_to_companion(dictionary):
|
||||||
|
@ -153,7 +160,7 @@ def process_command(request_path, params, queue=None):
|
||||||
"to": "previous"})
|
"to": "previous"})
|
||||||
|
|
||||||
elif request_path == "player/playback/skipTo":
|
elif request_path == "player/playback/skipTo":
|
||||||
skipTo(params.get('key').rsplit('/', 1)[1], params.get('type'))
|
skipTo(params)
|
||||||
|
|
||||||
elif request_path == "player/navigation/moveUp":
|
elif request_path == "player/navigation/moveUp":
|
||||||
JSONRPC("Input.Up").execute()
|
JSONRPC("Input.Up").execute()
|
||||||
|
|
|
@ -90,13 +90,7 @@ class Playqueue(Thread):
|
||||||
api = API(child)
|
api = API(child)
|
||||||
PL.add_item_to_playlist(playqueue, i, plex_id=api.getRatingKey())
|
PL.add_item_to_playlist(playqueue, i, plex_id=api.getRatingKey())
|
||||||
log.debug('Firing up Kodi player')
|
log.debug('Firing up Kodi player')
|
||||||
thread = Thread(target=Player().play,
|
Player().play(playqueue.kodi_pl, None, False, 0)
|
||||||
args=(playqueue.kodi_pl,
|
|
||||||
None,
|
|
||||||
False,
|
|
||||||
0)) # starting position
|
|
||||||
thread.setDaemon(True)
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
def update_playqueue_from_PMS(self,
|
def update_playqueue_from_PMS(self,
|
||||||
playqueue,
|
playqueue,
|
||||||
|
|
Loading…
Reference in a new issue