Fix plex.tv Watch Later ignored resume points

This commit is contained in:
tomkat83 2016-06-19 18:30:21 +02:00
parent 82c9d43fd9
commit 2129257f88
3 changed files with 34 additions and 15 deletions

View file

@ -85,7 +85,8 @@ class Main:
'chooseServer': entrypoint.chooseServer, 'chooseServer': entrypoint.chooseServer,
'watchlater': entrypoint.watchlater, 'watchlater': entrypoint.watchlater,
'enterPMS': entrypoint.enterPMS, 'enterPMS': entrypoint.enterPMS,
'togglePlexTV': entrypoint.togglePlexTV 'togglePlexTV': entrypoint.togglePlexTV,
'playwatchlater': entrypoint.playWatchLater
} }
if "/extrafanart" in sys.argv[0]: if "/extrafanart" in sys.argv[0]:
@ -134,6 +135,8 @@ class Main:
modes[mode](itemid, folderid) modes[mode](itemid, folderid)
elif mode == "companion": elif mode == "companion":
modes[mode](itemid, params=sys.argv[2]) modes[mode](itemid, params=sys.argv[2])
elif mode == 'playwatchlater':
modes[mode](params.get('id')[0], params.get('viewOffset')[0])
else: else:
modes[mode]() modes[mode]()
else: else:

View file

@ -158,22 +158,38 @@ def PassPlaylist(xml, resume=None):
resumeId=xml.attrib.get('playQueueSelectedItemID', None)) resumeId=xml.attrib.get('playQueueSelectedItemID', None))
def playWatchLater(itemid, viewOffset):
"""
Called only for a SINGLE element for Plex.tv watch later
Always to return with a "setResolvedUrl"
"""
utils.logMsg(title, 'playWatchLater called with id: %s, viewOffset: %s'
% (itemid, viewOffset), 1)
# Plex redirect, e.g. watch later. Need to get actual URLs
xml = downloadutils.DownloadUtils().downloadUrl(itemid,
authenticate=False)
if xml in (None, 401):
utils.logMsg(title, "Could not resolve url %s" % itemid, -1)
return xbmcplugin.setResolvedUrl(
int(sys.argv[1]), False, xbmcgui.ListItem())
try:
viewOffset = int(PlexFunctions.PlexToKodiTimefactor() *
float(viewOffset))
except:
pass
else:
utils.window('plex_customplaylist.seektime', value=str(viewOffset))
utils.logMsg('Set resume point to %s' % str(viewOffset), 1)
return pbutils.PlaybackUtils(xml).play(None, 'plexnode')
def doPlayback(itemid, dbid): def doPlayback(itemid, dbid):
""" """
Called only for a SINGLE element, not playQueues Called only for a SINGLE element, not playQueues
Always to return with a "setResolvedUrl" Always to return with a "setResolvedUrl"
""" """
if dbid == 'plexnode':
# Plex redirect, e.g. watch later. Need to get actual URLs
xml = downloadutils.DownloadUtils().downloadUrl(itemid,
authenticate=False)
if xml in (None, 401):
utils.logMsg(title, "Could not resolve url %s" % itemid, -1)
return xbmcplugin.setResolvedUrl(
int(sys.argv[1]), False, xbmcgui.ListItem())
return pbutils.PlaybackUtils(xml).play(None, dbid)
if utils.window('plex_authenticated') != "true": if utils.window('plex_authenticated') != "true":
utils.logMsg('doPlayback', 'Not yet authenticated for a PMS, abort ' utils.logMsg('doPlayback', 'Not yet authenticated for a PMS, abort '
'starting playback', -1) 'starting playback', -1)
@ -1616,10 +1632,9 @@ def watchlater():
utils.logMsg(title, 'Displaying watch later plex.tv items', 1) utils.logMsg(title, 'Displaying watch later plex.tv items', 1)
xbmcplugin.setContent(int(sys.argv[1]), 'movies') xbmcplugin.setContent(int(sys.argv[1]), 'movies')
url = "plugin://plugin.video.plexkodiconnect.movies/" url = "plugin://plugin.video.plexkodiconnect/"
params = { params = {
'mode': "play", 'mode': "playwatchlater",
'dbid': 'plexnode'
} }
for item in xml: for item in xml:
API = PlexAPI.API(item) API = PlexAPI.API(item)
@ -1627,6 +1642,7 @@ def watchlater():
API.AddStreamInfo(listitem) API.AddStreamInfo(listitem)
pbutils.PlaybackUtils(item).setArtwork(listitem) pbutils.PlaybackUtils(item).setArtwork(listitem)
params['id'] = item.attrib.get('key') params['id'] = item.attrib.get('key')
params['viewOffset'] = item.attrib.get('viewOffset', '')
xbmcplugin.addDirectoryItem( xbmcplugin.addDirectoryItem(
handle=int(sys.argv[1]), handle=int(sys.argv[1]),
url="%s?%s" % (url, urllib.urlencode(params)), url="%s?%s" % (url, urllib.urlencode(params)),

View file

@ -105,7 +105,7 @@ class Player(xbmc.Player):
self.logMsg("Playing itemtype is: %s" % itemType, 1) self.logMsg("Playing itemtype is: %s" % itemType, 1)
customseek = window('plex_customplaylist.seektime') customseek = window('plex_customplaylist.seektime')
if (window('plex_customplaylist') == "true" and customseek): if customseek:
# Start at, when using custom playlist (play to Kodi from webclient) # Start at, when using custom playlist (play to Kodi from webclient)
self.logMsg("Seeking to: %s" % customseek, 1) self.logMsg("Seeking to: %s" % customseek, 1)
try: try: