Run script on starting or stopping video, run script before or after movie playback?
#1
Lightbulb 
Is it possible to run a script, when you chose to play a video.

I read this article here about how to make a fake file for your offline DVD collection. I would like to be able to write a script, that ejects the DVD drive, when you play that movie. If this is even possible, if someone could point me in the correct direction, I would appreciate it.

Thanks
Reply
#2
use the player class in the xbmc module.

look at my lasttube plugin (link in sig), it has a class that watches for videos to play.

In a script (as opposed to a plugin), you probably won't need the same kind of while loop to keep it alive, but you'll have to play around to figure that out.

also this may not work if you followed the wiki link, since the "video" will not actually play. better thing to do would be to make a real .avi a few seconds long so that the player class can work.

off the top of my head, I think the best thing to do would be put all your short 1-2 second .avi files into one folder called /dvd/ or something like that, then use something like (pseudocode) if self.getTotalTime() == 2 : eject

no idea about ejecting the drive, it seems like there is a builtin or httpapi to do that, but I can't remember.
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply
#3
Thanks for the reply. I did create an .avi to use, it is a 10 sec clip that tells you to insert the DVD.

I also found the section of the script from your plugin, that deals with watching for movies to play. I have to admit though, my python skills are somewhat rudimentary and I have no idea how to interface them with xbmc. I know I can eject the drive, by using the linux command 'eject' so using subprocess, I can run that from a python script. What I cannot figure out is how to find the length of the movie, to see if I need to call the eject command.
Reply
#4
If you put all your offline 'videos' in a folder called /dvd/ then could you just check if the source folder for the video is /dvd/ and if so run the eject command?

I don't know too much about python (trying to learn), but since all your offline videos will be in one folder it doesn't matter if you check the video length. There should be a way to check the source path via python. This won't work if you put your offline videos in with your online videos folder.
Reply
#5
rwparris2 Wrote:off the top of my head, I think the best thing to do would be put all your short 1-2 second .avi files into one folder called /dvd/ or something like that, then use something like (pseudocode) if self.getTotalTime() == 2 : eject

I ment OR get total time or check source.

look at the py docs for how to do either

http://xbmc.sourceforge.net/python-docs/xbmc.html
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply
#6
Thanks for the help guys, I am almost there Smile

This is the script I have now.

Code:
import xbmc,xbmcgui
import subprocess

while 1:
    if xbmc.Player().isPlayingVideo()==1:
        tag = xbmc.Player().getVideoInfoTag()
        path = tag.getPath()
        if path.find("DVD Collection") > -1:
            subprocess.call("eject", shell=True)

This works, as you might expect ejecting the DVD drive, whenever a video from the "DVD Collection" folder is playing.

So far I have it playing a 10 sec video telling you to insert the DVD. If you are really fast, and insert the DVD while the video is playing it instantly ejects it again. Is there a way to modify this script, so that that it would only happen when a video is started to play, instead of when it is just playing.
Reply
#7
I tried this

Code:
import xbmc,xbmcgui
import subprocess


class MyPlayer( xbmc.Player ) :
    
    def __init__ ( self ):
        xbmc.Player.__init__( self )
        
    def onPlayBackStarted(self):
       if xbmc.Player().isPlayingVideo()==1:
        tag = xbmc.Player().getVideoInfoTag()
        path = tag.getPath()
        if path.find("DVD Collection") > -1:
            subprocess.call("eject", shell=True)
        
p=MyPlayer()

while(1):
    xbmc.sleep(500)

but although it does not have any syntax errors (the log doesn't say any), it fails to eject the drive. Can't quite figure out what I have done wrong. :|

Let me know if you have any ideas.
Reply
#8
w00t! I got it. Spent a little longer checking out rwparris's lasttube code. I found i needed to make xbmc sleep for a couple secs before asking for the video info. Thanks for all the help. Here is the finished script.

Code:
# eject.py
# Script to eject DVD drive whenever any video file is played that is located in the "DVD Collection" folder.
# Thanks to rwparris2 for his LastTube code and help on the forums.

import xbmc,xbmcgui
import subprocess


class MyPlayer( xbmc.Player ) :
    
    def __init__ ( self ):
        xbmc.Player.__init__( self )
        
    def onPlayBackStarted(self):
    xbmc.sleep(2000)
           tag = xbmc.Player().getVideoInfoTag()
    path = tag.getPath()
    if path.find("DVD Collection") > -1:
        subprocess.call("eject", shell=True)
        
p=MyPlayer()

while(1):
    xbmc.sleep(500)
Reply
#9
I currently have a script (that turns my HT lights off and back on) mapped to the play and pause/stop button on my remote. Lately I've been using the XBMC Commander app to play my movies but this uses the HTTP API to do so, not an actual remote command. Therefore is there somewhere in a system script/file I can place my "lights off" shell script, or commands, so that it's always executed when a movie is played or stopped? Is this only possible by having a python script run continuously in the background or something?

Thanks.
Reply
#10
yes doable by a script.
Reply
#11
Lightbulb 
Just wondering if it's possible to have the RunScript function triggered when a video stops playing?

I'd like to have a python script run at the 95% mark (ideally) or when a movie stops playing altogether, is this possible?

Thanks!

Km.
Reply
#12
Look at what the trakt.tv guys are doing since this is what they're doing.
Code:
GRANT ALL PRIVILEGES ON `xbmc_%`.* TO 'xbmc'@'%';
IF you have a mysql problem, find one of the 4 dozen threads already open.
Reply
#13
darkscout Wrote:Look at what the trakt.tv guys are doing since this is what they're doing.

Yeah I had thought about that, but my python Kung-Fu is weak Smile

Km.
Reply
#14
It is possible to run script after movie to play next episode ?
like in below post: ?
http://forum.xbmc.org/showthread.php?tid=9150&page=13
Reply
#15
Hello,
Sorry for resurrecting an old post, but my goal is similar. I have an nvidia shield, an harmony ultimate remote, a 4k bluray player and domoticz which can control harmony... In fact, this means i can eject my 4k player drive with a simple url "http..." thanks to domoticz.
I want kodi to eject my 4k drive when i play a short video in the folder "4K Bluray". How to modify torianironfist's script to launch my url, saying domoticz to eject my drive ?
And where do I place the "eject.py" script ?
Thanks for your help, hope i'm not confusing with my request !
Reply

Logout Mark Read Team Forum Stats Members Help
Run script on starting or stopping video, run script before or after movie playback?1