2018-07-13 02:46:02 +10:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2017-12-08 17:53:01 +11:00
|
|
|
"""
|
|
|
|
Processes Plex companion inputs from the plexbmchelper to Kodi commands
|
|
|
|
"""
|
|
|
|
from logging import getLogger
|
2017-03-06 04:28:30 +11:00
|
|
|
from xbmc import Player
|
|
|
|
|
2018-11-19 00:59:17 +11:00
|
|
|
from . import playqueue as PQ, plex_functions as PF
|
|
|
|
from . import json_rpc as js, variables as v, app
|
2017-03-05 03:54:24 +11:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
2018-06-22 03:24:37 +10:00
|
|
|
LOG = getLogger('PLEX.companion')
|
2017-03-05 03:54:24 +11:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
2017-12-08 17:53:01 +11:00
|
|
|
def skip_to(params):
|
2017-03-05 03:54:24 +11:00
|
|
|
"""
|
2017-12-08 17:53:01 +11:00
|
|
|
Skip to a specific playlist position.
|
2017-03-05 03:54:24 +11:00
|
|
|
|
2017-12-08 17:53:01 +11:00
|
|
|
Does not seem to be implemented yet by Plex!
|
2017-03-05 03:54:24 +11:00
|
|
|
"""
|
2017-12-29 07:46:48 +11:00
|
|
|
playqueue_item_id = params.get('playQueueItemID')
|
2018-06-22 03:24:37 +10:00
|
|
|
_, plex_id = PF.GetPlexKeyNumber(params.get('key'))
|
2017-12-08 17:53:01 +11:00
|
|
|
LOG.debug('Skipping to playQueueItemID %s, plex_id %s',
|
|
|
|
playqueue_item_id, plex_id)
|
2017-03-06 04:28:30 +11:00
|
|
|
found = True
|
2020-12-19 03:10:20 +11:00
|
|
|
for player in list(js.get_players().values()):
|
2018-01-07 01:19:12 +11:00
|
|
|
playqueue = PQ.PLAYQUEUES[player['playerid']]
|
2017-03-06 04:28:30 +11:00
|
|
|
for i, item in enumerate(playqueue.items):
|
2017-12-29 07:46:48 +11:00
|
|
|
if item.id == playqueue_item_id:
|
|
|
|
found = True
|
2017-03-06 04:28:30 +11:00
|
|
|
break
|
|
|
|
else:
|
2017-12-29 07:46:48 +11:00
|
|
|
for i, item in enumerate(playqueue.items):
|
|
|
|
if item.plex_id == plex_id:
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
if found is True:
|
2017-03-06 04:28:30 +11:00
|
|
|
Player().play(playqueue.kodi_pl, None, False, i)
|
2017-12-29 07:46:48 +11:00
|
|
|
else:
|
|
|
|
LOG.error('Item not found to skip to')
|
2017-03-05 03:54:24 +11:00
|
|
|
|
|
|
|
|
|
|
|
def convert_alexa_to_companion(dictionary):
|
2017-12-08 17:53:01 +11:00
|
|
|
"""
|
|
|
|
The params passed by Alexa must first be converted to Companion talk
|
|
|
|
"""
|
2021-05-02 22:35:24 +10:00
|
|
|
for key in list(dictionary):
|
2018-06-22 03:24:37 +10:00
|
|
|
if key in v.ALEXA_TO_COMPANION:
|
|
|
|
dictionary[v.ALEXA_TO_COMPANION[key]] = dictionary[key]
|
2017-03-05 03:54:24 +11:00
|
|
|
del dictionary[key]
|
|
|
|
|
|
|
|
|
2018-01-07 01:19:12 +11:00
|
|
|
def process_command(request_path, params):
|
2017-03-05 03:54:24 +11:00
|
|
|
"""
|
|
|
|
queue: Queue() of PlexCompanion.py
|
|
|
|
"""
|
|
|
|
if params.get('deviceName') == 'Alexa':
|
|
|
|
convert_alexa_to_companion(params)
|
2017-12-08 17:53:01 +11:00
|
|
|
LOG.debug('Received request_path: %s, params: %s', request_path, params)
|
2017-12-21 19:28:06 +11:00
|
|
|
if request_path == 'player/playback/playMedia':
|
2017-03-05 03:54:24 +11:00
|
|
|
# We need to tell service.py
|
2017-03-06 03:51:58 +11:00
|
|
|
action = 'alexa' if params.get('deviceName') == 'Alexa' else 'playlist'
|
2018-11-19 00:59:17 +11:00
|
|
|
app.APP.companion_queue.put({
|
2017-03-06 03:51:58 +11:00
|
|
|
'action': action,
|
2017-03-05 03:54:24 +11:00
|
|
|
'data': params
|
|
|
|
})
|
2017-05-31 21:44:04 +10:00
|
|
|
elif request_path == 'player/playback/refreshPlayQueue':
|
2018-11-19 00:59:17 +11:00
|
|
|
app.APP.companion_queue.put({
|
2017-05-31 21:44:04 +10:00
|
|
|
'action': 'refreshPlayQueue',
|
|
|
|
'data': params
|
|
|
|
})
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/setParameters":
|
|
|
|
if 'volume' in params:
|
2017-12-08 17:53:01 +11:00
|
|
|
js.set_volume(int(params['volume']))
|
2017-05-31 20:28:26 +10:00
|
|
|
else:
|
2017-12-08 17:53:01 +11:00
|
|
|
LOG.error('Unknown parameters: %s', params)
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/play":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.play()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/pause":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.pause()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/stop":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.stop()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/seekTo":
|
2020-12-21 20:41:19 +11:00
|
|
|
js.seek_to(float(params.get('offset', 0.0)) / 1000.0)
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/stepForward":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.smallforward()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/stepBack":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.smallbackward()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/skipNext":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.skipnext()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/skipPrevious":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.skipprevious()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/playback/skipTo":
|
2017-12-08 17:53:01 +11:00
|
|
|
skip_to(params)
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/navigation/moveUp":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.input_up()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/navigation/moveDown":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.input_down()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/navigation/moveLeft":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.input_left()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/navigation/moveRight":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.input_right()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/navigation/select":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.input_select()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/navigation/home":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.input_home()
|
2017-03-05 03:54:24 +11:00
|
|
|
elif request_path == "player/navigation/back":
|
2017-12-08 17:53:01 +11:00
|
|
|
js.input_back()
|
2017-12-16 02:11:19 +11:00
|
|
|
elif request_path == "player/playback/setStreams":
|
2018-11-19 00:59:17 +11:00
|
|
|
app.APP.companion_queue.put({
|
2017-12-16 02:11:19 +11:00
|
|
|
'action': 'setStreams',
|
|
|
|
'data': params
|
|
|
|
})
|
2017-03-05 03:54:24 +11:00
|
|
|
else:
|
2017-12-08 17:53:01 +11:00
|
|
|
LOG.error('Unknown request path: %s', request_path)
|