Fix resume time Plex Companion
This commit is contained in:
parent
fd8d6007db
commit
ea1bc0a5bd
2 changed files with 4 additions and 167 deletions
|
@ -66,7 +66,10 @@ def plexCompanion(fullurl, params):
|
||||||
utils.logMsg(
|
utils.logMsg(
|
||||||
title, "Error getting PMS playlist for key %s" % key, -1)
|
title, "Error getting PMS playlist for key %s" % key, -1)
|
||||||
else:
|
else:
|
||||||
PassPlaylist(xml, resume=int(params.get('offset', 0)))
|
PassPlaylist(
|
||||||
|
xml,
|
||||||
|
resume=PlexFunctions.ConvertPlexToKodiTime(
|
||||||
|
params.get('offset', 0)))
|
||||||
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)
|
||||||
|
|
|
@ -126,172 +126,6 @@ class PlaybackUtils():
|
||||||
|
|
||||||
return listitems
|
return listitems
|
||||||
|
|
||||||
def play(self, itemid, dbid=None):
|
|
||||||
|
|
||||||
self.logMsg("Play called.", 1)
|
|
||||||
|
|
||||||
doUtils = self.doUtils
|
|
||||||
item = self.item
|
|
||||||
API = self.API
|
|
||||||
listitem = xbmcgui.ListItem()
|
|
||||||
playutils = putils.PlayUtils(item)
|
|
||||||
|
|
||||||
playurl = playutils.getPlayUrl()
|
|
||||||
if not playurl:
|
|
||||||
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem)
|
|
||||||
|
|
||||||
if dbid is None:
|
|
||||||
# Item is not in Kodi database
|
|
||||||
listitem.setPath(playurl)
|
|
||||||
self.setProperties(playurl, listitem)
|
|
||||||
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
|
|
||||||
|
|
||||||
############### ORGANIZE CURRENT PLAYLIST ################
|
|
||||||
|
|
||||||
homeScreen = xbmc.getCondVisibility('Window.IsActive(home)')
|
|
||||||
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
|
||||||
startPos = max(playlist.getposition(), 0) # Can return -1
|
|
||||||
sizePlaylist = playlist.size()
|
|
||||||
currentPosition = startPos
|
|
||||||
|
|
||||||
propertiesPlayback = utils.window('emby_playbackProps') == "true"
|
|
||||||
introsPlaylist = False
|
|
||||||
dummyPlaylist = False
|
|
||||||
|
|
||||||
self.logMsg("Playlist start position: %s" % startPos, 1)
|
|
||||||
self.logMsg("Playlist plugin position: %s" % currentPosition, 1)
|
|
||||||
self.logMsg("Playlist size: %s" % sizePlaylist, 1)
|
|
||||||
|
|
||||||
############### RESUME POINT ################
|
|
||||||
|
|
||||||
userdata = API.getUserData()
|
|
||||||
seektime = API.adjustResume(userdata['Resume'])
|
|
||||||
|
|
||||||
# We need to ensure we add the intro and additional parts only once.
|
|
||||||
# Otherwise we get a loop.
|
|
||||||
if not propertiesPlayback:
|
|
||||||
|
|
||||||
utils.window('emby_playbackProps', value="true")
|
|
||||||
self.logMsg("Setting up properties in playlist.", 1)
|
|
||||||
|
|
||||||
if (not homeScreen and not seektime and
|
|
||||||
utils.window('emby_customPlaylist') != "true"):
|
|
||||||
|
|
||||||
self.logMsg("Adding dummy file to playlist.", 2)
|
|
||||||
dummyPlaylist = True
|
|
||||||
playlist.add(playurl, listitem, index=startPos)
|
|
||||||
# Remove the original item from playlist
|
|
||||||
self.pl.removefromPlaylist(startPos+1)
|
|
||||||
# Readd the original item to playlist - via jsonrpc so we have full metadata
|
|
||||||
self.pl.insertintoPlaylist(currentPosition+1, dbid, item['Type'].lower())
|
|
||||||
currentPosition += 1
|
|
||||||
|
|
||||||
############### -- CHECK FOR INTROS ################
|
|
||||||
|
|
||||||
if utils.settings('enableCinema') == "true" and not seektime:
|
|
||||||
# if we have any play them when the movie/show is not being resumed
|
|
||||||
url = "{server}/emby/Users/{UserId}/Items/%s/Intros?format=json" % itemid
|
|
||||||
intros = doUtils.downloadUrl(url)
|
|
||||||
|
|
||||||
if intros['TotalRecordCount'] != 0:
|
|
||||||
getTrailers = True
|
|
||||||
|
|
||||||
if utils.settings('askCinema') == "true":
|
|
||||||
resp = xbmcgui.Dialog().yesno("Emby Cinema Mode", "Play trailers?")
|
|
||||||
if not resp:
|
|
||||||
# User selected to not play trailers
|
|
||||||
getTrailers = False
|
|
||||||
self.logMsg("Skip trailers.", 1)
|
|
||||||
|
|
||||||
if getTrailers:
|
|
||||||
for intro in intros['Items']:
|
|
||||||
# The server randomly returns intros, process them.
|
|
||||||
introListItem = xbmcgui.ListItem()
|
|
||||||
introPlayurl = putils.PlayUtils(intro).getPlayUrl()
|
|
||||||
self.logMsg("Adding Intro: %s" % introPlayurl, 1)
|
|
||||||
|
|
||||||
# Set listitem and properties for intros
|
|
||||||
pbutils = PlaybackUtils(intro)
|
|
||||||
pbutils.setProperties(introPlayurl, introListItem)
|
|
||||||
|
|
||||||
self.pl.insertintoPlaylist(currentPosition, url=introPlayurl)
|
|
||||||
introsPlaylist = True
|
|
||||||
currentPosition += 1
|
|
||||||
|
|
||||||
|
|
||||||
############### -- ADD MAIN ITEM ONLY FOR HOMESCREEN ###############
|
|
||||||
|
|
||||||
if homeScreen and not seektime and not sizePlaylist:
|
|
||||||
# Extend our current playlist with the actual item to play
|
|
||||||
# only if there's no playlist first
|
|
||||||
self.logMsg("Adding main item to playlist.", 1)
|
|
||||||
self.pl.addtoPlaylist(dbid, item['Type'].lower())
|
|
||||||
|
|
||||||
# Ensure that additional parts are played after the main item
|
|
||||||
currentPosition += 1
|
|
||||||
|
|
||||||
############### -- CHECK FOR ADDITIONAL PARTS ################
|
|
||||||
|
|
||||||
if item.get('PartCount'):
|
|
||||||
# Only add to the playlist after intros have played
|
|
||||||
partcount = item['PartCount']
|
|
||||||
url = "{server}/emby/Videos/%s/AdditionalParts?format=json" % itemid
|
|
||||||
parts = doUtils.downloadUrl(url)
|
|
||||||
for part in parts['Items']:
|
|
||||||
|
|
||||||
additionalListItem = xbmcgui.ListItem()
|
|
||||||
additionalPlayurl = putils.PlayUtils(part).getPlayUrl()
|
|
||||||
self.logMsg("Adding additional part: %s" % partcount, 1)
|
|
||||||
|
|
||||||
# Set listitem and properties for each additional parts
|
|
||||||
pbutils = PlaybackUtils(part)
|
|
||||||
pbutils.setProperties(additionalPlayurl, additionalListItem)
|
|
||||||
pbutils.setArtwork(additionalListItem)
|
|
||||||
|
|
||||||
playlist.add(additionalPlayurl, additionalListItem, index=currentPosition)
|
|
||||||
self.pl.verifyPlaylist()
|
|
||||||
currentPosition += 1
|
|
||||||
|
|
||||||
if dummyPlaylist:
|
|
||||||
# Added a dummy file to the playlist,
|
|
||||||
# because the first item is going to fail automatically.
|
|
||||||
self.logMsg("Processed as a playlist. First item is skipped.", 1)
|
|
||||||
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem)
|
|
||||||
|
|
||||||
|
|
||||||
# We just skipped adding properties. Reset flag for next time.
|
|
||||||
elif propertiesPlayback:
|
|
||||||
self.logMsg("Resetting properties playback flag.", 2)
|
|
||||||
utils.window('emby_playbackProps', clear=True)
|
|
||||||
|
|
||||||
#self.pl.verifyPlaylist()
|
|
||||||
########## SETUP MAIN ITEM ##########
|
|
||||||
|
|
||||||
# For transcoding only, ask for audio/subs pref
|
|
||||||
if utils.window('emby_%s.playmethod' % playurl) == "Transcode":
|
|
||||||
playurl = playutils.audioSubsPref(playurl, listitem)
|
|
||||||
utils.window('emby_%s.playmethod' % playurl, value="Transcode")
|
|
||||||
|
|
||||||
listitem.setPath(playurl)
|
|
||||||
self.setProperties(playurl, listitem)
|
|
||||||
|
|
||||||
############### PLAYBACK ################
|
|
||||||
|
|
||||||
if homeScreen and seektime and utils.window('emby_customPlaylist') != "true":
|
|
||||||
self.logMsg("Play as a widget item.", 1)
|
|
||||||
self.setListItem(listitem)
|
|
||||||
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
|
|
||||||
|
|
||||||
elif ((introsPlaylist and utils.window('emby_customPlaylist') == "true") or
|
|
||||||
(homeScreen and not sizePlaylist)):
|
|
||||||
# Playlist was created just now, play it.
|
|
||||||
self.logMsg("Play playlist.", 1)
|
|
||||||
xbmc.Player().play(playlist, startpos=startPos)
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.logMsg("Play as a regular item.", 1)
|
|
||||||
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
|
|
||||||
|
|
||||||
def setProperties(self, playurl, listitem):
|
def setProperties(self, playurl, listitem):
|
||||||
# Set all properties necessary for plugin path playback
|
# Set all properties necessary for plugin path playback
|
||||||
itemid = self.API.getRatingKey()
|
itemid = self.API.getRatingKey()
|
||||||
|
|
Loading…
Reference in a new issue