From fb78d82db4da495c4e929711a889c9a4ae94240d Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 10 May 2018 20:22:28 -0500 Subject: [PATCH] Support resume default action --- resources/lib/playbackutils.py | 53 +++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index 2a7d18a5..deefe8eb 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -26,7 +26,7 @@ import shutil import embydb_functions as embydb from database import DatabaseConn from dialogs import resume -from utils import window, settings, language as lang +from utils import window, settings, language as lang, JSONRPC ################################################################################################# @@ -90,7 +90,7 @@ class PlaybackUtils(object): listitem = xbmcgui.ListItem() - log.info("Play called: %s", self.item['Name']) + log.info("Play called %s: %s", item_id, self.item['Name']) resume = window('emby.resume') window('emby.resume', clear=True) @@ -102,17 +102,27 @@ class PlaybackUtils(object): self.playlist.clear() return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem) - if force_transcode: - - seektime = self.API.get_userdata()['Resume'] - if seektime: - resume = self.resume_dialog(seektime) - if resume is None: - return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem) - elif not resume: - seektime = 0 - else: - seektime = self.API.adjust_resume(self.API.get_userdata()['Resume']) if resume == "true" else 0 + + if self.item['Type'] != "Audio": + + ''' Detect the seektime for video type content. + Verify the default video action set in Kodi for accurate resume behavior. + ''' + if self.get_play_action() == "Resume": + resume = "true" + + if force_transcode: + seektime = self.API.get_userdata()['Resume'] + + if seektime and resume != "true": + resume = self.resume_dialog(seektime) + + if resume is None: + return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem) + elif not resume: + seektime = 0 + else: + seektime = self.API.adjust_resume(self.API.get_userdata()['Resume']) if resume == "true" else 0 if force_transcode: log.info("Clear the playlist.") @@ -161,9 +171,24 @@ class PlaybackUtils(object): index += 1 if force_play: - if len(sys.argv) > 1: xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, self.stack[0][1]) + if len(sys.argv): + xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, self.stack[0][1]) + xbmc.Player().play(self.playlist, windowed=False) + @classmethod + def get_play_action(cls): + + ''' I could not figure out a way to listen to kodi setting changes? + For now, verify the play action every time play is called. + ''' + options = ['Choose', 'Play', 'Resume', 'Show information'] + result = JSONRPC('Settings.GetSettingValue').execute({'setting': "myvideos.selectaction"}) + try: + return options[result['result']['value']] + except Exception as error: + log.error("Returning play action due to error: %s", error) + return options[1] def set_playlist(self, play_url, item_id, listitem, seektime=None, db_id=None):