• 1
  • 16
  • 17
  • 18(current)
  • 19
  • 20
  • 23
[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)
(2015-07-27, 08:35)armaster Wrote:
(2015-07-24, 14:11)KenV99 Wrote: This, almost always, is a permissions issue.
But as has been mentioned OVER AND OVER on the forums, if you don't post your kodi.log to pastebin and put a link, it's pretty much impossible to provide useful help.

Here is my log: http://xbmclogs.com/pvfhmd9zj .

If I run script from shell it works. Thanks fro your reply.
What script are you trying to run?
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
(2015-07-27, 08:49)nickr Wrote:
(2015-07-27, 08:35)armaster Wrote:
(2015-07-24, 14:11)KenV99 Wrote: This, almost always, is a permissions issue.
But as has been mentioned OVER AND OVER on the forums, if you don't post your kodi.log to pastebin and put a link, it's pretty much impossible to provide useful help.

Here is my log: http://xbmclogs.com/pvfhmd9zj .

If I run script from shell it works. Thanks fro your reply.
What script are you trying to run?

This is the content of my bash script:

Code:
echo $(date) "starting irexec..." >  /home/osmc/temp_rc
sudo kill $(ps aux | grep '[l]ircd-lirc0' | awk '{print $2}')
sudo /usr/sbin/lircd --driver=default --device=/dev/lirc0 --uinput --output=/var/run/lirc/lircd --pidfile=/var/run/lirc/lircd.pid /home/osmc/lircd.conf
sudo irexec -d /home/osmc/.lircrc
echo $(date) "irexec started." >>  /home/osmc/temp_rc
Reply
(2015-07-27, 09:00)armaster Wrote:
(2015-07-27, 08:49)nickr Wrote:
(2015-07-27, 08:35)armaster Wrote: Here is my log: http://xbmclogs.com/pvfhmd9zj .

If I run script from shell it works. Thanks fro your reply.
What script are you trying to run?

This is the content of my bash script:

Code:
echo $(date) "starting irexec..." >  /home/osmc/temp_rc
sudo kill $(ps aux | grep '[l]ircd-lirc0' | awk '{print $2}')
sudo /usr/sbin/lircd --driver=default --device=/dev/lirc0 --uinput --output=/var/run/lirc/lircd --pidfile=/var/run/lirc/lircd.pid /home/osmc/lircd.conf
sudo irexec -d /home/osmc/.lircrc
echo $(date) "irexec started." >>  /home/osmc/temp_rc

I figured out. Forgot to add #!/bin/bash at the top of my script. Sorry to bother you and thanks for your help.
Reply
(2015-07-27, 07:05)MPRESTON81 Wrote: Hi everyone, new comer from the MCE world, and have been very impressed with kodi and how I can integrate it with my home automation.

Couple of quick questions though.

I know nothing of python but have cobbled together a few scripts that seem to be working for my lighting needs that can differentiate between night and day. BUT FOR THE LIFE OF ME I CANNOT GET RESUME TO WORK!!!! I was up until 4am the other night trying to make it do what I wanted.

Does kodi pass a media type argument on resume? After the amount of time I have spent on this I'm thinking its a no.

Basically when I watch a movie at night and I pause the lights behind my couch turn on. When I resume my hope would be that for a movie the light would turn back off, whereas for just regular tv watching I want all my lights to stay on. Which it currently doesn't do no matter what arguments I set.

Code:
import xbmc
import urllib2
import datetime


DAY, NIGHT = 1, 2
def check_time(time_to_check, on_time, off_time):
    if on_time > off_time:
        if time_to_check > on_time or time_to_check < off_time:
            return NIGHT, True
    elif on_time > off_time:
        if time_to_check > on_time and time_to_check < off_time:
            return DAY, True
    elif time_to_check == on_time:
        return None, True
    return None, False


on_time = datetime.time(18,00)
off_time = datetime.time(04,00)
timenow = datetime.datetime.now().time()
current_time = datetime.datetime.now().time()

when, matching = check_time(current_time, on_time, off_time)

if matching:
    if when == NIGHT:

    if 'movie' in sys.argv[1]:
        urllib2.urlopen('insert lighting url here')

    if 'episode' in sys.argv[1]:
            urllib2.urlopen('insert lighting url here')
            urllib2.urlopen('insert lighting url here')

Thanks in advance for any help or pointers offered.

So that I understand this completely, you are triggering the above code via XBMC.Callbacks2?
If so, then that is correct, the script does not pass parameters out during onPlayBackResume, only during onPlayBackStarted.

You could trying getting the type yourself in your script by subclassing xbmc.player and then sorting it out (see lines 223-260 in default.py).
The number of places that parameters are provided is limited because the settings interface becomes very tedious and cluttered (it already is).

Otherwise you could paste this over line 349 in default.py, implementing the same code as for playbackstarted:

Code:
...
        runtimeargs = []
        if __options__['arg_mediatype']:
            t = self.playing_type()
            if t is None:
                t = 'unknown'
            runtimeargs.append('type=' + t)
        if __options__['arg_filename']:
            runtimeargs.append('file=' + self.getPlayingFileEx())
        if __options__['arg_title']:
            runtimeargs.append('title=' + self.getTitle())
        if self.isPlayingVideo():
            if __options__['arg_aspectratio']:
                runtimeargs.append('aspectratio=' + self.getAspectRatio())
            if __options__['arg_resolution']:
                runtimeargs.append('resolution=' + self.getResoluion())
        self.dispatcher.dispatch('onPlaybackResumed', runtimeargs)
Reply
Thanks for the quick response KenV99!

Yeah, sorry it was getting late, I am using your callbacks 2 which is fantastic btw.

What I posted is what I am currently using, I had meant to post what I was trying to use.

I'll go out and try your suggestions to see if I can get them to work and report back. How'd code look otherwise? Any suggestions to clean it up?
Reply
(2015-07-27, 14:28)MPRESTON81 Wrote: Thanks for the quick response KenV99!

Yeah, sorry it was getting late, I am using your callbacks 2 which is fantastic btw.

What I posted is what I am currently using, I had meant to post what I was trying to use.

I'll go out and try your suggestions to see if I can get them to work and report back. How'd code look otherwise? Any suggestions to clean it up?

There are a million ways to skin a cat. If the code is doing what you want, then it is fine.
Let me know how you make out.
Reply
I was able to find some other code to shrink down my script complexity. But even with KenV99's cut and paste over line 349 in default.py; resume is still not working as desired. i.e. when I hit pause and then resume while watching a movie the light behind the couch stays on as if its not receiving the movie argument.

In advance I appreciate all the help you guys offer.

note the start time is set so early just for testing purposes.

Code:
import xbmc
import urllib2
import datetime
import sys

from datetime import datetime, time
now = datetime.now()
now_time = now.time()

if time(10,00) <= now.time() <= time(22,30):        
    if 'movie' in sys.argv[1]:
        urllib2.urlopen('url for dining room light off goes')
        urllib2.urlopen('url living room light goes off here')
Reply
It's working fine for me. Send some info to the log so you can check if it is executing as expected:
Code:
import xbmc
import urllib2
import datetime
import sys

from datetime import datetime, time
now = datetime.now()
now_time = now.time()
xbmc.log('#### onPlaybackResumed: sys.argv[1] = %s' % sys.argv[1])

if time(10,00) <= now.time() <= time(22,30):        
    if 'movie' in sys.argv[1]:
        urllib2.urlopen('url for dining room light off goes')
        urllib2.urlopen('url living room light goes off here')
        xbmc.log('#### onPlaybackResumed: movie lights off')
    else:
        xbmc.log('#### onPlaybackResumed: not a movie')
else:
    xbmc.log('#### onPlaybackResumed: not time')
Reply
It looks like whenever I hit play again after pause its calling my movie_play.py. I'll tinker some more and see if I can sort it out. I'm learning allot though. I suspect I may need to tinker with the cut and paste?
Reply
Here is the dump from my log. Hopefully it will be more helpful to one of you guys. For some reason it's not calling my movie_resume.py sript.[/quote]

Code:
18:48:01 T:4592    INFO: Loading skin file: VideoFullScreen.xml, load type: KEEP_IN_MEMORY
18:48:01 T:5104  NOTICE: -->Python Interpreter Initialized<--
18:48:01 T:5104   DEBUG: CPythonInvoker(13, C:\Program Files (x86)\Kodi\userdata\Movie_Play.py): the source file to load is "C:\Program Files (x86)\Kodi\userdata\Movie_Play.py"
18:48:01 T:5104 WARNING: CPythonInvoker(13): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
18:48:01 T:5104   DEBUG: CPythonInvoker(13, C:\Program Files (x86)\Kodi\userdata\Movie_Play.py): setting the Python path to C:\Program Files (x86)\Kodi\userdata;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.simplejson\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.beautifulsoup4\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.myconnpy\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.httplib2\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.addon.common-master\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.pyxbmct\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.beautifulsoup\lib;C:\Program Files (x86)\Kodi\addons\script.module.pil\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.common.plugin.cache\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.unidecode\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.simple.downloader\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.requests\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.pyxbmctmanager\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.hubparentalcontrol\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.parsedom\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.xbmcswift2\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.requests2-frodo\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.feedparser\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.metahandler\lib;C:\Program Files (x86)\Kodi\system\python\DLLs;C:\Program Files (x86)\Kodi\system\python\Lib;C:\Program Files (x86)\Kodi\python27.zip;C:\Program Files (x86)\Kodi\system\python\lib\plat-win;C:\Program Files (x86)\Kodi\system\python\lib\lib-tk;C:\Program Files (x86)\Kodi;C:\Program Files (x86)\Kodi\system\python;C:\Program Files (x86)\Kodi\system\python\lib\site-packages
18:48:01 T:4592   DEBUG: ------ Window Deinit (VideoOverlay.xml) ------
18:48:01 T:5104   DEBUG: CPythonInvoker(13, C:\Program Files (x86)\Kodi\userdata\Movie_Play.py): entering source directory C:\Program Files (x86)\Kodi\userdata
18:48:01 T:4592   DEBUG: ------ Window Init (VideoOSD.xml) ------
18:48:01 T:4592    INFO: Loading skin file: VideoOSD.xml, load type: KEEP_IN_MEMORY
18:48:01 T:4592   DEBUG: ------ Window Init (DialogSeekBar.xml) ------
18:48:01 T:4744   DEBUG: CActiveAESink::OpenSink - trying to open device WASAPI:{DFA4D7D2-03E8-4FA0-9940-F41F193D2392}
18:48:01 T:4744    INFO: CAESinkWASAPI::InitializeExclusive: Format is Supported - will attempt to Initialize
18:48:01 T:4744    INFO: CAESinkWASAPI::InitializeExclusive: WASAPI Exclusive Mode Sink Initialized using: AE_FMT_S16NE, 48000, 2
18:48:01 T:4744   DEBUG: CActiveAESink::OpenSink - WASAPI Initialized:
18:48:01 T:4744   DEBUG:   Output Device : HDMI - VSX-42-4 (NVIDIA High Definition Audio)
18:48:01 T:4744   DEBUG:   Sample Rate   : 48000
18:48:01 T:4744   DEBUG:   Sample Format : AE_FMT_S16NE
18:48:01 T:4744   DEBUG:   Channel Count : 2
18:48:01 T:4744   DEBUG:   Channel Layout: FL,FR
18:48:01 T:4744   DEBUG:   Frames        : 2400
18:48:01 T:4744   DEBUG:   Frame Samples : 4800
18:48:01 T:4744   DEBUG:   Frame Size    : 4
18:48:01 T:1388   DEBUG: CActiveAE::ClearDiscardedBuffers - buffer pool deleted
18:48:01 T:3900   DEBUG: Previous line repeats 1 times.
18:48:01 T:3900   DEBUG: CDVDClock::Discontinuity - CDVDPlayerAudio::HandleSyncError1 - was:78286.483073, should be:10594.336377, error:-67692.146696
18:48:01 T:2096   DEBUG: CDVDPlayer::HandleMessages - player started 1
18:48:01 T:5104    INFO: CPythonInvoker(13, C:\Program Files (x86)\Kodi\userdata\Movie_Play.py): script successfully run
18:48:01 T:5104    INFO: Python script stopped
18:48:01 T:5104   DEBUG: Thread LanguageInvoker 5104 terminating
18:48:01 T:3900   DEBUG: CDVDClock::Discontinuity - CDVDPlayerAudio::HandleSyncError1 - was:609578.859812, should be:495656.759610, error:-113922.100202
18:48:06 T:3044   DEBUG: CPullupCorrection: detected pattern of length 1: 41708.33, frameduration: 41708.333333
18:48:07 T:4592   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
18:48:07 T:4592   DEBUG: CAnnouncementManager - Announcement: OnPause from xbmc
18:48:07 T:4592   DEBUG: GOT ANNOUNCEMENT, type: 1, from xbmc, message OnPause
18:48:07 T:1136  NOTICE: $$$ [xbmc.callbacks2] - Executing command: [C:\Program Files (x86)\Kodi\userdata\Movie_Pause.py] for event: onPlaybackPaused
18:48:07 T:1136  NOTICE: $$$ [xbmc.callbacks2] - Command for onPlaybackPaused executed successfully
18:48:07 T:1960  NOTICE: Thread LanguageInvoker start, auto delete: false
18:48:07 T:1960    INFO: initializing python engine.
18:48:07 T:1960   DEBUG: CPythonInvoker(14, C:\Program Files (x86)\Kodi\userdata\Movie_Pause.py): start processing
18:48:07 T:1960  NOTICE: -->Python Interpreter Initialized<--
18:48:07 T:1960   DEBUG: CPythonInvoker(14, C:\Program Files (x86)\Kodi\userdata\Movie_Pause.py): the source file to load is "C:\Program Files (x86)\Kodi\userdata\Movie_Pause.py"
18:48:07 T:1960 WARNING: CPythonInvoker(14): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
18:48:07 T:1960   DEBUG: CPythonInvoker(14, C:\Program Files (x86)\Kodi\userdata\Movie_Pause.py): setting the Python path to C:\Program Files (x86)\Kodi\userdata;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.simplejson\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.beautifulsoup4\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.myconnpy\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.httplib2\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.addon.common-master\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.pyxbmct\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.beautifulsoup\lib;C:\Program Files (x86)\Kodi\addons\script.module.pil\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.common.plugin.cache\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.unidecode\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.simple.downloader\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.requests\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.pyxbmctmanager\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.hubparentalcontrol\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.parsedom\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.xbmcswift2\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.requests2-frodo\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.feedparser\lib;C:\Users\Mike\AppData\Roaming\Kodi\addons\script.module.metahandler\lib;C:\Program Files (x86)\Kodi\system\python\DLLs;C:\Program Files (x86)\Kodi\system\python\Lib;C:\Program Files (x86)\Kodi\python27.zip;C:\Program Files (x86)\Kodi\system\python\lib\plat-win;C:\Program Files (x86)\Kodi\system\python\lib\lib-tk;C:\Program Files (x86)\Kodi;C:\Program Files (x86)\Kodi\system\python;C:\Program Files (x86)\Kodi\system\python\lib\site-packages
18:48:07 T:1960   DEBUG: CPythonInvoker(14, C:\Program Files (x86)\Kodi\userdata\Movie_Pause.py): entering source directory C:\Program Files (x86)\Kodi\userdata
18:48:07 T:4592   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
18:48:07 T:3900   DEBUG: CDVDClock::Discontinuity - CDVDPlayerAudio::HandleSyncError1 - was:6564458.684752, should be:6068018.648590, error:-496440.036162
18:48:07 T:4592   DEBUG: CAnnouncementManager - Announcement: OnPlay from xbmc
18:48:07 T:4592   DEBUG: GOT ANNOUNCEMENT, type: 1, from xbmc, message OnPlay
18:48:07 T:4592   DEBUG: UPnP: Building didl for object 'E:\Movies\3 10 to Yuma\3.10.to.Yuma.mkv'
18:48:08 T:1960    INFO: CPythonInvoker(14, C:\Program Files (x86)\Kodi\userdata\Movie_Pause.py): script successfully run
18:48:08 T:1960    INFO: Python script stopped
18:48:08 T:1960   DEBUG: Thread LanguageInvoker 1960 terminating
18:48:09 T:4592   DEBUG: CApplication::ProcessMouse: trying mouse action leftclick
18:48:09 T:4592  NOTICE: CDVDPlayer::CloseFile()
Reply
I must have boned the copy paste action from earlier. I redid it tested and all is well in my world! Special thanks to KenV99!
Reply
Thanks very much for sharing this pilluli. Very useful
Reply
I updated my version to use script.module.requests instead of requests2 since it seems that since I initially wrote mine, script.module.requests has been updated to use the v2 backend and requests2 is giving some people issues with automatic downloads.
The link is the same at github: https://github.com/KenV99/service.xbmc.callbacks2
Reply
Thanks for this addon. Using it to run a library export after every scan.

Would it be possible to trigger a script when PVR reports a timer deleted? This signifies a recording finished and I would like to trigger the Perl Sorttv script to move the finished file, update the library and then export. The "timer deletion" is also reported on kodi start, so it would still catch it up if the recording ended while kodi wasn't running.
Reply
(2015-08-19, 13:53)rideti.me Wrote: Thanks for this addon. Using it to run a library export after every scan.

Would it be possible to trigger a script when PVR reports a timer deleted? This signifies a recording finished and I would like to trigger the Perl Sorttv script to move the finished file, update the library and then export. The "timer deletion" is also reported on kodi start, so it would still catch it up if the recording ended while kodi wasn't running.

Unfortunately, PVR timer deletions are not passed along to addons via the python xbmc.Monitor api. The events available are listed here:
http://mirrors.kodi.tv/docs/python-docs/...ml#Monitor

Furthermore, it is not documented to be available via the JSON interface: http://kodi.wiki/view/JSON-RPC_API/v6#Notifications_2.

The PVR addons are all written in cpp and are individual to each PVR backend so even hacking in and trying to do this nearly impossible.

I assume perhaps that you see that timer deletions appear in the log? If so, that's the only hack that I can imagine - create a loop that constantly reads the log and triggers when the timer is deleted. Doable, but I hate to say that I don't have the time or desire to develop that since I record everything on my TiVo. Sorry.
Reply
  • 1
  • 16
  • 17
  • 18(current)
  • 19
  • 20
  • 23

Logout Mark Read Team Forum Stats Members Help
[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)4