Redesign building Kodi playback list

This commit is contained in:
tomkat83 2016-02-04 12:59:36 +01:00
parent ea1bc0a5bd
commit 095eba1a74
2 changed files with 54 additions and 28 deletions

View file

@ -94,8 +94,8 @@ def PassPlaylist(xml, resume=None):
resume = max(resume1, resume2)
pbutils.PlaybackUtils(xml).StartPlay(
resume=resume,
resumeId=xml.attrib.get('playQueueSelectedItemID', None))
itemid=xml.attrib.get('playQueueSelectedItemID', None),
resume=resume)
def doPlayback(itemid, dbid):
@ -128,8 +128,8 @@ def doPlayback(itemid, dbid):
utils.logMsg(title, "No librarySectionUUID found.", 1)
# Play only 1 item, not playQueue
pbutils.PlaybackUtils(item).StartPlay(resume=resume,
resumeId=None)
pbutils.PlaybackUtils(item).StartPlay(itemid=itemid,
resume=resume)
##### DO RESET AUTH #####

View file

@ -39,13 +39,16 @@ class PlaybackUtils():
self.emby = embyserver.Read_EmbyServer()
self.pl = playlist.Playlist()
def StartPlay(self, resume=None, resumeId=None):
def StartPlay(self, itemid=None, resume=None):
"""
Feed with a PMS playQueue or a single PMS item metadata XML
Every item will get put in playlist
itemid is used to determine the original item supposed to be played
"""
self.logMsg("StartPlay called with resume=%s, resumeId=%s"
% (resume, resumeId), 1)
self.logMsg("StartPlay called with resume=%s, itemid=%s"
% (resume, itemid), 1)
self.itemid = itemid
self.playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
self.startPos = max(self.playlist.getposition(), 0) # Can return -1
@ -62,24 +65,32 @@ class PlaybackUtils():
startPlayer = True if self.startPos == self.sizePlaylist else False
# Run through the passed PMS playlist and construct self.playlist
listitems = []
listtuples = []
for mediaItem in self.item:
listitems += self.AddMediaItemToPlaylist(mediaItem)
listtuples += self.AddMediaItemToPlaylist(mediaItem)
# Kick off playback
# Kick off playback; no worries about overwriting initial listitem
if startPlayer:
self.logMsg("Starting new playback", 1)
Player = xbmc.Player()
Player.play(self.playlist, startpos=self.startPos)
if resume:
try:
Player.seekTime(resume)
except:
self.logMsg("Error, could not resume", -1)
Player.seekTime(resume)
# Kodi has already started playing; overwrite initial listitem to
# preserve resume timing on the Kodi side. No trailers anyway
elif resume > 0:
self.logMsg("Overwritten Kodi listitem for resume. Pos: %s"
% [x for (x, y) in listtuples if
x == self.newStartPos][0], 1)
startitem = [y for (x, y) in listtuples if
x == self.newStartPos][0]
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, startitem)
# No resume point given; start with very first item in our playlist
else:
# Delete the last playlist item because we have added it already
filename = self.playlist[-1].getfilename()
self.playlist.remove(filename)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitems[0])
self.logMsg("No resume; start from beginning", 1)
startitem = [y for (x, y) in listtuples if
x == self.startPos][0]
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, startitem)
def AddMediaItemToPlaylist(self, item):
"""
@ -94,7 +105,8 @@ class PlaybackUtils():
playutils = putils.PlayUtils(item)
# Get playurls per part and process them
listitems = []
listtuples = []
gotStart = False
for playurl in playutils.getPlayUrl():
# One new listitem per part
listitem = xbmcgui.ListItem()
@ -110,21 +122,34 @@ class PlaybackUtils():
self.setProperties(playurl, listitem)
# Set metadata
self.setListItem(listitem)
self.playlist.add(
playurl, listitem, index=self.currentPosition)
listitems.append(listitem)
playQueueItemID = self.API.GetPlayQueueItemID()
# This is the 1 part we need to start with (otherwise resume is
# lost on the Kodi side). Skip adding a playlist item; overwrite!
if (not gotStart and (self.itemid == self.API.getRatingKey() or
self.itemid == playQueueItemID)):
self.logMsg("Item to start with has playlist position %s"
% (self.currentPosition), 1)
# Safe place we're at for later
self.newStartPos = self.currentPosition
# Set flag that we found (first ;-)) start item/part
gotStart = True
# Otherwise, add a new playlist item
else:
self.playlist.add(
playurl, listitem, index=self.currentPosition)
listtuples.append((self.currentPosition, listitem))
self.currentPosition += 1
# We need to keep track of playQueueItemIDs for Plex Companion
playQueueItemID = self.API.GetPlayQueueItemID()
utils.window(
'plex_%s.playQueueItemID' % playurl, playQueueItemID)
utils.window(
'plex_%s.playlistPosition'
% playurl, str(self.currentPosition))
return listitems
return listtuples
def setProperties(self, playurl, listitem):
# Set all properties necessary for plugin path playback
@ -233,26 +258,26 @@ class PlaybackUtils():
mediaType = API.getType()
people = API.getPeople()
userdata = API.getUserData()
# userdata = API.getUserData()
title, sorttitle = API.getTitle()
metadata = {
'genre': API.joinList(API.getGenres()),
'year': API.getYear(),
'rating': API.getAudienceRating(),
'playcount': userdata['PlayCount'],
# 'playcount': userdata['PlayCount'],
'cast': people['Cast'],
'director': API.joinList(people.get('Director')),
'plot': API.getPlot(),
'title': title,
'sorttitle': sorttitle,
'duration': userdata['Runtime'],
# 'duration': userdata['Runtime'],
'studio': API.joinList(API.getStudios()),
'tagline': API.getTagline(),
'writer': API.joinList(people.get('Writer')),
'premiered': API.getPremiereDate(),
'dateadded': API.getDateCreated(),
'lastplayed': userdata['LastPlayedDate'],
# 'lastplayed': userdata['LastPlayedDate'],
'mpaa': API.getMpaa(),
'aired': API.getPremiereDate(),
'votes': None
@ -279,6 +304,7 @@ class PlaybackUtils():
# - artist : list (['U2'])
listItem.setProperty('IsPlayable', 'true')
listItem.setProperty('IsFolder', 'false')
listItem.setProperty('StartOffset', -1)
listItem.setLabel(metadata['title'])
listItem.setInfo('video', infoLabels=metadata)
"""