Kodi Community Forum

Full Version: Execute user tasks for Kodi events (callbacks ver2)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
(2016-03-10, 12:12)bigbadrabbit Wrote: [ -> ]
(2016-03-09, 22:00)KenV99 Wrote: [ -> ]%mt

This returns music|pvr|movie|episode|stream|unknown

So in your script when you process the command line arguments you would execute only if the argument is equal to movie or episode.

Thanks. I simply have zero experience with such arguments in scripts. All of my scripts are simple Applescripts which get called from within the bash via oascript:
Code:
#!/bin/bash

/usr/bin/osascript <<-EOF

tell application "AirServer" to stop broadcast
do shell script "curl http://192.168.0.20/goform/formiPhoneAppDirect.xml?PSDYNVOL%20OFF"

tell application "iTunes"
    pause
end tell

tell application "Hue Server" to run command "Wohnzimmer Off"
tell application "AirServer" to start broadcast
EOF

Could you please tell me WHERE i'd need to put in the proper argument to filter out movie or episode? Many thanks again!

Can't test it directly but google 'bash command line arguments' to read up ($1)
Code:
#!/bin/bash

if test -z "$1"
then
if ["$1" != "stream"] && ["$1" != "pvr"] && ["$1" != "music"]
then

/usr/bin/osascript <<-EOF

tell application "AirServer" to stop broadcast
do shell script "curl http://192.168.0.20/goform/formiPhoneAppDirect.xml?PSDYNVOL%20OFF"

tell application "iTunes"
    pause
end tell

tell application "Hue Server" to run command "Wohnzimmer Off"
tell application "AirServer" to start broadcast
EOF

fi
fi

might work
No, it won't work that way. And sadly this is all beyond my understanding.
So i'll stick with what i've have so far.

Thanks anyway, KenV99!
So do this:
1) Using script editor save the following as TEXT:
Code:
#! /usr/bin/osascript
on run (arguments)
    if (first item of arguments) is not equal to "pvr" and (first item of arguments) is not equal to "music" and (first item of arguments) is not equal to "stream" then    
        tell application "AirServer" to stop broadcast
        do shell script "curl http://192.168.0.20/goform/formiPhoneAppDirect.xml?PSDYNVOL%20OFF"

        tell application "iTunes"
            pause
        end tell

        tell application "Hue Server" to run command "Wohnzimmer Off"
        tell application "AirServer" to start broadcast
    end if
end run

2) Use terminal to go to the directory wherever you saved the above and chmod +x the file.
3) In the addon, in tasks, first browse and find the above file and then edit the line putting osascript before the filename (i.e. osascript /Users/kenv99/Desktop/test.applescript
4) Make sure use shell is NOT on. Click OK.
5) Under events use onPlaybackStarted and in the var subbed arg put %mt
6) Click OK and then test.

Since I don't have all of the things you're calling installed I tested it with this:
Code:
#! /usr/bin/osascript
on run (arguments)
    display dialog (first item of arguments)
end run
KenV99, thanks so much for you help! I really appreciate! Gonna try this.

EDIT:
It works partially! It filters out music and streams but sadly not PVR. I'm using a custom PVR-addon (see here) that's not in the official Kodi repo (nothing illegal here!).

But that shouldn't be the problem, right?
(2016-03-12, 00:41)bigbadrabbit Wrote: [ -> ]KenV99, thanks so much for you help! I really appreciate! Gonna try this.

EDIT:
It works partially! It filters out music and streams but sadly not PVR. I'm using a custom PVR-addon (see here) that's not in the official Kodi repo (nothing illegal here!).

But that shouldn't be the problem, right?

Well, the addon detects that it is playing a pvr file because Kodi prefixes those files with 'pvr' in the filename. You may want to try to see if the filenames that are associated with that addon have something unique about them or are in a specific directory and use the %fn as a second argument to the script and filter on that as well.
I pushed a new update to both branches which fixes a bug for the log Publisher that seems to only have affected linux users.
I also added a JSON notification task. This sends a notification to the Kodi JSON RPC server which is then broadcast to any sockets that are listening. There are no userargs for this as it sends all data that is normally collected along with the notification.

Other services can listen in python by subclassing xbmc.Monitor. If you want to receive notifications via python independent from Kodi, the easiest way seems to be using Websockets. I successfully implemented using autobahn and trollius (http://autobahn.ws/python).
Code:
from autobahn.asyncio.websocket import WebSocketClientProtocol

class MyClientProtocol(WebSocketClientProtocol):

   def onOpen(self):
      pass
      # self.sendMessage(u"Hello, world!".encode('utf8'))

   def onMessage(self, payload, isBinary):
      if isBinary:
         print("Binary message received: {0} bytes".format(len(payload)))
      else:
         print("Text message received: {0}".format(payload.decode('utf8')))

if __name__ == '__main__':

   try:
      import asyncio
   except ImportError:
      ## Trollius >= 0.3 was renamed
      import trollius as asyncio

   from autobahn.asyncio.websocket import WebSocketClientFactory
   factory = WebSocketClientFactory()
   factory.protocol = MyClientProtocol

   loop = asyncio.get_event_loop()
   coro = loop.create_connection(factory, '127.0.0.1', 9999)
   loop.run_until_complete(coro)
   loop.run_forever()
   loop.close()

New version can be downloaded here:

repo branch: https://github.com/KenV99/script.service...master.zip
nonrepo branch: https://github.com/KenV99/script.service...onrepo.zip
(2016-03-13, 17:32)KenV99 Wrote: [ -> ]Well, the addon detects that it is playing a pvr file because Kodi prefixes those files with 'pvr' in the filename. You may want to try to see if the filenames that are associated with that addon have something unique about them or are in a specific directory and use the %fn as a second argument to the script and filter on that as well.

Well, as you may have guessed, i'm stuck here again.

The log shows nothing unusual as far as i can see. I tried it with the channel "Das Erste HD".
Maybe you could have a quick look at the log, you'd definitely find the "error" if there was some.

I really also completely understand if you won't do that ;-)
Anyway thanks again for your help!
1) Make sure you are using the latest from Github, either branch.
2) Unless you really need it, I would turn debug off.
3) Create an event 'onLogSimple' using 'matchIf':
Code:
DVDPlayer: Opening: pvr://

You can use the same Task. Just set the userargs to the static string 'pvr'.
Hi KenV99,

ever since the major changes in the addon (that you posted on 02/27) Callbacks is not running correctly anymore on all my three Shield TV boxes (Android TV). Tasks do not seem to be executed. I reverted back to version 0.9.7.4 which is doing fine for me and hoped for the bug being fixed with a later release. Now that you announced the new version will go to the official repo I gave it another try but the bug is still there. No tasks are executed on my Shield boxes. I tried regenerating the settings.xml through the addon, but it did not help either.

Here is the log: http://xbmclogs.com/pyreueoxy

Btw.: Changelog says 0.9.9 was created (2015-03-22), but it surely was 2016 ;-)

Regards,

FantasticN
(2016-03-23, 10:12)fantasticn Wrote: [ -> ]Hi KenV99,

ever since the major changes in the addon (that you posted on 02/27) Callbacks is not running correctly anymore on all my three Shield TV boxes (Android TV). Tasks do not seem to be executed. I reverted back to version 0.9.7.4 which is doing fine for me and hoped for the bug being fixed with a later release. Now that you announced the new version will go to the official repo I gave it another try but the bug is still there. No tasks are executed on my Shield boxes. I tried regenerating the settings.xml through the addon, but it did not help either.

Here is the log: http://xbmclogs.com/pyreueoxy

Btw.: Changelog says 0.9.9 was created (2015-03-22), but it surely was 2016 ;-)

Regards,

FantasticN
Yes, thx for catching the date error.

I think most likely the issue is that there was a major change in the way the settings are read.
Please note what your current settings are and then clear your settings by hitting default.
Then hit ok and try to rebuild from scratch.

Regenerating the settings is something completely different - only for developers. It looks to see if you have placed a python file that creates a new task type that requires settings and rewrites the settings config file.
Using a previous version I already tried that with no success. But following your advice I tried it again with the current version and now it worked. Thanks again for your help and for the nice addon!
Just so you all know, I am *trying* to get it into the repo.
Whether or not it gets accepted is still to be determined.
Anyone interested - look here: https://github.com/xbmc/repo-scripts/pull/70
Updating to the latest repo / nonrepo version broke everything on my Mac...
Now it just displays an error message on startup.

Please tell me what specific logs you need. Thanks.
(2016-03-24, 16:22)bigbadrabbit Wrote: [ -> ]Updating to the latest repo / nonrepo version broke everything on my Mac...
Now it just displays an error message on startup.

Please tell me what specific logs you need. Thanks.

It's passing all tests on my OSX VM.
Try updating to the most recent from the repo, if that doesn't help then:

First try noting your settings and then clicking default, OK and then rebuilding your settings.

If that doesn't work, it's always the same. There is only one log - kodi.log.
See: http://kodi.wiki/view/Add-on:Kodi_Callbacks#FAQs
Hi.
Ran across your add-on and thought I'd give it a try. I seem to be having problems after spending a couple hours trying to config.

My goal is to enable Windows 10 Stereoscopic mode when playing back a 3D.iso and disable it when finished with playback.
I have working .bat files to enable and disable using Nvidia's nvstlink.exe.
I point to these .bat files using your player start and player end tasks and they indeed switch using Script as the type.
The problems are:

Stereoscopic MUST be enabled before playback actually begins. This bat has to take priority before KODI itself does otherwise KODI starts 3D mode switching incorrectly. I assume there is no way around this since the title has to be called 1st to trigger the add-on after numerous tries?

I've added "*3D.iso" to the variable but stereoscopic switches into 3D upon start of a 2D.mkv which makes no sense to me but I'm not a coder.
Can you help me achieve what I'm trying to do?

I'm on W10 using a variant of v.17 (afedchin's new 3D MVC build in the development thread)

This workaround may help Nvidia users be included in the upcoming KODI 3D MVC advancement and I'm eager to test if it can be accomplished.
Thanks for any assistance the community might offer.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21