Skip to content
Closed
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
682 changes: 682 additions & 0 deletions script.service.kodi.callbacks/LICENSE.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions script.service.kodi.callbacks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script.service.kodi.callbacks
=======================
Props to pilluli for initial idea

This is an all new version using a Publisher-Subscriber model.

For usage details, please see the wiki: http://kodi.wiki/view/Add-on:Kodi_Callbacks

Please report problems on the kodi forum at: http://forum.kodi.tv/showthread.php?tid=256170
24 changes: 24 additions & 0 deletions script.service.kodi.callbacks/addon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.service.kodi.callbacks" name="Kodi Callbacks" version="0.9.9" provider-name="KenV99">
<requires>
<import addon="xbmc.python" version="2.19.0"/>
<import addon="script.module.requests" version="2.3.0"/>
</requires>
<extension point="xbmc.service" library="default.py" start="startup">
</extension>
<extension point="xbmc.python.library" library="script.py">
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en">Callbacks for Kodi</summary>
<description lang="en">Provides user definable actions for specific events within Kodi. Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.
</description>
<disclaimer lang="en">For bugs, requests or general questions visit the Kodi forums.</disclaimer>
<platform>all</platform>
<source>https://github.com/KenV99/script.service.kodi.callbacks</source>
<website>http://kodi.wiki/view/Add-on:Kodi_Callbacks</website>
<forum>http://forum.kodi.tv/showthread.php?tid=256170</forum>
<license>GNU GENERAL PUBLIC LICENSE. Version 3, June 2007</license>
<language>en</language>
<email></email>
</extension>
</addon>
67 changes: 67 additions & 0 deletions script.service.kodi.callbacks/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
v0.9.9 (2016-03-22)
Version changed to meet official repo rules

v0.9.8.5 (2016-03-15)
Fixed log bug and testWatchdogStartup bugs

v0.9.8.4 (2016-03-09)
- Added JSON Notify task
- Corrected settings bug where one could not select tasks properly

v0.9.8.3 (2016-03-07)
- Removed github code from master branch

v0.9.8.2 (2016-03-05)
- Refactored settings xml generation
- Made unconfigured tasks unselectable in settings

v0.9.8 (2016-02-26)
- Merged nonrepo branch onto master
- Change xml to be official repo compliant
- Added ability to write settings to log - useful if need to put log on pastebin
- Hide unused tasks and events in settings

v0.9.7.6 (2016-02-22)
- Refactored update, detects paths with spaces

v0.9.7.5 (2016-02-16)
- Fix schedule import

v0.9.7.4 (2016-02-16)
- Added Scheduler publisher to schedule tasks to run daily or at a given interval

v0.9.7.3 (2016-02-15)
- Non-repo version added ability to update from Github

v0.9.7.2 (2016-02-14)
- Added ability to load from zip in settings and backup current

v0.9.7.2 (2016-02-13)
- Implement kodipathtools. Publisher tests passing on Linux, OSX, Windows.

v0.9.7.1 (2016-02-04)
- Android path fix. Added %mt for pause and resume. Changed settings to allow for special// paths.

v0.9.7 (2016-02-03)
- Watchdog startup file change detection added. Several bugs corrected.

v0.9.6 (2016-01-31)
- Publisher and Subscriber Factories. Readied for offical repo submission.

v0.9.5 (2016-01-29)
- Minor changes to onIdle and afterIdle

v0.9.4 (2016-01-27)
- Added after Idle event. Bug fix with string handling from settings.xml

v0.9.3 (2016-01-25)
- Provided string localization and po handling

v0.9.2 (2016-01-22)
- Added basic auth for http, added task testing to settings, bug fixes, removed dependency on service.watchdog

v0.9.1 (2016-01-16)
- Bug fixes, file watchdog added

v0.9.0 (2016-01-12)
- Initial version
167 changes: 167 additions & 0 deletions script.service.kodi.callbacks/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 KenV99
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#


debug = False # TODO: check
testdebug = False # TODO: check
testTasks = False # TODO: check
branch = 'master'
build = '1006'

from resources.lib.utils.debugger import startdebugger

if debug:
startdebugger()

import os
import sys
import threading
import xbmc
import xbmcaddon
import resources.lib.pubsub as PubSub_Threaded
from resources.lib.kodilogging import KodiLogger
from resources.lib.publisherfactory import PublisherFactory
from resources.lib.subscriberfactory import SubscriberFactory
from resources.lib.settings import Settings
from resources.lib.utils.poutil import KodiPo

kodipo = KodiPo()
_ = kodipo.getLocalizedString
log = KodiLogger.log

try:
_addonversion_ = xbmcaddon.Addon().getAddonInfo('version')
except RuntimeError:
try:
_addonversion_ = xbmcaddon.Addon('script.service.kodi.callbacks').getAddonInfo('version')
except RuntimeError:
_addonversion_ = 'ERROR getting version'


class Cache(object):
publishers = None
dispatcher = None


class MainMonitor(xbmc.Monitor):
def __init__(self):
super(MainMonitor, self).__init__()

def onSettingsChanged(self):
log(msg=_('Settings change detected - attempting to restart'))
abortall()
start()


def abortall():
for p in Cache.publishers:
try:
p.abort()
except threading.ThreadError as e:
log(msg=_('Error aborting: %s - Error: %s') % (str(p), str(e)))
Cache.dispatcher.abort()
for p in Cache.publishers:
p.join(0.5)
Cache.dispatcher.join(0.5)
if len(threading.enumerate()) > 1:
main_thread = threading.current_thread()
log(msg=_('Enumerating threads to kill others than main (%i)') % main_thread.ident)
for t in threading.enumerate():
if t is not main_thread and t.is_alive():
log(msg=_('Attempting to kill thread: %i: %s') % (t.ident, t.name))
try:
t.abort(0.5)
except (threading.ThreadError, AttributeError):
log(msg=_('Error killing thread'))
else:
if not t.is_alive():
log(msg=_('Thread killed succesfully'))
else:
log(msg=_('Error killing thread'))


def start():
global log
settings = Settings()
settings.getSettings()
kl = KodiLogger()
if settings.general['elevate_loglevel'] is True:
kl.setLogLevel(xbmc.LOGNOTICE)
else:
kl.setLogLevel(xbmc.LOGDEBUG)
log = kl.log
log(msg=_('Settings read'))
Cache.dispatcher = PubSub_Threaded.Dispatcher(interval=settings.general['TaskFreq'], sleepfxn=xbmc.sleep)
log(msg=_('Dispatcher initialized'))

subscriberfactory = SubscriberFactory(settings, kl)
subscribers = subscriberfactory.createSubscribers()
for subscriber in subscribers:
Cache.dispatcher.addSubscriber(subscriber)
publisherfactory = PublisherFactory(settings, subscriberfactory.topics, Cache.dispatcher, kl, debug)
publisherfactory.createPublishers()
Cache.publishers = publisherfactory.ipublishers

Cache.dispatcher.start()
log(msg=_('Dispatcher started'))

for p in Cache.publishers:
try:
p.start()
except threading.ThreadError:
raise
log(msg=_('Publisher(s) started'))


def main():
xbmc.log(msg=_('$$$ [kodi.callbacks] - Staring kodi.callbacks ver: %s (build %s)') % (str(_addonversion_), build),
level=xbmc.LOGNOTICE)
if branch != 'master':
xbmcaddon.Addon().setSetting('installed branch', branch)
start()
Cache.dispatcher.q_message(PubSub_Threaded.Message(PubSub_Threaded.Topic('onStartup')))
monitor = MainMonitor()
log(msg=_('Entering wait loop'))
monitor.waitForAbort()

# Shutdown tasks
Cache.dispatcher.q_message(PubSub_Threaded.Message(PubSub_Threaded.Topic('onShutdown'), pid=os.getpid()))
log(msg=_('Shutdown started'))
abortall()
log(msg='Shutdown complete')


if __name__ == '__main__':

if testTasks:
KodiLogger.setLogLevel(KodiLogger.LOGNOTICE)
startdebugger()
from resources.lib.tests.testTasks import testTasks

tt = testTasks()
tt.runTests()
else:
if branch != 'master':
try:
from resources.lib.utils.githubtools import processargs
except ImportError:
pass
else:
processargs(sys.argv)
main()
Binary file added script.service.kodi.callbacks/fanart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added script.service.kodi.callbacks/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions script.service.kodi.callbacks/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 KenV99
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
Loading