I'm trying to write a script that will will run when I start playing a video. I want the script to do two things. First, I would like to be able to figure out what the aspect ratio of the video is and send the appropriate zoom command to my projector. Second, I would like to send an http command to my automatic lights to dim the lights in the media room.
The script would be pretty simple and have the basic logic as follows:
on play
get aspect ratio
if aspect ratio = 2.35
then
zoom wide
else
zoom 16:9
dim lights
on stop
zoom 16:9
turn on lights
I've coded in c, c++, php, javascript, etc. Learning python seems pretty straightforward. What I am having a hard time finding is the xbmc specific stuff. In particular, how do I get a script to automatically run at startup (if that is even possible). Can I get xbmc to call my script when it starts to play a video, or would I have to alter the source code (likely beyond my expertise).
Thanks in advance for any help and/or advice,
Andy
To add to this, a service addon can be set to launch at startup and check periodically to see if a video is playing.
Thanks for the help! For the add-on service, what defines the folder and the script name?
<addon id="script.tv.betaseries"
name="BetaSeries.com"
version="0.1"
provider-name="blinkseb (XBMC)">
Is script.tv.betaseries in this example the folder in which the script is stored?
<extension point="xbmc.service"
library="default.py" start="[login|startup]">
And is "default.py" the actual script?
Also, where does the xml file with the info reside?
Thanks!
yes the folder needs to be exactly named like your addon id.
/addons/script.tv.betaseries/
default.py is the actual script which you can name like you want or even have in subfolder like
addon.xml resides in the root of the folder (see other scripts for examples).
/addons/script.tv.betaseries/addon.xml
needs to be either
or
Ok, I'm not able to get the script to run. Here's what I am using as a learning example...
import xbmc, xbmcgui
#get actioncodes from keymap.xml
ACTION_PREVIOUS_MENU = 10
ACTION_SELECT_ITEM = 7
class MyClass(xbmcgui.Window):
def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()
if action == ACTION_SELECT_ITEM:
self.strAction = xbmcgui.ControlLabel(300, 200, 200, 200, '', 'font14', '0xFF00FF00')
self.addControl(self.strAction)
self.strAction.setLabel('Hello world')
mydisplay = MyClass()
mydisplay .doModal()
del mydisplay
The script is saved in the AppData\Roaming\XBMC\scripts\test as default.py folder along with the following addon.xml file...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="test"
name="test script"
version="0.1"
provider-name="Andy">
<requires>
<import addon="xbmc.python" version="2.0"/>
</requires>
<extension point="xbmc.service"
library="default.py" start="[login|startup]">
</extension>
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary lang="en">My test script.</summary>
</extension>
</addon>
When I start xbmc, the script does not run. I previously had the script running when I put the autoexec.py file in the userdata folder. What am I missing?
Thanks!
Like I said you need to pick either startup or login and not both.
Thanks again! I was able to get the script running at start-up. Now all I have to make it do what I want...
(2012-10-16, 21:26)leechguy Wrote: [ -> ]You may want to check out this to use as a starting point: http://www.jordanhackworth.com/home-auto...with-xbmc/
Yes, I found that site very helpful. I now have my script working, although it needs a few tweaks to make it more efficient. I'll post it here in a few days.
Andy