Release - Execute user tasks for Kodi events (callbacks ver2)

  Thread Rating:
  • 3 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
adamioan Offline
Junior Member
Posts: 1
Joined: Dec 2016
Reputation: 0
Post: #181
Hello, I admire your work. Keep it going!
I use Windows 7 box and I have created an event on Playback Started.
This triggers a Http request to my remote server.
Everything works fine when I play a local video.
If I use YouTube addon to stream a video, task is being triggered only when its type is script -> Windows batch file.
When I set Task as PYTHON or HTTP, its not working.
This occurs only when the video is YouTube stream.
Any suggestions?

Thank you in advance
find quote
AndreaRaise Offline
Junior Member
Posts: 1
Joined: Dec 2016
Reputation: 0
Post: #182
Hi,

Im running Kodi on my Nas QNAP, on the same machine i have a torrent client, what im trying to do is to start/stop the torrent files when Kodi's playback start/stop.

If i use the command "transmission-remote -tall --stop" through SSH it works and all my torrents stop, so what i tried to do is to create a file start.sh with this code
Code:
#!/bin/sh
transmission-remote -n "admin:admin" -tall --stop
but when i try "Test Command" i got an error "transmission-remote command not found

Any help? Thanks
find quote
thegreatcow Offline
Junior Member
Posts: 16
Joined: Sep 2016
Reputation: 0
Post: #183
Hi I was hoping someone here can help me with something that might be simple. I am trying to run a script for background music within Kodi and I am putting in this string #!/bin/sh kodi-send -a "PlayMedia(/sdcard/music.mp3)"; I put it under "var subbed arg string" Did I enter that correctly or did I miss a step? Thanks for anyones input on this.
(This post was last modified: 2016-12-28 01:04 by thegreatcow.)
find quote
musteh Offline
Junior Member
Posts: 1
Joined: Jan 2017
Reputation: 0
Post: #184
Thanks a lot KenV99 for this, it's an absolute blinder and will help me a lot towards automating the lights in my room!

I have a scenario that I don't think is catered for (I'll happily be corrected) : I'm planning on using this to turn lights off and on to complement pause / play / stop / resume working in conjunction with eventghost and uirt, but my lights do not have separate "off" and "on" IR patterns, only a toggle.

Is there any way a "Paused Stopped" event could be captured so that if you play (lights off) then pause (lights on) then stop (lights off) the lights are not toggled when a paused film is stopped?
It's not going to be common, but I can see it happening and causing the lights to get out of sequence.

Thanks a lot
(This post was last modified: 2017-01-12 18:47 by musteh.)
find quote
unnamed777 Offline
Junior Member
Posts: 1
Joined: Jan 2017
Reputation: 0
Post: #185
I've installed the addon on SPMC 16 (fork of kodi for android) but it doesn't work properly. When I tested my task, I got an error. Log file said that addons was using wrong directory: default for kodi instead of spmc path:
Code:
Could not locate po at  /sdcard/Android/data/org.xbmc.kodi/files/.kodi/addons/script.service.kodi.callbacks/resources/language/English/strings.po

I tried to fix it by editing files ./resources/lib/utils/kodipathtools.py and ./resources/lib/utils/poutil.py, but I still get the same error with correct path:
Code:
17:52:45.656 T:18446744072992061744  NOTICE: Could not locate po at  /sdcard/Android/data/com.semperpax.spmc16/files/.spmc/addons/script.service.kodi.callbacks/resources/language/English/strings.po
17:52:50.764 T:18446744072992061744  NOTICE: $$$ [kodi.callbacks] - Running Test for Event: E1
17:52:53.206 T:18446744072992061744   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.AttributeError'>
                                            Error Contents: 'TestLogger' object has no attribute 'LOGERROR'
                                            Traceback (most recent call last):
                                              File "/storage/emulated/0/Android/data/com.semperpax.spmc16/files/.spmc/addons/script.service.kodi.callbacks/script.py", line 182, in <module>
                                                test(eventId)
                                              File "/storage/emulated/0/Android/data/com.semperpax.spmc16/files/.spmc/addons/script.service.kodi.callbacks/script.py", line 69, in test
                                                subscriber = subscriberfactory.createSubscriber(key)
                                              File "/storage/emulated/0/Android/data/com.semperpax.spmc16/files/.spmc/addons/script.service.kodi.callbacks/resources/lib/subscriberfactory.py", line 74, in createSubscriber
                                                self.logger.log(loglevel=self.logger.LOGERROR,
                                            AttributeError: 'TestLogger' object has no attribute 'LOGERROR'
                                            -->End of Python script error report<--

File /sdcard/Android/data/com.semperpax.spmc16/files/.spmc/addons/script.service.kodi.callbacks/resources/language/English/strings.po exists and it looks like the addon has permission to read it.

What else can I modify to make addon working?
find quote
tomatosoup Offline
Junior Member
Posts: 29
Joined: Dec 2010
Reputation: 0
Post: #186
Is there a reference list that shows what events are actually caused by? I want to pause at the beginning of each video in a playlist so I don't keep sleeping through videos, but I don't know which playback event would be the one to call the trigger from. I see onQueueNextItem which seems like it may be correct, but I have no way of knowing for sure.
find quote
WEHA Offline
Junior Member
Posts: 1
Joined: Feb 2017
Reputation: 0
Post: #187
Would it be possible to have hooks on volume up and down?
What I want to achieve is to be able to control an external IR to change the volume on my receiver when passthrough is active.
find quote
gkoper Offline
Junior Member
Posts: 6
Joined: Jan 2017
Reputation: 0
Post: #188
Currently running Kodi 16 with LibreELEC 7.0.3 and installed the latest callback add-on. (But same on OpenElec).
Made simple python scripts to switch the RPi3 touchscreen on and off.
This works wonderfully with onScreensaverActivated and onScreensaverDeactivated. Also in the log files the calls are filed.
Unfortunately not for onShutdown, even if I add a delay to allow the deamon to do its thing. No entry in the log file.
With debug on, the script gets activated but "interrupted". No positive effect either.

Any help?
(This post was last modified: 2017-02-05 17:24 by gkoper.)
find quote
cogano Offline
Junior Member
Posts: 19
Joined: Sep 2014
Reputation: 0
Post: #189
Hi,
I use Kodi 16.1, Callbacks 1.0.0. from repo, Lubuntu 16.04 x86_64.

When testing the Callbacks, the error is:

Code:
07:27:43 T:140713899562752   ERROR: $$$ [kodi.callbacks] - Testing for task type: script
                                            Settings: {u'use_shell': True, 'notify': True, u'scriptfile': u'/bin/bash', 'taskid': u'T1',
'userargs': u'', 'type': u'script', u'waitForCompletion': True}
                                            Runtime kwargs: {}
                                            ERROR encountered for Task , Event onIdle:E1
                                            ERROR mesage: <attribute 'message' of 'exceptions.BaseException' objects>
07:27:43 T:140713899562752 WARNING: CSkinInfo: failed to load skin settings                                            
07:28:21 T:140714040039168  NOTICE: $$$ [kodi.callbacks] - Task starting for onIdle:E1                                  
07:28:21 T:140714040039168  NOTICE: $$$ [kodi.callbacks] - Command for Task T1, Event onIdle:E1 completed succesfully!  
                                            The following message was returned: taskScript ARGS = bash                  
                                                SYSEXEC = None                                                          
                                             BASEDIR = /bin                                                            
                                            Process returned no data                                                    
07:28:21 T:140714040039168  NOTICE: $$$ [kodi.callbacks] - Task finalized for onIdle:E1

No matter what Task & Event I test, the error is similar (and it is displayed also on the screen).

EDIT: Sorry. I reinstalled from github, reset settings and the error disappeared. Not sure what went wrong earlier, it was a clean install...
(This post was last modified: 2017-02-14 09:21 by cogano.)
find quote
goldpizza44 Offline
Junior Member
Posts: 1
Joined: Feb 2017
Reputation: 0
Post: #190
Hi,

I installed this addon in libreelec (v7.0.0 -- kodi 16.1) so that I can turn off the TV and sound system when a screensaver starts and turn them back on when the screensaver deactivates.

I created a small /bin/bash script that uses cec-client to do the turnon/turnoff, and setup the kodi callbacks service to call these scripts from /storage/bin/tvoff and /storage/bin/tvon.

It appears that the python subprocess software is doing the equivalent of:

Code:
cd /storage/bin
tvon
The error in the log was:

Code:
2:29:34 T:546819797216  NOTICE: $$$ [kodi.callbacks] - Testing for task type: script
                                            Settings: {u'use_shell': True, 'notify': True, u'scriptfile': u'/storage/bin/tvon', 'taskid': u'T2', 'userargs': u'', 'type': u'script', u'waitForCompletion': True}
                                            Runtime kwargs: {}
                                            Command for Task T2, Event onScreensaverDeactivated completed succesfully!
                                            The following message was returned: taskScript ARGS = tvon
                                                SYSEXEC = None
                                             BASEDIR = /storage/bin
                                            Process returned data: [/bin/sh: tvon: not found]
12:29:34 T:546819797216 WARNING: CSkinInfo: failed to load skin settings

I eventually resolved it by looking at the ENVIRON for the kodi.bin process (tr '\000' '\012' < /proc/XXXX/environ) and finding a directory in the $PATH. Moving the scripts to

Code:
/storage/.kodi/addons/virtual.network-tools/bin/tvon
/storage/.kodi/addons/virtual.network-tools/bin/tvoff

Solves the issue for me.

I am thinking that "basedir" needs to be added to the end of the $PATH variable somehow in the environment of the subprocess when running a shell process. LibreElec only has one writable directory in the $PATH. The other directories (/usr/bin:/usr/sbin, etc) are all on a Read Only filesystem.

In any case it is now working great for me...I can walk away from the TV and be confident it won't stay on all night.

Thanks!
find quote
bigbadrabbit Offline
Senior Member
Posts: 264
Joined: Sep 2008
Reputation: 2
Location: Austria
Post: #191
I'm using the onStereoModeChange event to trigger a script that switches my projector to 3D mode. Works as expected - movie starts; Kodi detects 3D file and changes to stereoscopic mode; Callbacks addon triggers my script.

The problem is that there're no onStereoModeSTART or onStereoModeEND events available.

I need to run another script (onPlayBackEnded) to switch the projector back to 2D when the player stops. Kodi is also set to change to 2D once playback ends.

So right now when the movie ends - onPlayBackEnds triggers the script to switch projector to 2D; but simultaneously onStereoModeChange also triggers the "switch projector to 3D"-script again.

Is there another way to prevent this behavior?

Kodi Krypton
macOS Sierra 10.12
Mac mini (late 2012)
find quote
KenV99 Offline
Fan
Posts: 507
Joined: Nov 2013
Reputation: 28
Post: #192
(2017-03-11 18:47)bigbadrabbit Wrote:  I'm using the onStereoModeChange event to trigger a script that switches my projector to 3D mode. Works as expected - movie starts; Kodi detects 3D file and changes to stereoscopic mode; Callbacks addon triggers my script.

The problem is that there're no onStereoModeSTART or onStereoModeEND events available.

I need to run another script (onPlayBackEnded) to switch the projector back to 2D when the player stops. Kodi is also set to change to 2D once playback ends.

So right now when the movie ends - onPlayBackEnds triggers the script to switch projector to 2D; but simultaneously onStereoModeChange also triggers the "switch projector to 3D"-script again.

Is there another way to prevent this behavior?

The way to do this is to pass the variable 'stereoMode' to your script and then use a conditional to run one bit of code if it is a 3D mode and another bit if it is not...

Note: the last time I looked into the possible modes they were:
"off", "split_vertical", "split_horizontal", "row_interleaved", "hardware_based", "anaglyph_cyan_red", "anaglyph_green_magenta", "monoscopic"
(This post was last modified: 2017-03-12 16:03 by KenV99.)
find quote
D0nuts Offline
Junior Member
Posts: 1
Joined: Apr 2017
Reputation: 0
Question  RE: Execute user tasks for Kodi events (callbacks ver2)
Post: #193
Hello,

Thank you for this add-on. I'm runningKodi on Linux and want to create a bash script so my files are moved after playback.
I first thought it was really easy to write, this might be why it doesn't work... tried on my own and read the 13 pages before asking for help.
Code:
#!/bin/bash
# selected event: onPlayBackEnded

mv $1 /home/lukas/done/

echo $1 moved

Thanks
(This post was last modified: 2017-04-02 11:42 by D0nuts.)
find quote
stephr1 Offline
Junior Member
Posts: 23
Joined: Aug 2016
Reputation: 0
Post: #194
@KenV99

Thank you for your efforts!! I haven't started using it yet, but have a need for an event that isn't obviously available...

Running OSMC/RPI 3. Have a HDHomeRun dual tuner connected (thru the network) and would like to be able to turn on an LED (1 for each tuner channel) when a recording is happening, and off when it isn't (or recording is finished).

Does that exist in your addon (thought "onDailyAlarm" or "onIntervalAlarm" might be the answer, but not sure either would work the way I'd like it to), is there a combination of events I could use, or am I on my own here....

Thanks in advance....
(This post was last modified: 2017-04-21 17:42 by stephr1.)
find quote
stephr1 Offline
Junior Member
Posts: 23
Joined: Aug 2016
Reputation: 0
Post: #195
BUMP!! Anyone offer any help here? Thx....

(2017-04-20 16:37)stephr1 Wrote:  @KenV99

Thank you for your efforts!! I haven't started using it yet, but have a need for an event that isn't obviously available...

Running OSMC/RPI 3. Have a HDHomeRun dual tuner connected (thru the network) and would like to be able to turn on an LED (1 for each tuner channel) when a recording is happening, and off when it isn't (or recording is finished).

Does that exist in your addon (thought "onDailyAlarm" or "onIntervalAlarm" might be the answer, but not sure either would work the way I'd like it to), is there a combination of events I could use, or am I on my own here....

Thanks in advance....
find quote
Post Reply