From 48654801e5e0fd30c3115a887d1e47e4eedc0273 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 13 Oct 2015 03:00:32 -0500 Subject: [PATCH] Fix double report progress Removed stack implementation. Working with playlist and setresolvedurl. --- resources/lib/PlaybackUtils.py | 7 +++-- resources/lib/Player.py | 56 +++++++++------------------------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/resources/lib/PlaybackUtils.py b/resources/lib/PlaybackUtils.py index 4a1441be..9f787bf2 100644 --- a/resources/lib/PlaybackUtils.py +++ b/resources/lib/PlaybackUtils.py @@ -77,6 +77,7 @@ class PlaybackUtils(): propertiesPlayback = utils.window('propertiesPlayback') == "true" introsPlaylist = False + dummyPlaylist = False currentPosition = startPos self.logMsg("Playlist start position: %s" % startPos, 2) @@ -184,6 +185,7 @@ class PlaybackUtils(): if (not homeScreen and introsPlaylist) or (homeScreen and sizePlaylist > 0): # Playlist will fail on the current position. Adding dummy url + dummyPlaylist = True self.logMsg("Adding dummy url to counter the setResolvedUrl error.", 2) playlist.add(playurl, index=startPos) currentPosition += 1 @@ -194,6 +196,7 @@ class PlaybackUtils(): self.logMsg("Resetting properties playback flag.", 2) utils.window('propertiesPlayback', clear=True) + self.verifyPlaylist() ############### PLAYBACK ################ @@ -203,8 +206,8 @@ class PlaybackUtils(): self.logMsg("Processed as a single item.", 1) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem) - elif not homeScreen: - + elif 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) xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listItem) diff --git a/resources/lib/Player.py b/resources/lib/Player.py index 44cb0a37..8dfa27d3 100644 --- a/resources/lib/Player.py +++ b/resources/lib/Player.py @@ -31,8 +31,6 @@ class Player( xbmc.Player ): played_information = {} playStats = {} currentFile = None - stackFiles = None - stackElapsed = 0 def __init__(self, *args): @@ -47,38 +45,19 @@ class Player( xbmc.Player ): def GetPlayStats(self): return self.playStats - def currentStackItem(self, stackItems): - # Only for stacked items - stack:// - xbmcplayer = self.xbmcplayer - - stack = stackItems.replace("stack://", "").split(" , ") - position = xbmcplayer.getTime() - totalRuntime = 0 - - for item in stack: - runtime = int(utils.window("%sruntimeticks" % item)) / 10000000 - # Verify the position compared to the totalRuntime for stacked items processed in loop so far. - if position < (runtime + totalRuntime): - self.stackElapsed = totalRuntime - self.currentFile = item - return item - else: - totalRuntime += runtime - def onPlayBackStarted( self ): # Will be called when xbmc starts playing a file xbmcplayer = self.xbmcplayer self.stopAll() - + # Get current file try: currentFile = xbmcplayer.getPlayingFile() - xbmc.sleep(200) + xbmc.sleep(300) except: currentFile = "" count = 0 while not currentFile: - xbmc.sleep(100) try: currentFile = xbmcplayer.getPlayingFile() @@ -91,18 +70,9 @@ class Player( xbmc.Player ): if currentFile: - # if stack://, get currently playing item - if "stack://" in currentFile: - self.stackFiles = currentFile - currentFile = self.currentStackItem(currentFile) - else: - self.stackFiles = None - self.currentFile = currentFile - self.stackElapsed = 0 - self.logMsg("ONPLAYBACK_STARTED: %s" % currentFile, 0) + self.currentFile = currentFile - # We may need to wait for info to be set in kodi monitor itemId = utils.window("%sitem_id" % currentFile) tryCount = 0 @@ -116,6 +86,8 @@ class Player( xbmc.Player ): else: tryCount += 1 else: + self.logMsg("ONPLAYBACK_STARTED: %s ITEMID: %s" % (currentFile, itemId), 0) + # Only proceed if an itemId was found. runtime = utils.window("%sruntimeticks" % currentFile) refresh_id = utils.window("%srefresh_id" % currentFile) @@ -143,7 +115,7 @@ class Player( xbmc.Player ): 'MediaSourceId': itemId, 'PlayMethod': playMethod, 'VolumeLevel': volume, - 'PositionTicks': int(seekTime * 10000000) - int(self.stackElapsed * 10000000), + 'PositionTicks': int(seekTime * 10000000), 'IsMuted': muted } @@ -225,7 +197,7 @@ class Player( xbmc.Player ): 'SubtitleStreamIndex': postdata['SubtitleStreamIndex'], 'playmethod': playMethod, 'Type': itemType, - 'currentPosition': int(seekTime) - int(self.stackElapsed) + 'currentPosition': int(seekTime) } self.played_information[currentFile] = data @@ -284,7 +256,7 @@ class Player( xbmc.Player ): 'ItemId': itemId, 'MediaSourceId': itemId, 'PlayMethod': playMethod, - 'PositionTicks': int(playTime * 10000000) - int(self.stackElapsed * 10000000), + 'PositionTicks': int(playTime * 10000000), 'IsPaused': paused, 'VolumeLevel': volume, 'IsMuted': muted @@ -432,12 +404,12 @@ class Player( xbmc.Player ): if percentComplete >= markPlayedAt and offerDelete: # Item could be stacked, so only offer to delete the main item. - if not self.stackFiles or itemId == utils.window('%sitem_id' % self.stackFiles): - return_value = xbmcgui.Dialog().yesno("Offer Delete", "Delete %s" % currentFile.split("/")[-1], "on Emby Server?") - if return_value: - # Delete Kodi entry before Emby - listItem = [itemId] - LibrarySync().removefromDB(listItem, True) + self.logMsg("Offering deletion for: %s." % itemId, 1) + return_value = xbmcgui.Dialog().yesno("Offer Delete", "Delete %s" % currentFile.split("/")[-1], "on Emby Server?") + if return_value: + # Delete Kodi entry before Emby + listItem = [itemId] + LibrarySync().removefromDB(listItem, True) # Stop transcoding if playMethod == "Transcode":