Fix Alexa playback

This commit is contained in:
croneter 2018-02-08 11:16:39 +01:00
parent e3882acf50
commit bbb35856e0
2 changed files with 42 additions and 18 deletions

View file

@ -9,12 +9,14 @@ from urllib import urlencode
from xbmc import sleep, executebuiltin from xbmc import sleep, executebuiltin
from utils import settings, thread_methods from utils import settings, thread_methods, language as lang, dialog
from plexbmchelper import listener, plexgdm, subscribers, httppersist from plexbmchelper import listener, plexgdm, subscribers, httppersist
from plexbmchelper.subscribers import LOCKER from plexbmchelper.subscribers import LOCKER
from PlexFunctions import ParseContainerKey, GetPlexMetadata from PlexFunctions import ParseContainerKey, GetPlexMetadata, DownloadChunks
from PlexAPI import API from PlexAPI import API
from playlist_func import get_pms_playqueue, get_plextype_from_xml from playlist_func import get_pms_playqueue, get_plextype_from_xml, \
get_playlist_details_from_xml
from playback import playback_triage, play_xml
import json_rpc as js import json_rpc as js
import player import player
import variables as v import variables as v
@ -60,17 +62,28 @@ class PlexCompanion(Thread):
PQ.init_playqueue_from_plex_children( PQ.init_playqueue_from_plex_children(
api.getRatingKey(), api.getRatingKey(),
transient_token=data.get('token')) transient_token=data.get('token'))
elif data['containerKey'].startswith('/playQueues/'):
_, container_key, _ = ParseContainerKey(data['containerKey'])
xml = DownloadChunks('{server}/playQueues/%s?' % container_key)
if xml is None:
# "Play error"
dialog('notification', lang(29999), lang(30128), icon='{error}')
return
playqueue = PQ.get_playqueue_from_type(
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[api.getType()])
playqueue.clear()
get_playlist_details_from_xml(playqueue, xml)
if data.get('offset') != '0':
offset = float(data['offset']) / 1000.0
else:
offset = None
play_xml(playqueue, xml, offset)
else: else:
state.PLEX_TRANSIENT_TOKEN = data.get('token') state.PLEX_TRANSIENT_TOKEN = data.get('token')
params = { if data.get('offset') != '0':
'mode': 'plex_node', state.RESUMABLE = True
'key': '{server}%s' % data.get('key'), state.RESUME_PLAYBACK = True
'view_offset': data.get('offset'), playback_triage(api.getRatingKey(), api.getType(), resolve=False)
'play_directly': 'true',
'node': 'false'
}
executebuiltin('RunPlugin(plugin://%s?%s)'
% (v.ADDON_ID, urlencode(params)))
@staticmethod @staticmethod
def _process_node(data): def _process_node(data):

View file

@ -336,19 +336,30 @@ def process_indirect(key, offset, resolve=True):
thread.start() thread.start()
def play_xml(playqueue, xml, offset=None): def play_xml(playqueue, xml, offset=None, start_plex_id=None):
""" """
Play all items contained in the xml passed in. Called by Plex Companion. Play all items contained in the xml passed in. Called by Plex Companion.
Either supply the ratingKey of the starting Plex element. Or set
playqueue.selectedItemID
""" """
LOG.info("play_xml called") LOG.info("play_xml called with offset %s, start_plex_id %s",
offset, start_plex_id)
stack = _prep_playlist_stack(xml) stack = _prep_playlist_stack(xml)
_process_stack(playqueue, stack) _process_stack(playqueue, stack)
LOG.debug('Playqueue after play_xml update: %s', playqueue) LOG.debug('Playqueue after play_xml update: %s', playqueue)
for startpos, item in enumerate(playqueue.items): if start_plex_id is not None:
if item.id == playqueue.selectedItemID: for startpos, item in enumerate(playqueue.items):
break if item.plex_id == start_plex_id:
break
else:
startpos = 0
else: else:
startpos = 0 for startpos, item in enumerate(playqueue.items):
if item.id == playqueue.selectedItemID:
break
else:
startpos = 0
thread = Thread(target=threaded_playback, thread = Thread(target=threaded_playback,
args=(playqueue.kodi_pl, startpos, offset)) args=(playqueue.kodi_pl, startpos, offset))
LOG.info('Done play_xml, starting Kodi player at position %s', startpos) LOG.info('Done play_xml, starting Kodi player at position %s', startpos)