Enable Alexa for Plex music
This commit is contained in:
parent
3d525f7772
commit
f1dc7639ab
4 changed files with 59 additions and 13 deletions
|
@ -79,7 +79,29 @@ class PlexCompanion(Thread):
|
||||||
log.debug('Processing: %s' % task)
|
log.debug('Processing: %s' % task)
|
||||||
data = task['data']
|
data = task['data']
|
||||||
|
|
||||||
if (task['action'] == 'playlist' and
|
if task['action'] == 'alexa':
|
||||||
|
# e.g. Alexa
|
||||||
|
xml = GetPlexMetadata(data['key'])
|
||||||
|
try:
|
||||||
|
xml[0].attrib
|
||||||
|
except (AttributeError, IndexError, TypeError):
|
||||||
|
log.error('Could not download Plex metadata')
|
||||||
|
return
|
||||||
|
api = API(xml[0])
|
||||||
|
if api.getType() == v.PLEX_TYPE_ALBUM:
|
||||||
|
log.debug('Plex music album detected')
|
||||||
|
self.mgr.playqueue.init_playqueue_from_plex_children(
|
||||||
|
api.getRatingKey())
|
||||||
|
else:
|
||||||
|
thread = Thread(target=Plex_Node,
|
||||||
|
args=('{server}%s' % data.get('key'),
|
||||||
|
data.get('offset'),
|
||||||
|
True,
|
||||||
|
False),)
|
||||||
|
thread.setDaemon(True)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
elif (task['action'] == 'playlist' and
|
||||||
data.get('address') == 'node.plexapp.com'):
|
data.get('address') == 'node.plexapp.com'):
|
||||||
# E.g. watch later initiated by Companion
|
# E.g. watch later initiated by Companion
|
||||||
thread = Thread(target=Plex_Node,
|
thread = Thread(target=Plex_Node,
|
||||||
|
@ -88,6 +110,7 @@ class PlexCompanion(Thread):
|
||||||
True),)
|
True),)
|
||||||
thread.setDaemon(True)
|
thread.setDaemon(True)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
elif task['action'] == 'playlist':
|
elif task['action'] == 'playlist':
|
||||||
# Get the playqueue ID
|
# Get the playqueue ID
|
||||||
try:
|
try:
|
||||||
|
@ -97,16 +120,6 @@ class PlexCompanion(Thread):
|
||||||
import traceback
|
import traceback
|
||||||
log.error("Traceback:\n%s" % traceback.format_exc())
|
log.error("Traceback:\n%s" % traceback.format_exc())
|
||||||
return
|
return
|
||||||
if typus == 'library/metadata':
|
|
||||||
# e.g. Alexa
|
|
||||||
thread = Thread(target=Plex_Node,
|
|
||||||
args=('{server}%s' % data.get('key'),
|
|
||||||
data.get('offset'),
|
|
||||||
True,
|
|
||||||
False),)
|
|
||||||
thread.setDaemon(True)
|
|
||||||
thread.start()
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
playqueue = self.mgr.playqueue.get_playqueue_from_type(
|
playqueue = self.mgr.playqueue.get_playqueue_from_type(
|
||||||
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[data['type']])
|
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[data['type']])
|
||||||
|
|
|
@ -101,8 +101,9 @@ def process_command(request_path, params, queue=None):
|
||||||
log.debug('Received request_path: %s, params: %s' % (request_path, params))
|
log.debug('Received request_path: %s, params: %s' % (request_path, params))
|
||||||
if "/playMedia" in request_path:
|
if "/playMedia" in request_path:
|
||||||
# We need to tell service.py
|
# We need to tell service.py
|
||||||
|
action = 'alexa' if params.get('deviceName') == 'Alexa' else 'playlist'
|
||||||
queue.put({
|
queue.put({
|
||||||
'action': 'playlist',
|
'action': action,
|
||||||
'data': params
|
'data': params
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ def playlist_item_from_kodi(kodi_item):
|
||||||
# TO BE VERIFIED - PLEX DOESN'T LIKE PLAYLIST ADDS IN THIS MANNER
|
# TO BE VERIFIED - PLEX DOESN'T LIKE PLAYLIST ADDS IN THIS MANNER
|
||||||
item.uri = ('library://%s/item/library%%2Fmetadata%%2F%s' %
|
item.uri = ('library://%s/item/library%%2Fmetadata%%2F%s' %
|
||||||
(item.plex_UUID, item.plex_id))
|
(item.plex_UUID, item.plex_id))
|
||||||
|
log.debug('Made playlist item from Kodi: %s' % item)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,6 +137,10 @@ def playlist_item_from_plex(plex_id):
|
||||||
item.kodi_type = plex_dbitem[4]
|
item.kodi_type = plex_dbitem[4]
|
||||||
except:
|
except:
|
||||||
raise KeyError('Could not find plex_id %s in database' % plex_id)
|
raise KeyError('Could not find plex_id %s in database' % plex_id)
|
||||||
|
item.plex_UUID = plex_id
|
||||||
|
item.uri = ('library://%s/item/library%%2Fmetadata%%2F%s' %
|
||||||
|
(item.plex_UUID, plex_id))
|
||||||
|
log.debug('Made playlist item from plex: %s' % item)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,10 @@ from xbmc import sleep, Player, PlayList, PLAYLIST_MUSIC, PLAYLIST_VIDEO
|
||||||
|
|
||||||
from utils import window, ThreadMethods, ThreadMethodsAdditionalSuspend
|
from utils import window, ThreadMethods, ThreadMethodsAdditionalSuspend
|
||||||
import playlist_func as PL
|
import playlist_func as PL
|
||||||
from PlexFunctions import ConvertPlexToKodiTime
|
from PlexFunctions import ConvertPlexToKodiTime, GetAllPlexChildren
|
||||||
|
from PlexAPI import API
|
||||||
from playbackutils import PlaybackUtils
|
from playbackutils import PlaybackUtils
|
||||||
|
import variables as v
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
log = logging.getLogger("PLEX."+__name__)
|
log = logging.getLogger("PLEX."+__name__)
|
||||||
|
@ -69,6 +71,31 @@ class Playqueue(Thread):
|
||||||
raise ValueError('Wrong playlist type passed in: %s' % typus)
|
raise ValueError('Wrong playlist type passed in: %s' % typus)
|
||||||
return playqueue
|
return playqueue
|
||||||
|
|
||||||
|
def init_playqueue_from_plex_children(self, plex_id):
|
||||||
|
"""
|
||||||
|
Init a new playqueue e.g. from an album. Alexa does this
|
||||||
|
"""
|
||||||
|
xml = GetAllPlexChildren(plex_id)
|
||||||
|
try:
|
||||||
|
xml[0].attrib
|
||||||
|
except (TypeError, IndexError, AttributeError):
|
||||||
|
log.error('Could not download the PMS xml for %s' % plex_id)
|
||||||
|
return
|
||||||
|
playqueue = self.get_playqueue_from_type(
|
||||||
|
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[xml[0].attrib['type']])
|
||||||
|
playqueue.clear()
|
||||||
|
for i, child in enumerate(xml):
|
||||||
|
api = API(child)
|
||||||
|
PL.add_item_to_playlist(playqueue, i, plex_id=api.getRatingKey())
|
||||||
|
log.debug('Firing up Kodi player')
|
||||||
|
thread = Thread(target=Player().play,
|
||||||
|
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,
|
||||||
playqueue_id=None,
|
playqueue_id=None,
|
||||||
|
|
Loading…
Add table
Reference in a new issue