Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: "on-idle" script runs too often unneccessarily #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
service.xbmc.callbacks
======================

Addon service for XBMC to call user defined scripts on specific callbacks such as player starts, stops, etc.
Addon service for XBMC to call user defined external scripts on specific callbacks such as

* player starts, stops, pauses and resumes;
* screensaver starts, stops;
* XBMC is idle (with timeout and check frequency);
* database gets updated.
29 changes: 22 additions & 7 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This script is based on script.randomitems & script.wacthlist
# Thanks to their original authors
# This script is based on script.randomitems & script.wacthlist &
# service.xbmc.callbacks by pilluli.
# Thanks to their original authors.

import os
import sys
Expand All @@ -34,6 +35,8 @@
script_screensaver_starts = ''
script_screensaver_stops = ''
script_idle = ''
idle_timeout = ''
idle_chk_per = ''
script_db_update = ''

__addon__ = xbmcaddon.Addon()
Expand Down Expand Up @@ -72,6 +75,8 @@ def _init_property(self):
global script_screensaver_starts
global script_screensaver_stops
global script_idle
global idle_timeout
global idle_chk_period
global script_db_update
script_xbmc_starts = xbmc.translatePath(__addon__.getSetting("xbmc_starts"))
script_player_starts = xbmc.translatePath(__addon__.getSetting("player_starts"))
Expand All @@ -81,6 +86,8 @@ def _init_property(self):
script_screensaver_starts = xbmc.translatePath(__addon__.getSetting("screensaver_starts"))
script_screensaver_stops = xbmc.translatePath(__addon__.getSetting("screensaver_stops"))
script_idle = xbmc.translatePath(__addon__.getSetting("xbmc_idle"))
idle_timeout = int(xbmc.translatePath(__addon__.getSetting("idle_timeout")))
idle_chk_period = int(xbmc.translatePath(__addon__.getSetting("idle_chk_period")))
script_db_update = xbmc.translatePath(__addon__.getSetting("db_update"))
log('script xbmc starts = "' + script_xbmc_starts + '"')
log('script player starts = "' + script_player_starts + '"')
Expand All @@ -90,24 +97,32 @@ def _init_property(self):
log('script screensaver starts = "' + script_screensaver_starts + '"')
log('script screensaver stops = "' + script_screensaver_stops + '"')
log('script idle = "' + script_idle + '"')
log('idle timeout = "' + str(idle_timeout) + '"')
log('idle check period = "' + str(idle_chk_period) + '"')
log('db update = "' + script_db_update + '"')

def _player_status(self):
return self.Player.playing_status()

def _daemon(self):
global script_idle
global idle_timeout
global idle_chk_period
cntr = 0
while (not xbmc.abortRequested):
# Do nothing
global script_idle
if script_idle:
if xbmc.getGlobalIdleTime() > 60 * __addon__.getSetting("idle_time"):
log('XBMC is idle')
log('Going to execute script = "' + script_idle + '"')
if xbmc.getGlobalIdleTime() > 60 * idle_timeout and cntr >= 60 * idle_chk_period:
log('XBMC is idle. Going to execute script = "' + script_idle + '"')
try:
subprocess.call(script_idle)
except:
log('ERROR executing script when xbmc goes idle')
xbmc.sleep(4000)
cntr = 0
# Increase counter for the sleep period in seconds
cntr = cntr + 2
# Keep the sleep period short so that XBMC can quit quickly if needed
xbmc.sleep(2 * 1000)
log('abort requested')


Expand Down
4 changes: 4 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ msgstr ""
msgctxt "#32020"
msgid "Database updated"
msgstr ""

msgctxt "#32021"
msgid "Idle check period (minutes)"
msgstr ""
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<setting label="32017" type="executable" id="screensaver_stops"/>
<setting label="32018" type="executable" id="xbmc_idle"/>
<setting label="32019" type="slider" id="idle_time" default="10" range="1,1,60" option="int" />
<setting label="32021" type="slider" id="idle_chk_period" default="1" range="1,1,10" option="int" />
<setting label="32020" type="executable" id="db_update"/>
</category>
</settings>