Adjust Plex Companion playQueues being passed to PlexKodiConnect to use playlist playall

This commit is contained in:
tomkat83 2016-02-10 13:50:04 +01:00
parent 531dba40bf
commit ea63801a2b
5 changed files with 39 additions and 37 deletions

View file

@ -132,7 +132,7 @@ def GetPlayQueue(playQueueID):
""" """
Fetches the PMS playqueue with the playQueueID as an XML Fetches the PMS playqueue with the playQueueID as an XML
Returns False if something went wrong Returns None if something went wrong
""" """
url = "{server}/playQueues/%s" % playQueueID url = "{server}/playQueues/%s" % playQueueID
args = {'Accept': 'application/xml'} args = {'Accept': 'application/xml'}
@ -140,7 +140,7 @@ def GetPlayQueue(playQueueID):
try: try:
xml.attrib['playQueueID'] xml.attrib['playQueueID']
except (AttributeError, KeyError): except (AttributeError, KeyError):
return False return None
return xml return xml

View file

@ -23,8 +23,8 @@ import embydb_functions as embydb
import playbackutils as pbutils import playbackutils as pbutils
import playutils import playutils
import api import api
import playlist
import PlexAPI
import PlexFunctions import PlexFunctions
################################################################################################# #################################################################################################
@ -53,21 +53,23 @@ def plexCompanion(fullurl, params):
params['containerKey']) params['containerKey'])
# Construct a container key that works always (get rid of playlist args) # Construct a container key that works always (get rid of playlist args)
utils.window('containerKey', '/'+library+'/'+key) utils.window('containerKey', '/'+library+'/'+key)
# Assume it's video when something goes wrong
playbackType = params.get('type', 'video')
if 'playQueues' in library: if 'playQueues' in library:
utils.logMsg(title, "Playing a playQueue. Query was: %s" % query, 1) utils.logMsg(title, "Playing a playQueue. Query was: %s" % query, 1)
# Playing a playlist that we need to fetch from PMS # Playing a playlist that we need to fetch from PMS
xml = PlexFunctions.GetPlayQueue(key) xml = PlexFunctions.GetPlayQueue(key)
if not xml: if xml is None:
utils.logMsg( utils.logMsg(
title, "Error getting PMS playlist for key %s" % key, -1) title, "Error getting PMS playlist for key %s" % key, -1)
return
else: else:
PassPlaylist( resume = PlexFunctions.ConvertPlexToKodiTime(
xml, params.get('offset', 0))
resume=PlexFunctions.ConvertPlexToKodiTime( itemids = []
params.get('offset', 0))) for item in xml:
itemids.append(item.get('ratingKey'))
return playlist.Playlist().playAll(itemids, resume)
else: else:
utils.logMsg( utils.logMsg(
title, "Not knowing what to do for now - no playQueue sent", -1) title, "Not knowing what to do for now - no playQueue sent", -1)
@ -104,7 +106,7 @@ def doPlayback(itemid, dbid):
item = PlexFunctions.GetPlexMetadata(itemid) item = PlexFunctions.GetPlexMetadata(itemid)
if item is None: if item is None:
return False return False
pbutils.PlaybackUtils(item).play(itemid, dbid) return pbutils.PlaybackUtils(item).play(itemid, dbid)
# utils.logMsg(title, "doPlayback called with itemid=%s, dbid=%s" # utils.logMsg(title, "doPlayback called with itemid=%s, dbid=%s"
# % (itemid, dbid), 1) # % (itemid, dbid), 1)

View file

@ -12,7 +12,6 @@ import xbmcplugin
import artwork import artwork
import clientinfo import clientinfo
import downloadutils
import playutils as putils import playutils as putils
import playlist import playlist
import read_embyserver as embyserver import read_embyserver as embyserver
@ -117,7 +116,8 @@ class PlaybackUtils():
############### -- CHECK FOR INTROS ################ ############### -- CHECK FOR INTROS ################
if utils.settings('enableCinema') == "true" and not seektime: if (utils.settings('enableCinema') == "true" and not seektime and
not utils.window('emby_customPlaylist') == "true"):
# if we have any play them when the movie/show is not being resumed # if we have any play them when the movie/show is not being resumed
xml = PF.GetPlexPlaylist( xml = PF.GetPlexPlaylist(
itemid, itemid,
@ -143,6 +143,11 @@ class PlaybackUtils():
if len(item[0][0]) > 1: if len(item[0][0]) > 1:
# Only add to the playlist after intros have played # Only add to the playlist after intros have played
for counter, part in enumerate(item[0][0]): for counter, part in enumerate(item[0][0]):
# Playlist items don't fail on their first call - skip them
# here, otherwise we'll get two 1st parts
if (counter == 0 and
utils.window('emby_customPlaylist') == "true"):
continue
# Set listitem and properties for each additional parts # Set listitem and properties for each additional parts
API.setPartNumber(counter) API.setPartNumber(counter)
additionalListItem = xbmcgui.ListItem() additionalListItem = xbmcgui.ListItem()

View file

@ -113,7 +113,7 @@ class Player(xbmc.Player):
# Start at, when using custom playlist (play to Kodi from webclient) # Start at, when using custom playlist (play to Kodi from webclient)
seektime = utils.window('emby_customPlaylist.seektime') seektime = utils.window('emby_customPlaylist.seektime')
self.logMsg("Seeking to: %s" % seektime, 1) self.logMsg("Seeking to: %s" % seektime, 1)
xbmcplayer.seekTime(int(seektime)/10000000.0) xbmcplayer.seekTime(int(seektime)*1000.0)
utils.window('emby_customPlaylist.seektime', clear=True) utils.window('emby_customPlaylist.seektime', clear=True)
seekTime = xbmcplayer.getTime() seekTime = xbmcplayer.getTime()

View file

@ -26,11 +26,6 @@ class Playlist():
self.emby = embyserver.Read_EmbyServer() self.emby = embyserver.Read_EmbyServer()
def playAll(self, itemids, startat): def playAll(self, itemids, startat):
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
player = xbmc.Player() player = xbmc.Player()
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear() playlist.clear()
@ -45,28 +40,28 @@ class Playlist():
# Seek to the starting position # Seek to the starting position
utils.window('emby_customplaylist.seektime', str(startat)) utils.window('emby_customplaylist.seektime', str(startat))
for itemid in itemids: with embydb.GetEmbyDB() as emby_db:
embydb_item = emby_db.getItem_byId(itemid) for itemid in itemids:
try: embydb_item = emby_db.getItem_byId(itemid)
dbid = embydb_item[0] try:
mediatype = embydb_item[4] dbid = embydb_item[0]
except TypeError: mediatype = embydb_item[4]
# Item is not found in our database, add item manually except TypeError:
self.logMsg("Item was not found in the database, manually adding item.", 1) # Item is not found in our database, add item manually
item = self.emby.getItem(itemid) self.logMsg("Item was not found in the database, manually adding item.", 1)
self.addtoPlaylist_xbmc(playlist, item) item = self.emby.getItem(itemid)
else: self.addtoPlaylist_xbmc(playlist, item)
# Add to playlist else:
self.addtoPlaylist(dbid, mediatype) # Add to playlist
self.addtoPlaylist(dbid, mediatype)
self.logMsg("Adding %s to playlist." % itemid, 1) self.logMsg("Adding %s to playlist." % itemid, 1)
if not started: if not started:
started = True started = True
player.play(playlist) player.play(playlist)
self.verifyPlaylist() self.verifyPlaylist()
embycursor.close()
def modifyPlaylist(self, itemids): def modifyPlaylist(self, itemids):