From 2129257f888740f705400738b359cfdb99e3b8c6 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 19 Jun 2016 18:30:21 +0200 Subject: [PATCH] Fix plex.tv Watch Later ignored resume points --- default.py | 5 ++++- resources/lib/entrypoint.py | 42 +++++++++++++++++++++++++------------ resources/lib/player.py | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/default.py b/default.py index 31fbd6a8..d9b6d9bb 100644 --- a/default.py +++ b/default.py @@ -85,7 +85,8 @@ class Main: 'chooseServer': entrypoint.chooseServer, 'watchlater': entrypoint.watchlater, 'enterPMS': entrypoint.enterPMS, - 'togglePlexTV': entrypoint.togglePlexTV + 'togglePlexTV': entrypoint.togglePlexTV, + 'playwatchlater': entrypoint.playWatchLater } if "/extrafanart" in sys.argv[0]: @@ -134,6 +135,8 @@ class Main: modes[mode](itemid, folderid) elif mode == "companion": modes[mode](itemid, params=sys.argv[2]) + elif mode == 'playwatchlater': + modes[mode](params.get('id')[0], params.get('viewOffset')[0]) else: modes[mode]() else: diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 196c0422..3fb857e4 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -158,22 +158,38 @@ def PassPlaylist(xml, resume=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): """ Called only for a SINGLE element, not playQueues 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": utils.logMsg('doPlayback', 'Not yet authenticated for a PMS, abort ' 'starting playback', -1) @@ -1616,10 +1632,9 @@ def watchlater(): utils.logMsg(title, 'Displaying watch later plex.tv items', 1) xbmcplugin.setContent(int(sys.argv[1]), 'movies') - url = "plugin://plugin.video.plexkodiconnect.movies/" + url = "plugin://plugin.video.plexkodiconnect/" params = { - 'mode': "play", - 'dbid': 'plexnode' + 'mode': "playwatchlater", } for item in xml: API = PlexAPI.API(item) @@ -1627,6 +1642,7 @@ def watchlater(): API.AddStreamInfo(listitem) pbutils.PlaybackUtils(item).setArtwork(listitem) params['id'] = item.attrib.get('key') + params['viewOffset'] = item.attrib.get('viewOffset', '') xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url="%s?%s" % (url, urllib.urlencode(params)), diff --git a/resources/lib/player.py b/resources/lib/player.py index db02a649..60b52dd2 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -105,7 +105,7 @@ class Player(xbmc.Player): self.logMsg("Playing itemtype is: %s" % itemType, 1) 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) self.logMsg("Seeking to: %s" % customseek, 1) try: