Fix Alexa playback
This commit is contained in:
parent
e3882acf50
commit
bbb35856e0
2 changed files with 42 additions and 18 deletions
|
@ -9,12 +9,14 @@ from urllib import urlencode
|
|||
|
||||
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.subscribers import LOCKER
|
||||
from PlexFunctions import ParseContainerKey, GetPlexMetadata
|
||||
from PlexFunctions import ParseContainerKey, GetPlexMetadata, DownloadChunks
|
||||
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 player
|
||||
import variables as v
|
||||
|
@ -60,17 +62,28 @@ class PlexCompanion(Thread):
|
|||
PQ.init_playqueue_from_plex_children(
|
||||
api.getRatingKey(),
|
||||
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:
|
||||
state.PLEX_TRANSIENT_TOKEN = data.get('token')
|
||||
params = {
|
||||
'mode': 'plex_node',
|
||||
'key': '{server}%s' % data.get('key'),
|
||||
'view_offset': data.get('offset'),
|
||||
'play_directly': 'true',
|
||||
'node': 'false'
|
||||
}
|
||||
executebuiltin('RunPlugin(plugin://%s?%s)'
|
||||
% (v.ADDON_ID, urlencode(params)))
|
||||
if data.get('offset') != '0':
|
||||
state.RESUMABLE = True
|
||||
state.RESUME_PLAYBACK = True
|
||||
playback_triage(api.getRatingKey(), api.getType(), resolve=False)
|
||||
|
||||
@staticmethod
|
||||
def _process_node(data):
|
||||
|
|
|
@ -336,19 +336,30 @@ def process_indirect(key, offset, resolve=True):
|
|||
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.
|
||||
|
||||
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)
|
||||
_process_stack(playqueue, stack)
|
||||
LOG.debug('Playqueue after play_xml update: %s', playqueue)
|
||||
for startpos, item in enumerate(playqueue.items):
|
||||
if item.id == playqueue.selectedItemID:
|
||||
break
|
||||
if start_plex_id is not None:
|
||||
for startpos, item in enumerate(playqueue.items):
|
||||
if item.plex_id == start_plex_id:
|
||||
break
|
||||
else:
|
||||
startpos = 0
|
||||
else:
|
||||
startpos = 0
|
||||
for startpos, item in enumerate(playqueue.items):
|
||||
if item.id == playqueue.selectedItemID:
|
||||
break
|
||||
else:
|
||||
startpos = 0
|
||||
thread = Thread(target=threaded_playback,
|
||||
args=(playqueue.kodi_pl, startpos, offset))
|
||||
LOG.info('Done play_xml, starting Kodi player at position %s', startpos)
|
||||
|
|
Loading…
Reference in a new issue