Kodi Community Forum
Install python script (windows) - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Install python script (windows) (/showthread.php?tid=93794)

Pages: 1 2


Install python script (windows) - Evilgb - 2011-02-10

Hi,

If this has already been answered, I'm terribly sorry. But I've searched and couldn't come up with anything.

My problem is that I have this script that Klabbe on http://www.telldus.se/forum/ created for tellstick, but I can't get it to work with XBMC 10.0 on Windows 7. I guess I need some sort of .xml file to load it. I've been sitting for a whole day trying to figure out how to get this to load.

Code:
# ljus.py

import xbmc,xbmcgui
import subprocess,os

class MyPlayer(xbmc.Player) :
  
        def __init__ (self):
            xbmc.Player.__init__(self)

        def onPlayBackStarted(self):
            if xbmc.Player().isPlayingVideo():
                os.system("c:\test.exe")

        def onPlayBackEnded(self):
            if (VIDEO == 1):
                os.system("c:\test.exe")

        def onPlayBackStopped(self):
            if (VIDEO == 1):
                os.system("c:\test.exe")

        def onPlayBackPaused(self):
            if xbmc.Player().isPlayingVideo():
                os.system("c:\test.exe")

        def onPlayBackResumed(self):
            if xbmc.Player().isPlayingVideo():
                os.system("c:\test.exe")

player=MyPlayer()

while(1):
    if xbmc.Player().isPlayingVideo():
        VIDEO = 1

    else:
        VIDEO = 0

    xbmc.sleep(3000)

What the script does is to open a file, which sends a command to another file to dim my lights when I start playing a movie, and dim them up again when I stop playing.

If anyone would be so very kind to help me with this, I will love you long time! Tongue


- Evilgb - 2011-02-11

Well, I've copy pasted the .xml file from http://wiki.xbmc.org/index.php?title=HOW-TO:_Automatically_start_addons_using_services but I'm getting "Could not read addon description of script.ljus" all the time. Do I need some description in the default.py file aswell?


- divingmule - 2011-02-11

import xbmcaddon


- Evilgb - 2011-02-11

Tried it now, but still same error message in the log :S Thanks anyway Smile I'm deleting the addons folder in AppData\Roaming\XBMC between every attempt aswell.


- divingmule - 2011-02-12

Maybe post what you have for an addon.xml?


- Evilgb - 2011-02-12

As I wrote, it was copy pasted from the wiki, except the <description> part.

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.tv.betaseries"
       name="BetaSeries.com"
       version="0.1"
       provider-name="blinkseb (XBMC)">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
  </requires>
  <extension point="xbmc.service"
             library="default.py">
  </extension>
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <summary lang="en">BetaSeries.com integration.</summary>
    <description lang="en">pewpew</description>
  </extension>
</addon>



- divingmule - 2011-02-13

Try this:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.ljus"
       name="ljus"
       version="0.0.0"
       provider-name="">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
   </requires>

  <extension point="xbmc.python.script"
            library="ljus.py">
  </extension>
  <extension point="xbmc.addon.metadata">
    <summary></summary>
    <description></description>
    <platform>all</platform>
  </extension>
</addon>

Put your addon.xml and ljus.py in a folder named script.ljus in addons/

And add the, import xbmcaddon to the top of ljus.py .


- Evilgb - 2011-02-13

Thanks alot! Now the script is loaded. But for some reason it don't want to open the file. I loaded the script in XBMC 9.04 manually, and it worked there. So if you, or anyone else, have any clue on why the file wont open, I'm all ears.
I've tried some other paths, like "special://xbmcbin/dimtest.exe"
"special:\\xbmcbin\dimtest.exe"
"//xbmcbin/dimtest.exe" "
"\\xbmcbin\dimtest.exe"
"\\xbmc\dimtest.exe"
"//xbmc/dimtest.exe"
"special:\\xbmc\dimtest.exe"
"special://xbmc/dimtest.exe"
and of course "C:/dimtest.exe", which worked in 9.04

Thanks again divingmule Smile


- Evilgb - 2011-02-20

No one? Sad


- amet - 2011-02-20

what is your .py file called? ljus.py?

do you see your addon in Programs?

zip and upload somewhere that we can access it and we can have a look


- Evilgb - 2011-02-20

Thanks for the fast answer Smile

The .py file is actually called default.py. The script was just copy pasted from another forum, which I said. But something I learned is that the file should be called default. The script is loaded in xbmc in the programs tab. But does that mean it does not run automaticly in the background?

Here's default.py:
Code:
import xbmcaddon

# default.py

import xbmc,xbmcgui
import subprocess,os

class MyPlayer(xbmc.Player) :
  
        def __init__ (self):
            xbmc.Player.__init__(self)

        def onPlayBackStarted(self):
            if xbmc.Player().isPlayingVideo():
                os.execv('c:\dimtest.exe')

        def onPlayBackEnded(self):
            if (VIDEO == 1):
                os.execv("c:\dimtest.exe")

        def onPlayBackStopped(self):
            if (VIDEO == 1):
                os.execv("c:\dimtest.exe")

        def onPlayBackPaused(self):
            if xbmc.Player().isPlayingVideo():
                os.execv("c:\dimtest.exe")

        def onPlayBackResumed(self):
            if xbmc.Player().isPlayingVideo():
                os.execv("c:\dimtest.exe")

player=MyPlayer()

while(1):
    if xbmc.Player().isPlayingVideo():
        VIDEO = 1

    else:
        VIDEO = 0

    xbmc.sleep(3000)

And here is addon.xml, thanks to divingmule:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.ljus"
       name="ljus"
       version="0.0.0"
       provider-name="">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
   </requires>

  <extension point="xbmc.python.script"
            library="default.py">
  </extension>
  <extension point="xbmc.addon.metadata">
    <summary></summary>
    <description></description>
    <platform>all</platform>
  </extension>
</addon>
.

Also a link to the zip file:

http://www.mediafire.com/?604exybrd6ctarh


- amet - 2011-02-20

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.ljus"
       name="ljus"
       version="0.0.0"
       provider-name="">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
   </requires>

  <extension point="xbmc.python.script"
            library="[color=red]ljus.py[/color]">
  </extension>
  <extension point="xbmc.addon.metadata">
    <summary></summary>
    <description></description>
    <platform>all</platform>
  </extension>
</addon>

library="ljus.py" should be library="default.py"

and no, it will not auto load on start, you need to start it


- Evilgb - 2011-02-20

It allready is. I must have uploaded wrong file.

The correct file:
http://www.mediafire.com/?gmcd3xll2crc353


- amet - 2011-02-20

what happens when you run it? debug log would have the answers


- Evilgb - 2011-02-20

Nothing happens if I run it. What the script should do is run in the background at all times, and when I play/pause/stop etc it should execute a file. But now it seems like it's a program that I just run manually. I tried running it when a movie was plaiyng, but nothing happened.

The log:
http://www.mediafire.com/?zz5df4p6fxuuuqf