[RELEASE] Execute user scripts on specific XBMC actions (play starts/stops...)

  Thread Rating:
  • 3 Vote(s) - 4.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
tekno Offline
Senior Member
Posts: 205
Joined: Feb 2012
Reputation: 1
Post: #181
I tried this script and it does work as advertised thank you.

I have a suggestion however for the launch at start up, or maybe it is already possible some other way.....

Is there any way one can delay the availability (not launch) of xbmc/kodi until the start up script has completed? If not can this be implemented into this script? I am using this to sync files from a web server and need to delay the availability of using xbmc until the script has completed. I have to prevent add ons from being run till this is done
find quote
KenV99 Offline
Senior Member
Posts: 268
Joined: Nov 2013
Reputation: 8
Post: #182
(2014-12-25 18:53)tekno Wrote:  I tried this script and it does work as advertised thank you.

I have a suggestion however for the launch at start up, or maybe it is already possible some other way.....

Is there any way one can delay the availability (not launch) of xbmc/kodi until the start up script has completed? If not can this be implemented into this script? I am using this to sync files from a web server and need to delay the availability of using xbmc until the script has completed. I have to prevent add ons from being run till this is done

This addon cannot do that since it is the python interpreter within Kodi that runs the scripts.
You might want to write a script in an appropriate language for your OS to perform your tasks and wait for them to complete prior to starting Kodi and then launch Kodi using that script.
(This post was last modified: 2014-12-26 00:00 by KenV99.)
find quote
Jpaytoncfd Offline
Member
Posts: 67
Joined: Mar 2009
Reputation: 1
Post: #183
(2014-12-25 18:53)tekno Wrote:  I tried this script and it does work as advertised thank you.

I have a suggestion however for the launch at start up, or maybe it is already possible some other way.....

Is there any way one can delay the availability (not launch) of xbmc/kodi until the start up script has completed? If not can this be implemented into this script? I am using this to sync files from a web server and need to delay the availability of using xbmc until the script has completed. I have to prevent add ons from being run till this is done

On ubuntu you could use Upstart to start Kodi. I think you can use the starton to look for a file existing before starting.

Read here, http://upstart.ubuntu.com/cookbook/#envi...-variables
(This post was last modified: 2014-12-29 19:59 by Jpaytoncfd.)
find quote
tekno Offline
Senior Member
Posts: 205
Joined: Feb 2012
Reputation: 1
Post: #184
Actually, I ended up doing this somewhat differently than I wanted to and thought I would post that result here.

Instead of making xbmc "unavailable" like muting video or something of the like I used xbmc callbacks and my script now includes a message to xbmc-eventclients that says "Please Wait, Downloading..." then after the script is run it sends "Download complete, Ready."

Works quite well however I wish that the kodi devs would finally reduce the volume of alerts or the recordings they play back The sounds are quite sharp and loud compared to average Movie or TV volume. I have seen these alerts complained about before. yes I have lowered the volume in the recordings before but they get overwritten on an upgrade

Thanks
find quote
bigbadrabbit Offline
Senior Member
Posts: 170
Joined: Sep 2008
Reputation: 0
Location: Austria
Post: #185
Can someone help please with the following .sh script:

Code:
#!/bin/bash

/usr/bin/osascript <<-EOF

      tell application "System Events"
    if process "iTunes" exists then
        set okflag to true --iTunes is running
    else
        set okflag to false
    end if
end tell

if okflag is true then
    
    tell application "iTunes"
        
        set currentvolume to the sound volume
        if player state is playing then
            repeat
                --Fade down    
                repeat with i from currentvolume to 0 by -1 --try by -4 on slower Macs
                    set the sound volume to i
                    delay 0.01 -- Adjust this to change fadeout duration (delete this line on slower Macs)
                end repeat
                pause
                --Restore original volume
                set the sound volume to currentvolume
                exit repeat
            end repeat
        else -- if player state is paused then
            
            set the sound volume to 0 --2007-03-20 script update to fix startup glitch
            play
            
            -- tell application "System Events" to set visible of process "iTunes" to false
            
            -- reveal current track
            
            repeat with j from 0 to currentvolume by 1 --try by 4 on slower Macs
                set the sound volume to j
                delay 0.01 -- Adjust this to change fadeout duration (delete this line on slower Macs)    
            end repeat
        end if
    end tell
end if

EOF

This one worked with the original callbacks 0.5 but not with callbacks2. I get the following errors:

[Image: Bildschirmfoto%202015-01-02%20callbacks2%20error1.png]
[Image: Bildschirmfoto%202015-01-02%20callbacks2%20error2.png]

Kodi Helix
Mac OS X 10.10.1
Mac mini (late 2012) | i5 | 8GB RAM | SSD
find quote
bigbadrabbit Offline
Senior Member
Posts: 170
Joined: Sep 2008
Reputation: 0
Location: Austria
Post: #186
Nevermind. Found a way to execute the applescript within Python.

Any chance there'll be a "Kodi Quit/Exit" option instead of shutdown?

Kodi Helix
Mac OS X 10.10.1
Mac mini (late 2012) | i5 | 8GB RAM | SSD
(This post was last modified: 2015-01-04 18:22 by bigbadrabbit.)
find quote
ReplayHarry Offline
Junior Member
Posts: 10
Joined: Feb 2014
Reputation: 0
Post: #187
I saw this service addon script and it gave me a great idea. It works well triggering the starts of video and stops, which is what I wanted.
I'm running Gotham 13.2 on a win 8.1 system with nextpvr doing my recording for me.

I am trying to make viewing videos similar to my REPLAY TV (some people may remember these and my wife is still using one of ours). With Replay TV, when a video ends or you stop it, it gives you 3 options, "Resume playback", "Delete the video", or "Play another Video". By default I have the "Play another video" working as that would be where Kodi would return anyway, and I don't think I will have any problem with the delete. That is ordinary stuff.

I am of course using Python to try to do these things, and while not a Python expert, I am getting better with it. I've already made a couple of handy little tools for Kodi.

But... the resume is another story for me and maybe someone could point me in the right direction as my searches on this forum and elsewhere have not found a solution. When I "START" a video (I'm watching in file mode so I can skip the commercials via COMSKIP), the trigger records all the pertinent info available with the addon (file name, the trigger, etc, etc) and writes that to a file for later use. I then use that file when "STOP" is triggered as the addon does not provide the filename there. But when I execute a xbmc.player.play(), it always starts at the beginning of the video, not in the place it left off. I do have XBMC video settings set to "Resume" and that works fine when playing or resuming a video normally.

I am assuming Kodi has a bookmark someplace saying where the video left off as it knows when you start a video. So I need to know where that is and how to get it so I could use it in my Python script. There does not seem to be a player.resume() function to execute and I'd like to build one for my function. I know the player.play() function has a field indicating where to start. So if I could retrieve that info from "who knows where" I should be able to plug it in and do exactly what I want. I'd also like to find where the "WATCHED" or "UNWATCHED" field is as ideally I'd only like to trigger my delete function when the show is watched.

I'm doing all my development on my desktop PC so Kodi remains stable and usable for my normal needs.

Anyone have any ideas? I would greatly appreciate it. It might help me finally get my wife to give up her ReplayTVs.

Thanks in advance for any assistance that may be given.

------- OK, I found a fix
jsonrpc. From there I can send a play "resume".

{"jsonrpc": "2.0",
"id": 1,
"method": "Player.Open",
"params": {"item": {"file":my_file},
"options": {"resume": True

I wanted to use the "executejsonrpc" from within the XBMC Python transport. Never could get it to work. After much research, trial and error, and frustration I went to the HTTP jsonrpc transport, and got it to work. Not a lot of examples out on the web to help, but the ones I did find, finally gave me enough help to make it work.

So now when a show stops (set it up to only do my thing if a TV Show) I have the 3 options mentioned above. And when I select "delete" it deletes the show file along with the other edl and txt files created by COMSKIP. If the directory is now empty, it deletes the directory too.

Maybe someone else will be helped by this.
(This post was last modified: 2015-02-02 18:51 by ReplayHarry.)
find quote
Post Reply