From fdd16895e52137b4c71cdbe5cbf62a8791d2d831 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Sun, 16 Aug 2020 09:29:49 +0200 Subject: [PATCH 01/16] Update service.py --- service.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/service.py b/service.py index 6dee062..6110570 100644 --- a/service.py +++ b/service.py @@ -29,7 +29,7 @@ msgdialogprogress = xbmcgui.DialogProgress() addon_id = 'service.sleeptimer' -selfAddon = xbmcaddon.Addon(addon_id) +selfAddon = xbmcaddon.Addon(id=addon_id) datapath = xbmc.translatePath(selfAddon.getAddonInfo('profile')).decode('utf-8') addonfolder = xbmc.translatePath(selfAddon.getAddonInfo('path')).decode('utf-8') debug=selfAddon.getSetting('debug_mode') @@ -54,7 +54,7 @@ def translate(text): return selfAddon.getLocalizedString(text).encode('utf-8') def _log( message ): - print addon_id + ": " + str(message) + print(addon_id + ": " + str(message)) # print the actual playing file in DEBUG-mode def print_act_playing_file(): @@ -269,6 +269,25 @@ def __init__(self): xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (i)) # move down slowly xbmc.sleep(audiochangerate) + + #check if user pressed something while audio volume is going down and abort sleep process + idle_time_in_minutes = int(xbmc.getGlobalIdleTime())/60 + if idle_time_in_minutes < max_time_in_minutes: + _log ( "DEBUG: User pressed a key while volume is going down. Aborting sleep process" ) + #set volume back + _log ( "DEBUG: Setting back original volume") + xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (dct["result"]["volume"])) + iCheckTime = check_time_next + _log ( "Progressdialog cancelled, next check in " + str(iCheckTime) + " min" ) + # set next_check, so that it opens the dialog after "iCheckTime" + next_check = True + cancelled = True + break + if cancelled: + continue + + + # stop player anyway xbmc.sleep(5000) # wait 5s before stopping From b06f90ba26a393a1c9152fc772d62fb43438b1dc Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Thu, 1 Sep 2022 22:31:59 +0200 Subject: [PATCH 02/16] Merge from Kodi 19 --- addon.xml | 6 +-- resources/language/English/strings.po | 64 +++++++++++++----------- resources/language/Portuguese/strings.po | 8 ++- resources/settings.xml | 3 +- service.py | 60 ++++++++-------------- 5 files changed, 67 insertions(+), 74 deletions(-) diff --git a/addon.xml b/addon.xml index 330ff55..4d7be23 100644 --- a/addon.xml +++ b/addon.xml @@ -1,11 +1,11 @@ - + @@ -16,6 +16,6 @@ http://forum.kodi.tv/showthread.php?tid=211971 https://github.com/enen92/service.sleeptimer all - GNU GENERAL PUBLIC LICENSE. Version 2, June 1991 + GPL-2.0-only diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index e9b55bb..1e64586 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -16,116 +16,120 @@ msgstr "" msgctxt "#30000" msgid "Sleep Timer" -"" +msgstr "" msgctxt "#30001" msgid "Cancel to continue playing" -"" +msgstr "" msgctxt "#30002" msgid "Service check time (minutes)" -"" +msgstr "" msgctxt "#30003" msgid "Waiting time for the dialog (before stop) (seconds)" -"" +msgstr "" msgctxt "#30004" msgid "Slow mute audio before stop playing" -"" +msgstr "" msgctxt "#30005" msgid "General" -"" +msgstr "" msgctxt "#30006" -msgid "Time between 1% volume change (millisec)" -"" +msgid "Time it takes to reach 0% volume (minutes)" +msgstr "" msgctxt "#30007" msgid "Next check time if dialog is cancelled (minutes)" -"" +msgstr "" msgctxt "#30008" msgid "Enable Screensaver after stopping" -"" +msgstr "" msgctxt "#30009" msgid "Audio/Video Supervision settings" -"" +msgstr "" msgctxt "#30010" msgid "Enable Video Supervision" -"" +msgstr "" msgctxt "#30011" msgid "Enable Audio Supervision" -"" +msgstr "" msgctxt "#30012" msgid "Maximum Playing time (minutes) before asking to stop" -"" +msgstr "" msgctxt "#30013" msgid "Video Playbacktime" -"" +msgstr "" msgctxt "#30014" msgid "Audio Playbacktime" -"" +msgstr "" msgctxt "#30015" msgid "Debug" -"" +msgstr "" msgctxt "#30016" msgid "Debug mode" -"" +msgstr "" msgctxt "#30017" msgid "'Enable' debugging sets:" -"" +msgstr "" msgctxt "#30018" msgid "Audio and Video-Check enabled" -"" +msgstr "" msgctxt "#30019" msgid "Service check time (minutes): '1'" -"" +msgstr "" msgctxt "#30020" msgid "Waiting time for the dialog (before stop) (seconds): '30'" -"" +msgstr "" msgctxt "#30021" msgid "It doesn't matter, what you set in the other Tabs!" -"" +msgstr "" msgctxt "#30022" msgid "Execute custom cmd after playback stop" -"" +msgstr "" msgctxt "#30023" msgid "Custom CMD" -"" +msgstr "" msgctxt "#30024" msgid "Supervision Mode" -"" +msgstr "" msgctxt "#30025" msgid "Hour start (eg. 23:00)" -"" +msgstr "" msgctxt "#30026" msgid "Hour supervision end (eg. 03:20)" -"" +msgstr "" msgctxt "#30027" msgid "Always" -"" +msgstr "" msgctxt "#30028" msgid "Specific Time" -"" \ No newline at end of file +msgstr "" + +msgctxt "#30029" +msgid "Set the minimum volume %" +msgstr "" \ No newline at end of file diff --git a/resources/language/Portuguese/strings.po b/resources/language/Portuguese/strings.po index 5828ff1..83957c5 100644 --- a/resources/language/Portuguese/strings.po +++ b/resources/language/Portuguese/strings.po @@ -38,8 +38,8 @@ msgid "General" msgstr "Geral" msgctxt "#30006" -msgid "Time between 1% volume change (millisec)" -msgstr "Tempo entre a alteração de 1% volume (millisec)" +msgid "Time it takes to reach 0% volume (minutes)" +msgstr "Tempo que leva para atingir o volume de 0% (minutos)" msgctxt "#30007" msgid "Next check time if dialog is cancelled (minutes)" @@ -128,3 +128,7 @@ msgstr "Sempre" msgctxt "#30028" msgid "Specific Time" msgstr "Tempo especifico" + +msgctxt "#30029" +msgid "Set the minimum volume %" +msgstr "Defina o volume mínimo %" \ No newline at end of file diff --git a/resources/settings.xml b/resources/settings.xml index a9443d3..366f995 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -4,7 +4,8 @@ - + + diff --git a/service.py b/service.py index 6110570..2b0f042 100644 --- a/service.py +++ b/service.py @@ -29,9 +29,9 @@ msgdialogprogress = xbmcgui.DialogProgress() addon_id = 'service.sleeptimer' -selfAddon = xbmcaddon.Addon(id=addon_id) -datapath = xbmc.translatePath(selfAddon.getAddonInfo('profile')).decode('utf-8') -addonfolder = xbmc.translatePath(selfAddon.getAddonInfo('path')).decode('utf-8') +selfAddon = xbmcaddon.Addon(addon_id) +datapath = xbmc.translatePath(selfAddon.getAddonInfo('profile')) +addonfolder = xbmc.translatePath(selfAddon.getAddonInfo('path')) debug=selfAddon.getSetting('debug_mode') __version__ = selfAddon.getAddonInfo('version') @@ -39,7 +39,8 @@ check_time_next = int(selfAddon.getSetting('check_time_next')) time_to_wait = int(selfAddon.getSetting('waiting_time_dialog')) audiochange = selfAddon.getSetting('audio_change') -audiochangerate = int(selfAddon.getSetting('audio_change_rate')) +muteVol = int(selfAddon.getSetting('mute_volume')) +audiointervallength = int(selfAddon.getSetting('audio_interval_length')) global audio_enable audio_enable = str(selfAddon.getSetting('audio_enable')) video_enable = str(selfAddon.getSetting('video_enable')) @@ -54,13 +55,13 @@ def translate(text): return selfAddon.getLocalizedString(text).encode('utf-8') def _log( message ): - print(addon_id + ": " + str(message)) + xbmc.log(addon_id + ": " + str(message), level=xbmc.LOGDEBUG) # print the actual playing file in DEBUG-mode def print_act_playing_file(): if debug == 'true': actPlayingFile = xbmc.Player().getPlayingFile() - _log ( "DEBUG: File: " + str(actPlayingFile) ) + _log (str(actPlayingFile)) # wait for abort - xbmc.sleep or time.sleep doesn't work # and prevents Kodi from exiting @@ -108,8 +109,9 @@ class service: def __init__(self): FirstCycle = True next_check = False + monitor = xbmc.Monitor() - while True: + while not monitor.abortRequested(): kodi_time = get_kodi_time() try: supervise_start_time = int(selfAddon.getSetting('hour_start_sup').split(':')[0]+selfAddon.getSetting('hour_start_sup').split(':')[1]) @@ -153,7 +155,7 @@ def __init__(self): _log ( "DEBUG: ----------------------------------------------------------------" ) # wait 15s before start to let Kodi finish the intro-movie - if xbmc.Monitor().waitForAbort(15): + if monitor.waitForAbort(15): break max_time_in_minutes = -1 @@ -238,7 +240,7 @@ def __init__(self): percent = increment*secs/100 secs_left = str((time_to_wait - secs)) remaining_display = str(secs_left) + " seconds left." - msgdialogprogress.update(percent,translate(30001),remaining_display) + msgdialogprogress.update(int(percent),translate(30001)) xbmc.sleep(1000) if (msgdialogprogress.iscanceled()): cancelled = True @@ -260,42 +262,23 @@ def __init__(self): if audiochange == 'true': resp = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": { "properties": [ "volume"] }, "id": 1}') dct = json.loads(resp) - muteVol = 10 - if (dct.has_key("result")) and (dct["result"].has_key("volume")): + if ("result" in dct) and ("volume" in dct["result"]): curVol = dct["result"]["volume"] for i in range(curVol - 1, muteVol - 1, -1): xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (i)) - # move down slowly - xbmc.sleep(audiochangerate) - - #check if user pressed something while audio volume is going down and abort sleep process - idle_time_in_minutes = int(xbmc.getGlobalIdleTime())/60 - if idle_time_in_minutes < max_time_in_minutes: - _log ( "DEBUG: User pressed a key while volume is going down. Aborting sleep process" ) - #set volume back - _log ( "DEBUG: Setting back original volume") - xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (dct["result"]["volume"])) - iCheckTime = check_time_next - _log ( "Progressdialog cancelled, next check in " + str(iCheckTime) + " min" ) - # set next_check, so that it opens the dialog after "iCheckTime" - next_check = True - cancelled = True - break - if cancelled: - continue - - - + # move down slowly ((total mins / steps) * ms in a min) + # (curVol-muteVol) runs the full timer where a user might control their volume via kodi instead of cutting it short when assuming a set volume of 100% + xbmc.sleep(round(audiointervallength / (curVol - muteVol) * 60000)) # stop player anyway - xbmc.sleep(5000) # wait 5s before stopping + monitor.waitForAbort(5) # wait 5s before stopping xbmc.executebuiltin('PlayerControl(Stop)') if audiochange == 'true': - xbmc.sleep(2000) # wait 2s before changing the volume back - if (dct.has_key("result")) and (dct["result"].has_key("volume")): + monitor.waitForAbort(2) # wait 2s before changing the volume back + if ("result" in dct) and ("volume" in dct["result"]): curVol = dct["result"]["volume"] # we can move upwards fast, because there is nothing playing xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (curVol)) @@ -303,9 +286,9 @@ def __init__(self): if enable_screensaver == 'true': if debug == 'true': _log ( "DEBUG: Activating screensaver" ) - xbmc.executebuiltin('ActivateScreensaver') - - #Run a custom cmd after playback is stopped + xbmc.executebuiltin('ActivateScreensaver') + + # Run a custom cmd after playback is stopped if custom_cmd == 'true': if debug == 'true': _log ( "DEBUG: Running custom script" ) @@ -325,5 +308,6 @@ def __init__(self): _log ( "DEBUG: diff_between_idle_and_check_time: " + str(diff_between_idle_and_check_time) ) do_next_check(iCheckTime) + monitor.waitForAbort(1) service() From d83788785367465693b8baad8d6598ff704853a2 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Thu, 1 Sep 2022 22:35:26 +0200 Subject: [PATCH 03/16] Allow user-abort when audio volume is going down --- service.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/service.py b/service.py index 2b0f042..aa53ba3 100644 --- a/service.py +++ b/service.py @@ -271,6 +271,22 @@ def __init__(self): # move down slowly ((total mins / steps) * ms in a min) # (curVol-muteVol) runs the full timer where a user might control their volume via kodi instead of cutting it short when assuming a set volume of 100% xbmc.sleep(round(audiointervallength / (curVol - muteVol) * 60000)) + + #check if user pressed something while audio volume is going down and abort sleep process + idle_time_in_minutes = int(xbmc.getGlobalIdleTime())/60 + if idle_time_in_minutes < max_time_in_minutes: + _log ( "DEBUG: User pressed a key while volume is going down. Aborting sleep process" ) + #set volume back + _log ( "DEBUG: Setting back original volume") + xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (dct["result"]["volume"])) + iCheckTime = check_time_next + _log ( "Progressdialog cancelled, next check in " + str(iCheckTime) + " min" ) + # set next_check, so that it opens the dialog after "iCheckTime" + next_check = True + cancelled = True + break + if cancelled: + continue # stop player anyway monitor.waitForAbort(5) # wait 5s before stopping From ac72543d1f98eed27aacfe62581aa0020aa4af39 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Fri, 10 Feb 2023 08:27:32 +0100 Subject: [PATCH 04/16] Prepared touch mode --- addon.xml | 2 +- resources/language/English/strings.po | 4 ++++ resources/settings.xml | 8 +++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/addon.xml b/addon.xml index 4d7be23..3d11b4f 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index 1e64586..801c0f6 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -132,4 +132,8 @@ msgstr "" msgctxt "#30029" msgid "Set the minimum volume %" +msgstr "" + +msgctxt "#30030" +msgid "Touch mode (Timer reset on start playing instead of user interaction)" msgstr "" \ No newline at end of file diff --git a/resources/settings.xml b/resources/settings.xml index 366f995..f44634b 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -15,14 +15,16 @@ - - + + - + + + From 64696e8107d7988e28e2602645c04ab97173832c Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Fri, 10 Feb 2023 10:16:12 +0100 Subject: [PATCH 05/16] Added touch mode --- resources/language/English/strings.po | 6 ++- resources/settings.xml | 3 +- service.py | 56 +++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index 801c0f6..3658f53 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -79,7 +79,7 @@ msgid "Debug" msgstr "" msgctxt "#30016" -msgid "Debug mode" +msgid "Debug mode (overwrites some settings!)" msgstr "" msgctxt "#30017" @@ -136,4 +136,8 @@ msgstr "" msgctxt "#30030" msgid "Touch mode (Timer reset on start playing instead of user interaction)" +msgstr "" + +msgctxt "#30031" +msgid "Touch mode Stop Time (min)" msgstr "" \ No newline at end of file diff --git a/resources/settings.xml b/resources/settings.xml index f44634b..559b9c1 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -1,7 +1,7 @@ - + @@ -24,6 +24,7 @@ + diff --git a/service.py b/service.py index aa53ba3..6281ee9 100644 --- a/service.py +++ b/service.py @@ -49,6 +49,8 @@ enable_screensaver = selfAddon.getSetting('enable_screensaver') custom_cmd = selfAddon.getSetting('custom_cmd') cmd = selfAddon.getSetting('cmd') +touchmode = selfAddon.getSetting('touchmode') +touchmodeStopTime = selfAddon.getSetting('touchmodeStopTime') # Functions: def translate(text): @@ -104,12 +106,49 @@ def should_i_supervise(kodi_time,supervise_start_time,supervise_end_time): return True else: return False + +class Touchmode: + def getSecondsFromNow(self, x): + return (datetime.datetime.now()-x).total_seconds() + + def checkStop(self): + if not xbmc.Player().isPlaying(): + + if self.lastStopTimeTest is None: + _log ( "Touch Mode: StopTimeTest" ) + self.lastStopTimeTest = datetime.datetime.now() + else: + if self.getSecondsFromNow(self.lastStopTimeTest) > touchmodeStopTime: + self.lastStopTimeStable = self.lastStopTimeTest + _log ( "Touch Mode: Set StopTime " + str(self.lastStopTimeStable) ) + else: + _log ( "Touch Mode: Waiting for stable" ) + #wait until touchmodeStopTime is elapsed - maybe only loading time due to new movie + pass + else: + self.lastStopTimeTest = None + + def __init__(self): + _log ( "Init Touch mode" ) + self.lastStopTimeTest = None + self.lastStopTimeStable = datetime.datetime.now() + self.checkStop() + + def getGlobalIdleTime(self): + self.checkStop() + if xbmc.Player().isPlaying(): + result = self.getSecondsFromNow(self.lastStopTimeStable) + else: + result = 0 + _log ( "Touch Mode: Return Idle Time " + str(result) ) + class service: def __init__(self): FirstCycle = True next_check = False monitor = xbmc.Monitor() + touchmode = Touchmode() while not monitor.abortRequested(): kodi_time = get_kodi_time() @@ -142,15 +181,15 @@ def __init__(self): _log ( "DEBUG: ################################################################" ) # Set this low values for easier debugging! _log ( "DEBUG: debug is enabled! Override Settings:" ) - enable_audio = 'true' + #enable_audio = 'true' _log ( "DEBUG: -> enable_audio: " + str(enable_audio) ) - maxaudio_time_in_minutes = 1 + #maxaudio_time_in_minutes = 1 _log ( "DEBUG: -> maxaudio_time_in_minutes: " + str(maxaudio_time_in_minutes) ) - enable_video = 'true' + #enable_video = 'true' _log ( "DEBUG: -> enable_video: " + str(enable_audio) ) - maxvideo_time_in_minutes = 1 + #maxvideo_time_in_minutes = 1 _log ( "DEBUG: -> maxvideo_time_in_minutes: " + str(maxvideo_time_in_minutes) ) - iCheckTime = 1 + #iCheckTime = 1 _log ( "DEBUG: -> check_time: " + str(iCheckTime) ) _log ( "DEBUG: ----------------------------------------------------------------" ) @@ -160,8 +199,11 @@ def __init__(self): max_time_in_minutes = -1 FirstCycle = False - - idle_time = xbmc.getGlobalIdleTime() + + if not touchmode: + idle_time = touchmode.getGlobalIdleTime() + else: + idle_time = xbmc.getGlobalIdleTime() idle_time_in_minutes = int(idle_time)/60 if xbmc.Player().isPlaying(): From 583d0e9203fc48be41b9b1f29cf5f1334f68734d Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Fri, 10 Feb 2023 16:35:58 +0100 Subject: [PATCH 06/16] Added touchmode function --- service.py | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/service.py b/service.py index 6281ee9..f8f6869 100644 --- a/service.py +++ b/service.py @@ -111,36 +111,44 @@ class Touchmode: def getSecondsFromNow(self, x): return (datetime.datetime.now()-x).total_seconds() - def checkStop(self): - if not xbmc.Player().isPlaying(): - - if self.lastStopTimeTest is None: - _log ( "Touch Mode: StopTimeTest" ) - self.lastStopTimeTest = datetime.datetime.now() - else: - if self.getSecondsFromNow(self.lastStopTimeTest) > touchmodeStopTime: - self.lastStopTimeStable = self.lastStopTimeTest - _log ( "Touch Mode: Set StopTime " + str(self.lastStopTimeStable) ) - else: - _log ( "Touch Mode: Waiting for stable" ) - #wait until touchmodeStopTime is elapsed - maybe only loading time due to new movie - pass - else: - self.lastStopTimeTest = None + def checkStateChange(self): + if xbmc.Player().isPlaying() != self.lastStateIsPlaying: + _log ( "Touch mode: " + repr(self.getSecondsFromNow(self.lastStateChangeTime)) + " > " + repr(float(touchmodeStopTime))) + if self.getSecondsFromNow(self.lastStateChangeTime) > float(touchmodeStopTime)*60: + self.lastStateChangeTime = datetime.datetime.now() + self.lastStateIsPlaying = xbmc.Player().isPlaying() + _log ( "Touch mode: Playing state change detected. Now isPlaying=" + repr(self.lastStateIsPlaying)) + return True + else: + _log ( "Delay... Waiting if change is permanent") + return False + return False + + def update(self): + hasChanged = self.checkStateChange() + if xbmc.Player().isPlaying(): + if hasChanged: + self.lastStopTime = datetime.datetime.now() + else: + self.lastStopTime = datetime.datetime.now() + _log ( "Touch Mode: Check Stop: Playing="+ str(xbmc.Player().isPlaying()) +" hasChanged=" +str(hasChanged) + " LastStop=" + str(self.lastStopTime)) def __init__(self): _log ( "Init Touch mode" ) - self.lastStopTimeTest = None - self.lastStopTimeStable = datetime.datetime.now() - self.checkStop() + self.lastStateIsPlaying = xbmc.Player().isPlaying() + self.lastStateChangeTime = datetime.datetime.now() + self.lastStopTime = datetime.datetime.now() + self.update() def getGlobalIdleTime(self): - self.checkStop() + self.update() if xbmc.Player().isPlaying(): - result = self.getSecondsFromNow(self.lastStopTimeStable) + result = int(self.getSecondsFromNow(self.lastStopTime)) else: result = 0 - _log ( "Touch Mode: Return Idle Time " + str(result) ) + _log ( "XBMC Idle Time" + repr(xbmc.getGlobalIdleTime())) + _log ( "Touch Mode: Return Idle Time " + repr(result) ) + return result class service: @@ -200,7 +208,7 @@ def __init__(self): max_time_in_minutes = -1 FirstCycle = False - if not touchmode: + if touchmode: idle_time = touchmode.getGlobalIdleTime() else: idle_time = xbmc.getGlobalIdleTime() From ab4daa85b9f0195792e7c5aadeae8de658bae5d8 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Wed, 22 Mar 2023 09:39:24 +0100 Subject: [PATCH 07/16] Fix for Kodi 20 --- addon.xml | 2 +- service.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addon.xml b/addon.xml index 3d11b4f..601fba9 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/service.py b/service.py index f8f6869..be1f9cc 100644 --- a/service.py +++ b/service.py @@ -30,8 +30,8 @@ addon_id = 'service.sleeptimer' selfAddon = xbmcaddon.Addon(addon_id) -datapath = xbmc.translatePath(selfAddon.getAddonInfo('profile')) -addonfolder = xbmc.translatePath(selfAddon.getAddonInfo('path')) +datapath = xbmcvfs.translatePath(selfAddon.getAddonInfo('profile')) +addonfolder = xbmcvfs.translatePath(selfAddon.getAddonInfo('path')) debug=selfAddon.getSetting('debug_mode') __version__ = selfAddon.getAddonInfo('version') From 6bffaf4c8c1210633ba465b4d6b9ee70bdd776c9 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Wed, 29 Mar 2023 16:19:20 +0200 Subject: [PATCH 08/16] new touchmode detections --- addon.xml | 2 +- service.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/addon.xml b/addon.xml index 601fba9..0d67d9d 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/service.py b/service.py index be1f9cc..ab96237 100644 --- a/service.py +++ b/service.py @@ -18,6 +18,7 @@ import time import datetime +import math import xbmc import xbmcplugin import xbmcgui @@ -123,27 +124,77 @@ def checkStateChange(self): _log ( "Delay... Waiting if change is permanent") return False return False + + def checkSeekOrNextMovie(self): + _log( "checkSeekOrNextMovie: " + repr(check_time)) + try: + if xbmc.Player().getPlayingFile() is not None: + if xbmc.Player().getPlayingFile() == self.lastPlayingFile: + _log ( "Still the same movie. Checking for seek user interaction" + str(self.lastGetTime) + " " + str( xbmc.Player().getTime()) + " check_time = " + str(check_time)) + + if math.fabs(xbmc.Player().getTime() - int(check_time)*60 - self.lastGetTime) > 3.0: #3sec of tolerance + _log ( "Seek detected. => User interaction") + self.setMovieDetails() + return True + else: + self.setMovieDetails() + #no seek detected + return False + else: + if self.lastGetTime > self.lastDuration - int(check_time)*60 - 3.0: #3sec of tolerance + _log ( "Next movie was selected because the old one reached its end.") + self.setMovieDetails() + return False + else: + _log ( "Changed movie by User interaction detected") + self.setMovieDetails() + return True + else: + if self.lastPlayingFile is not None: + _log ( "Stop detected by user") + self.setMovieDetails() + return True + else: + self.setMovieDetails() + return False + except Exception as e: + _log( "Exception in checkSeekOrNextMovie: " + str(e)) + return False + return False + def update(self): hasChanged = self.checkStateChange() + hasChanged2 = self.checkSeekOrNextMovie() if xbmc.Player().isPlaying(): - if hasChanged: - self.lastStopTime = datetime.datetime.now() + if hasChanged or hasChanged2: + self.lastUserInteractionTime = datetime.datetime.now() else: - self.lastStopTime = datetime.datetime.now() - _log ( "Touch Mode: Check Stop: Playing="+ str(xbmc.Player().isPlaying()) +" hasChanged=" +str(hasChanged) + " LastStop=" + str(self.lastStopTime)) + self.lastUserInteractionTime = datetime.datetime.now() + _log ( "Touch Mode: Check Stop: Playing="+ str(xbmc.Player().isPlaying()) +" hasChanged=" +str(hasChanged) + " lastUserInteractionTime=" + str(self.lastUserInteractionTime)) + + def setMovieDetails(self): + try: + self.lastPlayingFile = xbmc.Player().getPlayingFile() + self.lastGetTime = xbmc.Player().getTime() + self.lastDuration = xbmc.Player().getTotalTime() + except: + self.lastPlayingFile = None + self.lastGetTime = 0.0 + self.lastDuration = 100.0 def __init__(self): _log ( "Init Touch mode" ) self.lastStateIsPlaying = xbmc.Player().isPlaying() self.lastStateChangeTime = datetime.datetime.now() - self.lastStopTime = datetime.datetime.now() + self.lastUserInteractionTime = datetime.datetime.now() + self.setMovieDetails() self.update() def getGlobalIdleTime(self): self.update() if xbmc.Player().isPlaying(): - result = int(self.getSecondsFromNow(self.lastStopTime)) + result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) else: result = 0 _log ( "XBMC Idle Time" + repr(xbmc.getGlobalIdleTime())) @@ -157,6 +208,7 @@ def __init__(self): next_check = False monitor = xbmc.Monitor() touchmode = Touchmode() + diff_between_idle_and_check_time = None while not monitor.abortRequested(): kodi_time = get_kodi_time() @@ -375,5 +427,8 @@ def __init__(self): do_next_check(iCheckTime) monitor.waitForAbort(1) + else: + do_next_check(check_time) + monitor.waitForAbort(1) service() From b9b07163efa4a71b1b65a0bd735ffa66010e2986 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Thu, 30 Mar 2023 11:03:43 +0200 Subject: [PATCH 09/16] New concept using callback functions --- addon.xml | 2 +- resources/language/English/strings.po | 6 +- resources/settings.xml | 3 +- service.py | 132 ++++++++------------------ 4 files changed, 43 insertions(+), 100 deletions(-) diff --git a/addon.xml b/addon.xml index 0d67d9d..6085d89 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index 3658f53..7ea95c7 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -135,9 +135,5 @@ msgid "Set the minimum volume %" msgstr "" msgctxt "#30030" -msgid "Touch mode (Timer reset on start playing instead of user interaction)" +msgid "Alternative mode (user interaction is detected differently)" msgstr "" - -msgctxt "#30031" -msgid "Touch mode Stop Time (min)" -msgstr "" \ No newline at end of file diff --git a/resources/settings.xml b/resources/settings.xml index 559b9c1..e1200e6 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -23,8 +23,7 @@ - - + diff --git a/service.py b/service.py index ab96237..e22fc62 100644 --- a/service.py +++ b/service.py @@ -50,8 +50,7 @@ enable_screensaver = selfAddon.getSetting('enable_screensaver') custom_cmd = selfAddon.getSetting('custom_cmd') cmd = selfAddon.getSetting('cmd') -touchmode = selfAddon.getSetting('touchmode') -touchmodeStopTime = selfAddon.getSetting('touchmodeStopTime') +useAlternativeMode = selfAddon.getSetting('alternativemode') # Functions: def translate(text): @@ -107,98 +106,47 @@ def should_i_supervise(kodi_time,supervise_start_time,supervise_end_time): return True else: return False - -class Touchmode: + + +class AlternativeDetectionMode( xbmc.Player ): + + def __init__( self, *args ): + _log ( "Init Alternative mode" ) + self.setTime() + def getSecondsFromNow(self, x): return (datetime.datetime.now()-x).total_seconds() - - def checkStateChange(self): - if xbmc.Player().isPlaying() != self.lastStateIsPlaying: - _log ( "Touch mode: " + repr(self.getSecondsFromNow(self.lastStateChangeTime)) + " > " + repr(float(touchmodeStopTime))) - if self.getSecondsFromNow(self.lastStateChangeTime) > float(touchmodeStopTime)*60: - self.lastStateChangeTime = datetime.datetime.now() - self.lastStateIsPlaying = xbmc.Player().isPlaying() - _log ( "Touch mode: Playing state change detected. Now isPlaying=" + repr(self.lastStateIsPlaying)) - return True - else: - _log ( "Delay... Waiting if change is permanent") - return False - return False - - def checkSeekOrNextMovie(self): - _log( "checkSeekOrNextMovie: " + repr(check_time)) - try: - if xbmc.Player().getPlayingFile() is not None: - if xbmc.Player().getPlayingFile() == self.lastPlayingFile: - _log ( "Still the same movie. Checking for seek user interaction" + str(self.lastGetTime) + " " + str( xbmc.Player().getTime()) + " check_time = " + str(check_time)) - - if math.fabs(xbmc.Player().getTime() - int(check_time)*60 - self.lastGetTime) > 3.0: #3sec of tolerance - _log ( "Seek detected. => User interaction") - self.setMovieDetails() - return True - else: - self.setMovieDetails() - #no seek detected - return False - else: - if self.lastGetTime > self.lastDuration - int(check_time)*60 - 3.0: #3sec of tolerance - _log ( "Next movie was selected because the old one reached its end.") - self.setMovieDetails() - return False - else: - _log ( "Changed movie by User interaction detected") - self.setMovieDetails() - return True - else: - if self.lastPlayingFile is not None: - _log ( "Stop detected by user") - self.setMovieDetails() - return True - else: - self.setMovieDetails() - return False - except Exception as e: - _log( "Exception in checkSeekOrNextMovie: " + str(e)) - return False - return False - - - def update(self): - hasChanged = self.checkStateChange() - hasChanged2 = self.checkSeekOrNextMovie() - if xbmc.Player().isPlaying(): - if hasChanged or hasChanged2: - self.lastUserInteractionTime = datetime.datetime.now() - else: - self.lastUserInteractionTime = datetime.datetime.now() - _log ( "Touch Mode: Check Stop: Playing="+ str(xbmc.Player().isPlaying()) +" hasChanged=" +str(hasChanged) + " lastUserInteractionTime=" + str(self.lastUserInteractionTime)) - - def setMovieDetails(self): - try: - self.lastPlayingFile = xbmc.Player().getPlayingFile() - self.lastGetTime = xbmc.Player().getTime() - self.lastDuration = xbmc.Player().getTotalTime() - except: - self.lastPlayingFile = None - self.lastGetTime = 0.0 - self.lastDuration = 100.0 - - def __init__(self): - _log ( "Init Touch mode" ) - self.lastStateIsPlaying = xbmc.Player().isPlaying() - self.lastStateChangeTime = datetime.datetime.now() + + def setTime(self): self.lastUserInteractionTime = datetime.datetime.now() - self.setMovieDetails() - self.update() + + def onPlayBackSeekChapter(self, chapter): + _log( "onPlayBackSeekChapter" ) + self.setTime() + + def onPlayBackSeek(self, time, seekOffset): + _log( "onPlayBackSeek" ) + self.setTime() + + def onPlayBackResumed( self ): + # Will be called when xbmc starts playing a file + _log( "onPlayBackResumed" ) + self.setTime() + + def onPlayBackPaused( self ): + # Will be called when xbmc stops playing a file + _log( "onPlayBackPaused" ) + self.setTime() + + def onPlayBackStopped( self ): + # Will be called when user stops xbmc playing a file + _log( "onPlayBackStopped" ) + self.setTime() def getGlobalIdleTime(self): - self.update() - if xbmc.Player().isPlaying(): - result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) - else: - result = 0 - _log ( "XBMC Idle Time" + repr(xbmc.getGlobalIdleTime())) - _log ( "Touch Mode: Return Idle Time " + repr(result) ) + result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) + _log ( "XBMC Idle Time " + repr(xbmc.getGlobalIdleTime())) + _log ( "Alternative Idle Time " + repr(result) ) return result @@ -207,7 +155,7 @@ def __init__(self): FirstCycle = True next_check = False monitor = xbmc.Monitor() - touchmode = Touchmode() + alternativeMode = AlternativeDetectionMode() diff_between_idle_and_check_time = None while not monitor.abortRequested(): @@ -260,8 +208,8 @@ def __init__(self): max_time_in_minutes = -1 FirstCycle = False - if touchmode: - idle_time = touchmode.getGlobalIdleTime() + if useAlternativeMode: + idle_time = alternativeMode.getGlobalIdleTime() else: idle_time = xbmc.getGlobalIdleTime() idle_time_in_minutes = int(idle_time)/60 From e78b57c06251a04d3e6ec7abeca7fc82d5fed238 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Fri, 31 Mar 2023 18:49:22 +0200 Subject: [PATCH 10/16] Bugfix --- service.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/service.py b/service.py index e22fc62..4a41f89 100644 --- a/service.py +++ b/service.py @@ -150,6 +150,14 @@ def getGlobalIdleTime(self): return result + +def getIdleTimeInSeconds(alternativeMode): + if useAlternativeMode: + idle_time = alternativeMode.getGlobalIdleTime() + else: + idle_time = xbmc.getGlobalIdleTime() + return idle_time + class service: def __init__(self): FirstCycle = True @@ -208,10 +216,7 @@ def __init__(self): max_time_in_minutes = -1 FirstCycle = False - if useAlternativeMode: - idle_time = alternativeMode.getGlobalIdleTime() - else: - idle_time = xbmc.getGlobalIdleTime() + idle_time = getIdleTimeInSeconds(alternativeMode) idle_time_in_minutes = int(idle_time)/60 if xbmc.Player().isPlaying(): @@ -323,7 +328,7 @@ def __init__(self): xbmc.sleep(round(audiointervallength / (curVol - muteVol) * 60000)) #check if user pressed something while audio volume is going down and abort sleep process - idle_time_in_minutes = int(xbmc.getGlobalIdleTime())/60 + idle_time_in_minutes = int(getIdleTimeInSeconds(alternativeMode))/60 if idle_time_in_minutes < max_time_in_minutes: _log ( "DEBUG: User pressed a key while volume is going down. Aborting sleep process" ) #set volume back From c22786e1720da5d1a7fb386b05c54715f9d90f57 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Fri, 31 Mar 2023 18:59:14 +0200 Subject: [PATCH 11/16] Increase version to 2.3.1 --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 6085d89..50b2955 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ From 699bd67ee982a93fb4442f9ce5402fa142480f5a Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Sat, 1 Apr 2023 08:36:04 +0200 Subject: [PATCH 12/16] Bugfix for alternativMode --- addon.xml | 2 +- service.py | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/addon.xml b/addon.xml index 50b2955..23eba45 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/service.py b/service.py index 4a41f89..8ddcedd 100644 --- a/service.py +++ b/service.py @@ -112,41 +112,42 @@ class AlternativeDetectionMode( xbmc.Player ): def __init__( self, *args ): _log ( "Init Alternative mode" ) - self.setTime() + self.resetTime() def getSecondsFromNow(self, x): return (datetime.datetime.now()-x).total_seconds() - def setTime(self): + def resetTime(self): self.lastUserInteractionTime = datetime.datetime.now() def onPlayBackSeekChapter(self, chapter): _log( "onPlayBackSeekChapter" ) - self.setTime() + self.resetTime() def onPlayBackSeek(self, time, seekOffset): _log( "onPlayBackSeek" ) - self.setTime() + self.resetTime() def onPlayBackResumed( self ): # Will be called when xbmc starts playing a file _log( "onPlayBackResumed" ) - self.setTime() + self.resetTime() def onPlayBackPaused( self ): # Will be called when xbmc stops playing a file _log( "onPlayBackPaused" ) - self.setTime() + self.resetTime() def onPlayBackStopped( self ): # Will be called when user stops xbmc playing a file _log( "onPlayBackStopped" ) - self.setTime() + self.resetTime() def getGlobalIdleTime(self): - result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) - _log ( "XBMC Idle Time " + repr(xbmc.getGlobalIdleTime())) - _log ( "Alternative Idle Time " + repr(result) ) + result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) + if debug == 'true': + _log ( "XBMC Idle Time " + repr(xbmc.getGlobalIdleTime())) + _log ( "Alternative Idle Time " + repr(result) ) return result @@ -299,6 +300,7 @@ def __init__(self): xbmc.sleep(1000) if (msgdialogprogress.iscanceled()): cancelled = True + alternativeMode.resetTime() if debug == 'true': _log ( "DEBUG: Progressdialog cancelled" ) break From df12ee0a5d39c70e2f7a90f9a871849c4baae0c8 Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Fri, 14 Apr 2023 07:51:45 +0200 Subject: [PATCH 13/16] Added "Start" detection. --- addon.xml | 2 +- service.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 23eba45..f052d9a 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/service.py b/service.py index 8ddcedd..c888e9c 100644 --- a/service.py +++ b/service.py @@ -113,6 +113,7 @@ class AlternativeDetectionMode( xbmc.Player ): def __init__( self, *args ): _log ( "Init Alternative mode" ) self.resetTime() + self.lastEnded = None def getSecondsFromNow(self, x): return (datetime.datetime.now()-x).total_seconds() @@ -143,6 +144,30 @@ def onPlayBackStopped( self ): _log( "onPlayBackStopped" ) self.resetTime() + def onPlayBackStarted( self ): + # Will be called when user stops xbmc playing a file + if self.lastEnded is None: + _log("onPlayBackStarted: No ended movie detected before => user interaction") + self.resetTime() + return + + delayFromLastEnded = self.getSecondsFromNow(self.lastEnded) + _log( "onPlayBackStarted: Last Ended was detected within " + str(delayFromLastEnded) + "seconds" ) + + if delayFromLastEnded is not None and delayFromLastEnded < 60: + _log("onPlayBackStarted: Last movie endend => No user interaction") + #do nothing + else: + _log("onPlayBackStarted: Last movie did not end during 60s => User interaction") + self.resetTime() + + + def onPlayBackEnded( self ): + _log( "onPlayBackEnded" ) + _log("Storing last Ended time") + self.lastEnded = datetime.datetime.now() + self.resetTime() + def getGlobalIdleTime(self): result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) if debug == 'true': From bc7b38b74b23a3b58533e99be6439faca18c6cbb Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Sat, 15 Apr 2023 08:26:10 +0200 Subject: [PATCH 14/16] Bugfix --- addon.xml | 2 +- service.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addon.xml b/addon.xml index f052d9a..102b63a 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/service.py b/service.py index c888e9c..24f9eb9 100644 --- a/service.py +++ b/service.py @@ -166,7 +166,7 @@ def onPlayBackEnded( self ): _log( "onPlayBackEnded" ) _log("Storing last Ended time") self.lastEnded = datetime.datetime.now() - self.resetTime() + #self.resetTime() def getGlobalIdleTime(self): result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) From 44561f40e7f46be6dd14e562c24f7752fedebdfc Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Sun, 23 Jul 2023 22:34:53 +0200 Subject: [PATCH 15/16] More debug output --- service.py | 81 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/service.py b/service.py index 24f9eb9..6980b16 100644 --- a/service.py +++ b/service.py @@ -58,6 +58,10 @@ def translate(text): def _log( message ): xbmc.log(addon_id + ": " + str(message), level=xbmc.LOGDEBUG) + +def _debug( message ): + if debug == 'true': + _log ( "DEBUG: " + str(message) ) # print the actual playing file in DEBUG-mode def print_act_playing_file(): @@ -122,57 +126,57 @@ def resetTime(self): self.lastUserInteractionTime = datetime.datetime.now() def onPlayBackSeekChapter(self, chapter): - _log( "onPlayBackSeekChapter" ) + _debug( "onPlayBackSeekChapter" ) self.resetTime() def onPlayBackSeek(self, time, seekOffset): - _log( "onPlayBackSeek" ) + _debug( "onPlayBackSeek" ) self.resetTime() def onPlayBackResumed( self ): # Will be called when xbmc starts playing a file - _log( "onPlayBackResumed" ) + _debug( "onPlayBackResumed" ) self.resetTime() def onPlayBackPaused( self ): # Will be called when xbmc stops playing a file - _log( "onPlayBackPaused" ) + _debug( "onPlayBackPaused" ) self.resetTime() def onPlayBackStopped( self ): # Will be called when user stops xbmc playing a file - _log( "onPlayBackStopped" ) + _debug( "onPlayBackStopped" ) self.resetTime() def onPlayBackStarted( self ): # Will be called when user stops xbmc playing a file if self.lastEnded is None: - _log("onPlayBackStarted: No ended movie detected before => user interaction") + _debug("onPlayBackStarted: No ended movie detected before => user interaction") self.resetTime() return delayFromLastEnded = self.getSecondsFromNow(self.lastEnded) - _log( "onPlayBackStarted: Last Ended was detected within " + str(delayFromLastEnded) + "seconds" ) + _debug( "onPlayBackStarted: Last Ended was detected within " + str(delayFromLastEnded) + "seconds" ) if delayFromLastEnded is not None and delayFromLastEnded < 60: - _log("onPlayBackStarted: Last movie endend => No user interaction") + _debug("onPlayBackStarted: Last movie endend => No user interaction") #do nothing else: - _log("onPlayBackStarted: Last movie did not end during 60s => User interaction") + _debug("onPlayBackStarted: Last movie did not end during 60s => User interaction") self.resetTime() def onPlayBackEnded( self ): - _log( "onPlayBackEnded" ) - _log("Storing last Ended time") + _debug( "onPlayBackEnded" ) + _debug("Storing last Ended time") self.lastEnded = datetime.datetime.now() #self.resetTime() def getGlobalIdleTime(self): result = int(self.getSecondsFromNow(self.lastUserInteractionTime)) - if debug == 'true': - _log ( "XBMC Idle Time " + repr(xbmc.getGlobalIdleTime())) - _log ( "Alternative Idle Time " + repr(result) ) + + _debug ( "XBMC Idle Time " + repr(xbmc.getGlobalIdleTime())) + _debug ( "Alternative Idle Time " + repr(result) ) return result @@ -265,8 +269,7 @@ def __init__(self): what_is_playing = "audio" max_time_in_minutes = maxaudio_time_in_minutes else: - if debug == 'true': - _log ( "DEBUG: Player is playing Audio, but check is disabled" ) + _debug ( "DEBUG: Player is playing Audio, but check is disabled" ) do_next_check(iCheckTime) continue @@ -278,8 +281,7 @@ def __init__(self): what_is_playing = "video" max_time_in_minutes = maxvideo_time_in_minutes else: - if debug == 'true': - _log ( "DEBUG: Player is playing Video, but check is disabled" ) + _debug ( "DEBUG: Player is playing Video, but check is disabled" ) do_next_check(iCheckTime) continue @@ -294,20 +296,16 @@ def __init__(self): do_next_check(iCheckTime) continue - if debug == 'true': - _log ( "DEBUG: what_is_playing: " + str(what_is_playing) ) - - if debug == 'true': - _log ( "DEBUG: idle_time: '" + str(idle_time) + "s'; idle_time_in_minutes: '" + str(idle_time_in_minutes) + "'" ) - _log ( "DEBUG: max_time_in_minutes: " + str(max_time_in_minutes) ) + _debug ( "DEBUG: what_is_playing: " + str(what_is_playing) ) + _debug ( "DEBUG: idle_time: '" + str(idle_time) + "s'; idle_time_in_minutes: '" + str(idle_time_in_minutes) + "'" ) + _debug ( "DEBUG: max_time_in_minutes: " + str(max_time_in_minutes) ) # only display the Progressdialog, if audio or video is enabled AND idle limit is reached # Check if what_is_playing is not "other" and idle time exceeds limit if ( what_is_playing != "other" and idle_time_in_minutes >= max_time_in_minutes ): - if debug == 'true': - _log ( "DEBUG: idle_time exceeds max allowed. Display Progressdialog" ) + _debug ( "DEBUG: idle_time exceeds max allowed. Display Progressdialog" ) ret = msgdialogprogress.create(translate(30000),translate(30001)) secs=0 @@ -326,8 +324,7 @@ def __init__(self): if (msgdialogprogress.iscanceled()): cancelled = True alternativeMode.resetTime() - if debug == 'true': - _log ( "DEBUG: Progressdialog cancelled" ) + _debug ( "DEBUG: Progressdialog cancelled" ) break if cancelled == True: iCheckTime = check_time_next @@ -347,8 +344,11 @@ def __init__(self): if ("result" in dct) and ("volume" in dct["result"]): curVol = dct["result"]["volume"] + + _debug ( "DEBUG: Original volume value is " + str(curVol) ) for i in range(curVol - 1, muteVol - 1, -1): + _debug ( "DEBUG: Reducing volume to " + str(i)) xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (i)) # move down slowly ((total mins / steps) * ms in a min) # (curVol-muteVol) runs the full timer where a user might control their volume via kodi instead of cutting it short when assuming a set volume of 100% @@ -357,9 +357,9 @@ def __init__(self): #check if user pressed something while audio volume is going down and abort sleep process idle_time_in_minutes = int(getIdleTimeInSeconds(alternativeMode))/60 if idle_time_in_minutes < max_time_in_minutes: - _log ( "DEBUG: User pressed a key while volume is going down. Aborting sleep process" ) + _debug ( "DEBUG: User pressed a key while volume is going down. Aborting sleep process" ) #set volume back - _log ( "DEBUG: Setting back original volume") + _debug ( "DEBUG: Setting back original volume" + str(dct["result"]["volume"])) xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (dct["result"]["volume"])) iCheckTime = check_time_next _log ( "Progressdialog cancelled, next check in " + str(iCheckTime) + " min" ) @@ -371,32 +371,35 @@ def __init__(self): continue # stop player anyway + _debug ( "DEBUG: Waiting before stop" + str(curVol) ) monitor.waitForAbort(5) # wait 5s before stopping + _debug ( "DEBUG: Stopping... " + str(curVol) ) xbmc.executebuiltin('PlayerControl(Stop)') if audiochange == 'true': monitor.waitForAbort(2) # wait 2s before changing the volume back - if ("result" in dct) and ("volume" in dct["result"]): + if ("result" in dct) and ("volume" in dct["result"]): curVol = dct["result"]["volume"] + _debug ( "DEBUG: Reset volume to original value" + str(curVol) ) # we can move upwards fast, because there is nothing playing xbmc.executebuiltin('SetVolume(%d,showVolumeBar)' % (curVol)) + else: + _debug ( "DEBUG: DID NOT Reset volume 1 to original value" + str(curVol) ) + else: + _debug ( "DEBUG: DID NOT Reset volume 2 to original value" + str(curVol) ) if enable_screensaver == 'true': - if debug == 'true': - _log ( "DEBUG: Activating screensaver" ) + _debug ( "DEBUG: Activating screensaver" ) xbmc.executebuiltin('ActivateScreensaver') # Run a custom cmd after playback is stopped if custom_cmd == 'true': - if debug == 'true': - _log ( "DEBUG: Running custom script" ) + _debug ( "DEBUG: Running custom script" ) os.system(cmd) else: - if debug == 'true': - _log ( "DEBUG: Playing the stream, time does not exceed max limit" ) + _debug ( "DEBUG: Playing the stream, time does not exceed max limit" ) else: - if debug == 'true': - _log ( "DEBUG: Not playing any media file" ) + _debug ( "DEBUG: Not playing any media file" ) # reset max_time_in_minutes max_time_in_minutes = -1 From ae04d364a25f96e29c743d062c8b0e4e36c4dbdd Mon Sep 17 00:00:00 2001 From: haribertlondon Date: Tue, 8 Aug 2023 19:04:59 +0200 Subject: [PATCH 16/16] Changed order of commands, maybe a bugfix for android... --- service.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/service.py b/service.py index 6980b16..db58bad 100644 --- a/service.py +++ b/service.py @@ -373,11 +373,9 @@ def __init__(self): # stop player anyway _debug ( "DEBUG: Waiting before stop" + str(curVol) ) monitor.waitForAbort(5) # wait 5s before stopping - _debug ( "DEBUG: Stopping... " + str(curVol) ) - xbmc.executebuiltin('PlayerControl(Stop)') if audiochange == 'true': - monitor.waitForAbort(2) # wait 2s before changing the volume back + #monitor.waitForAbort(2) # wait 2s before changing the volume back if ("result" in dct) and ("volume" in dct["result"]): curVol = dct["result"]["volume"] _debug ( "DEBUG: Reset volume to original value" + str(curVol) ) @@ -387,6 +385,9 @@ def __init__(self): _debug ( "DEBUG: DID NOT Reset volume 1 to original value" + str(curVol) ) else: _debug ( "DEBUG: DID NOT Reset volume 2 to original value" + str(curVol) ) + + _debug ( "DEBUG: Stopping... " + str(curVol) ) + xbmc.executebuiltin('PlayerControl(Stop)') if enable_screensaver == 'true': _debug ( "DEBUG: Activating screensaver" )