HELP with starting write python scripts
#1
Im starting to write python scripts .. I found this guide in wiki :

http://wiki.xbmc.org/index.php?title=HOW...lay_A_File

i started with primitive script :


xbmc@XBMCLive:~/Videos$ more test.py
# variable to contain the file location
file = 'Reset_Sberna.mp3'
# tell xbmc to play our file we specified in the above variable
xbmc.Player().play(file)

after start im getting error :


xbmc@XBMCLive:~/Videos$ python test.py
Traceback (most recent call last):
File "test.py", line 4, in <module>
xbmc.Player().play(file)
NameError: name 'xbmc' is not defined


same with secondary example


xbmc@XBMCLive:~/Videos$ more test2.py
# Import XBMC module
import xbmc

# First we need to create an object containing the getMusicInfoTag() class from XBMC.Player().
# This is in order to use the same instance of the class twice and not create a new class
# for every time we query for information.
# This is a bit important to notice, as creating many instances is rarely
# a good thing to do (unless you need it, but not in this case).

tag = xbmc.Player().getMusicInfoTag()

# Now tag contains the getMusicInfoTag() class which then again contains song information.
# Now we use this object to get the data by calling functions within that class:

artist = tag.getArtist()
title = tag.getTitle()

# Now you have two strings containing the information. An example of what you could do next is to print it:

print "Playing: " + artist + " - " + title

# This will produce i.e: "Playing: AC/DC - Back in black"


xbmc@XBMCLive:~/Videos$ python test2.py
Traceback (most recent call last):
File "test2.py", line 2, in <module>
import xbmc
ImportError: No module named xbmc


What im doning wrong ?
Reply
#2
Pytkin Wrote:xbmc@XBMCLive:~/Videos$ python test2.py
Traceback (most recent call last):
File "test2.py", line 2, in <module>
import xbmc
ImportError: No module named xbmc


What im doning wrong ?

you need to run them from within xbmc as the xbmc module is not available outside of the application.

check out this and this for more help.

t0mm0
Reply
#3
thanx .. it works now ..
Reply
#4
t0mm0 : script is working .. i want to playback stream from internet and every 10 second im checking if stream is playing , and if no , then will try playit again .. Script looks:

Code:
file = 'rtmp://myserver/live/mystream'
while True:
        if not xbmc.Player().isPlaying():
                xbmc.Player().stop()
                xbmc.Player().play(file)
        xbmc.sleep(10000)

Everyhing works .. but in display I see allert:

Loading directory
Retrieved 0 items
and button cancel

under this dialog box i see my stream .. how can i disable to show this dialog box ?
Reply
#5
Pytkin Wrote:t0mm0 : script is working .. i want to playback stream from internet and every 10 second im checking if stream is playing , and if no , then will try playit again .. Script looks:

Code:
file = 'rtmp://myserver/live/mystream'
while True:
        if not xbmc.Player().isPlaying():
                xbmc.Player().stop()
                xbmc.Player().play(file)
        xbmc.sleep(10000)

Everyhing works .. but in display I see allert:

Loading directory
Retrieved 0 items
and button cancel

under this dialog box i see my stream .. how can i disable to show this dialog box ?

Try something like this -
Code:
def MyFunction():
    file = 'rtmp://myserver/live/mystream'
    xbmc.Player().play(file)
    MyPlayer().onPlayBackStarted()

class MyPlayer( xbmc.Player ) :            
        def __init__ ( self ):
            xbmc.Player.__init__( self )
                
        def onPlayBackStarted(self):
            while (True):
                if self.isPlaying():
                    xbmc.sleep(1000)
                else:
                    #do something like call your function
                    MyFunction()
Reply
#6
divingmule : video is not starting ..

i was added at end call to MyFucntion() , for starting playback .. Video vas started , but I see again over video popup with LOADING DIRECTORY/ Retrieved 0 items/ Cancel :

Image
Reply
#7
Pytkin Wrote:divingmule : video is not starting ..

i was added at end call to MyFucntion() , for starting playback .. Video vas started , but I see again over video popup with LOADING DIRECTORY/ Retrieved 0 items/ Cancel :

i think to get rid of the loading directory thing you need to make sure you pass isFolder=False to xbmcplugin.addDirectoryItem()

but yeah, other than that subclassing xbmc.Player as divingmule says is the way to do this kind of thing. see here for a more complex example. took me a while to figure that out Wink

t0mm0
Reply
#8
Seems your script is adding a directory, so I'm guessing you need to add endOfDirectory http://xbmc.sourceforge.net/python-docs/...fDirectory

Usually if it's a plugin you can add this to the bottom of your script.
Code:
xbmcplugin.endOfDirectory(int(sys.argv[1]))

Edit: Yeah, also what t0mm0 said Wink
Reply
#9
YES .. xbmcplugin.endOfDirectory(int(sys.argv[1])) at start of scripts works .. it shows empty folder at start , but after that will start playback of stream without popup ..
Reply
#10
Pytkin Wrote:YES .. xbmcplugin.endOfDirectory(int(sys.argv[1])) at start of scripts works .. it shows empty folder at start , but after that will start playback of stream without popup ..

glad you got it sorted! if this is the only thing your addon does, sounds like a script might be better than a plugin as then you don't need to worry about the xbmcplugin stuff at all.

t0mm0
Reply
#11
t0mm0 : yes maybe .. Im looking in xbmc , and not see , how to start scripts .. i see some scripts in ~/.xbmc/addons .. But how can I start it , or acces it ?

I need to create script , which will start after booting into XBMC (live on ION) .. will be playback an live stream , and after problems with internet connection it will restart stream ..

Im almost done .. But i got an secondary problem .. If I interupt internet connection for a small time , stream will start again correctly .. If I interupt internet for longer time, i got this message :

Playback failed
One or more items failed to play
Check the log for details ..
OK

After click on OK , script will starting to play a stream again .. But I need to playback without human interaction ..
Can I disable to show this "Playback failed" dialog ?

and my last question .. Where can I setup, to autostart my plugin, after XBMC LIVE boot ?
Reply
#12
Pytkin Wrote:t0mm0 : yes maybe .. Im looking in xbmc , and not see , how to start scripts .. i see some scripts in ~/.xbmc/addons .. But how can I start it , or acces it ?

I need to create script , which will start after booting into XBMC (live on ION) .. will be playback an live stream , and after problems with internet connection it will restart stream ..

Im almost done .. But i got an secondary problem .. If I interupt internet connection for a small time , stream will start again correctly .. If I interupt internet for longer time, i got this message :

Playback failed
One or more items failed to play
Check the log for details ..
OK

After click on OK , script will starting to play a stream again .. But I need to playback without human interaction ..
Can I disable to show this "Playback failed" dialog ?

and my last question .. Where can I setup, to autostart my plugin, after XBMC LIVE boot ?

don't think i can help with any of that Sad

maybe rather than use a script with xbmc.Player subclassed you could write a service to check whether the stream is still playing and if not try again? not looked at services but that may do the trick, though i guess you may still end up with the 'playback failed' dialog? - anyone else?

t0mm0
Reply
#13
Im plying with this about 3 days and no luck .. if there are no connection , then Player everytime show message with PLAYBACK FAILED .. and I need click with mouse .. i was tested everything .. onPlayBackEnded , onPlayBackStopped .. still the same ..

Have anybody any idea ?

Or should I simulate this mouse click on message from Python ?
Reply

Logout Mark Read Team Forum Stats Members Help
HELP with starting write python scripts0