PDA

View Full Version : Python Scripts Development


Blackbelt
2003-10-07, 20:17
i noticed that a ported version of python (http://www.python.org) is included in the xbmc source. this is great as python is a simple and powerful object oriented scripting language. so how is python used by xbmc? are scripts used as a part of the application or is the intent only to execute external utility scripts?

the ability to tweak scripts and see the results without recompiling and downloading to the xbox would sure be nice...

Hullebulle
2003-10-08, 01:51
you can select the scripts like a program or movie and start it. :)

too bad that i have no idea of python.

Zealot
2003-10-08, 19:51
i'm really wondering the same thing. i've looked through the forums and docs on the xbmp site, and i couldn't find a definite answer.

does xbmc have a full embedded python interpreter, or is it a limited set of functionality? is there socket support? like, would i be able to build a web service / client in python?

Hullebulle
2003-10-08, 21:36
does xbmc have a full embedded python interpreter, or is it a limited set of functionality?
full

is there socket support?
yes

like, would i be able to build a web service / client in python?
yes

burriko
2003-10-09, 13:33
can any of the devs give a bit more info on this? as it sounds very interesting.
how do the scripts interact with xbmc? how exactly do you execute scripts? i tried selecting a small test script in xbmc, but it didn't seem to have any effect.

windragz
2003-10-10, 22:14
a dream becomes to be a reality!!
yes, yes. i want develop some webservice, so dear python dev implementator tell us anything is possibile about this wonderful part :)

it's clear that i'm excited? :d

burriko
2003-10-15, 01:01
currently i am buzy to integrate some xbmc stuff into xbmc, like a yes / no dialog and the progress dialog. for example, you could use the progress dialog when downloading a file from ftp so an user could see how long it takes before it would finish.
sounds good.
i was thinking about writing some python scripts to control a tivo over the network. just simple tasks such as deleting shows, etc. to complement duo's work on streaming video from tivo. i don't think it should be too difficult.
i would need python to be able to display a list of objects (in the same format as it displays a list of videos or mp3s would be great) in xbmc and then wait for the user to select one and pass the selected option on to the script. is that functionality likely to be available to python?

Gamester17
2003-10-15, 14:50
things i would like 2 see for python:

1. bind a button control to a script. so pressing a button will run a script
a nice place for one of those buttons would be under the future tv-guide, user could link it to a grab tv listings script

windragz
2003-10-16, 20:47
frodo, we are on the same page!! http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/wow.gif

burriko
2003-10-18, 21:10
i just tested out a python script in xbmc that i wrote to delete a show from a networked tivo, and it worked great. it should be quite easy to add a lot of extra functionality to xbmc using python.
darkie, how exactly do you use the 4 dialogs that you've added so far? i can't find any example scripts or documentation.

thanks,
burriko.

darkie
2003-10-18, 21:54
it isn't in cvs yet, still expirimenting a lot with it.
i'll add it to cvs in lets say 2 day's, with some sample scripts.

burriko
2003-10-22, 02:30
darkie, i've just been playing around with the stuff that you've added to cvs so far. and it's awesome! i already have some of my scripts running on xbmc to control tivo using the list and ok dialogs.
python is going to add so much functionality to xbmc!

btw, i'm sure you know this already, but when any script finishes running it crashes xbmc (this is compiled from anonymous cvs about an hour ago).

darkie
2003-10-22, 19:03
btw, i'm sure you know this already, but when any script finishes running it crashes xbmc (this is compiled from anonymous cvs about an hour ago).
uuuh no... didn't know that. xbmc + python are running fine in both debug and relase build on my xbox.
does xbmc crash to when running any of those examples included in cvs?

burriko
2003-10-22, 19:48
does xbmc crash to when running any of those examples included in cvs?
yes, every script that i've tried freezes up the xbox when it finishes running, including the examples that come with it.

i've just upgraded to the cvs build that has been released today (although i think it's compiled from exactly the same code as the one i compiled last night) and the scripts are still freezing the xbox when they finish running.

darkie
2003-10-22, 21:30
wel i did fix a bug related to the crashing, but a fix for it is in cvs now for 2 days. maybe anon cvs is very long behind.

fonzi
2003-10-29, 09:40
it'will be a nice feature when xbmc start's it runs some file automatictly, like startup.py and when xbmc quit's a separate file.

so i can program a python scripts that saves the state of the played file and when it starts up it continues where it finished, like
car cd players.

Gamester17
2003-10-29, 14:37
so i can program a python scripts that saves the state of the played file and when it starts up it continues where it finished, like car cd players.
if would be much better if that be codec into xbmc gui/core nativly as an option than into a separate python script

cyberplague
2003-11-08, 00:23
are there any links to documentation on how to use python with xbmc?

i am looking to write some code in python to connect to my replaytv and delete and possibly stream shows straight from the replay.

thanks,

cp

rjm2k
2003-11-08, 01:40
are there any links to documentation on how to use python with xbmc?

i am looking to write some code in python to connect to my replaytv and delete and possibly stream shows straight from the replay.

thanks,

cp
this thread details how to get python running if you read back far enough. you then goto settings->scripts and select the script you want to run. afaik, it's pretty much a full implementation of python, though interaction with xbmc is limited at the moment (a few dialogs). i've read of people connecting to devices using ip like you mention, i'm not sure if you would be able to stream though, that would depend on xbmc supporting the streaming protocol, which may or may not be a problem.

darkie
2003-11-08, 01:43
for xbmc there is no documentation atm. but since writing python code for windows is the same as writing it on the xbox you should be able to find most information at python.org (http://www.python.org)

for xbmc specific functions you can take a look at the examples which are in cvs\scripts\

problem for now is that there isn't any error output to xbmc, so you can't see if the script runs ok or not.

burriko
2003-11-08, 01:54
cyberplague, it's very easy to see how to use the xbmc specific stuff if you take a look at darkie's example scripts.

here's the current version of my tivo scripts if anyone is interested.
tivocontrol.zip (http://www.tait.nildram.co.uk/tivocontrol.zip)
keep in mind that this script has only been tested on my tivo so far. i'd be interested to hear from anyone who tries it.

cyberplague
2003-11-08, 10:20
doh! i will check out python.org. as well as the scripts.

thanks for the tivoscripts. my mother-in-law has a tivo, so i will test it with hers and let you know the outcome.

darkie: couldn't in the scripts we code an error catching routine, that could use the dialogs to output any errors or something to let us know the script ran fine?

thanks again guys. tomorrow i will start my testing...

cp

rjm2k
2003-11-08, 17:05
i found a pretty good python remote debugger at http://www.activestate.com/ , seems to work well with xbmc.

darkie
2003-11-08, 18:10
to cyberplague:, the error catching is already there. only need to be written to a dialog (which isn't a big deal, just didn't had the time yet)

cyberplague
2003-11-08, 19:34
darkie - awesome. i figured it was not active cause of time issues. any idea when it could be done? i don't need a specific date, just if it is going to be days, weeks or months before it gets written to a dialog. it would really help with python script development. which you already know.

keep up the great work. i wouldn't mind writing some documentation for the python side of things. let me know.

cp

burriko
2003-11-18, 19:16
darkie, is it possible to write a page of text to the screen? kind of like the script output screen i suppose.
btw, i did a dir(xbmc) to check what's available from importing xbmc, obviously dialog and dialogprogress are used in your example scripts so i can see what we can do with them, but what about window and ouput?

thanks for any info you can give.
burriko

darkie
2003-11-19, 00:07
what i am busy with is to make it possible to create your own windows (add text / images / buttons and more) and display it, but this isn't finished yet.

xbmc.window as it is now in cvs is just an expiriment and doesn't do anything at all.
if you want to write to to screen you could use xbmc.output or sys.stdout for now

burriko
2003-11-19, 01:04
cool, thanks for the info. what you described sounds great, i look forward to seeing what develops.

Gamester17
2003-11-19, 13:42
too bad xbmc does not yet have xbmp's tv-guide or the fruits of the python xmltv tv_grab (http://sourceforge.net/projects/pytvgrab/) project would be usefull http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/wink.gif

kikiller
2003-11-19, 14:02
sure, python in xbmc has a lot of potential in plugin development and that would be great to be able to auto update tv listings through python.
can't wait to see this http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/cool.gif

Cyan
2003-11-28, 11:12
i just wanted to give a big *thank you* to the xbmc developers for putting python support into xbmc, it's truly awesome. there are a *lot* of neat things that can be done with this, and it's about time that we had an easy user-level scripting language to use for doing cool things on the xbox. i'm really looking forward to what can be done with this in the future.

in particular, i've written a basic irc bot that comes onto irc (by utilizing the sockets support in python) and can be controlled into doing some very basic things (i.e. playing a particular song/movie, etc.) it works surprisingly well. in the future i plan on writing in dcc support so that the bot can receive/send files to/from xbmc (the idea being, the bot will be able to say "now playing: song x, to download, type /ctcp mybot blah".) although i know that xbmc is alpha software for now, i have a couple of suggestions. i'm sure you guys have thought of some of these already, but without further ado:

* the ability to auto-execute scripts upon loading would be a major plus, that way my irc bot would always re-join automatically.
* several functions that would allow us to see what media is being played (and its name, size, length, how much its played so far, etc) would be very useful. also, some kind of traversal functions would be good (i.e. "tell me all of the mp3 files available on my smb share in a certain directory) subsequently, being able to query information about that file (i.e. "return the id3 tags for file x") would be useful.

beyond that, *thanks* for doing a great job, and i see that filezilla support was finally added into the cvs tree, so maybe now i'll be able to use xbmc as a dashboard replacement. :) i look forward to seeing what else will come of xbmc.

--cyan

febs
2003-11-28, 17:34
maybe now i'll be able to use xbmc as a dashboard replacement.

too bad xbmc it isn't usable as dashboard replacement 'till now.
it's very promising (it will also allow to set xbox settings like date and time, video format, savegames, and so on).

a killer app. keep on the amazing work and thank you

Nickman
2003-11-30, 22:20
ok, python has the option now to create windows where text and images can be drawn on.
i've just added *a small example to the cvs tree so people can have a look at it.

note, it is impossible to close a window at this time with your controller or remote. will be fixed soon.
great work darkie!

now i just have to learn python and start coding.

python is most likely to be the scripting language to replace arexx in amigaos 4 :)

so it won't be a waste of time. http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/wink.gif

fonzi
2003-12-01, 12:55
in particular, i've written a basic irc bot that comes onto irc (by utilizing the sockets support in python) and can be controlled into doing some very basic things (i.e. playing a particular song/movie, etc.) it works surprisingly well. in the future i plan on writing in dcc support so that the bot can receive/send files to/from xbmc (the idea being, the bot will be able to say "now playing: song x, to download, type /ctcp mybot blah".) although i know that xbmc is alpha software for now, i have a couple of suggestions. i'm sure you guys have thought of some of these already, but without further ado:
hi cyan

you gived me a great idea with your irc bot, so i tried to program it
myself

i downloaded the python irclib, edited the testbot example so it doesn't need sys library.

but the script works on my windows pc but not on xbmc(it does not give any errors but doesn't connect to irc)

can you tell me what you used for your bot,or did you wtite it from scratch or can you public the source code

fonzi

Cyan
2003-12-02, 08:28
since i'm very familiar with irc (i've been on irc in one form or another for almost ten years, now,) it was really simple for me to write my own code. i thought that there might be an existing irclib for python, but i didn't know enough about the language and how its module system worked to try to use it. without further ado, here's the basics of it, although excuse any sloppy/incorrect code, as it's my first attempt at a python script. i've stripped out some code as to keep the post short, but, it's obvious as to how it should work. i've added comments at the bottom of the post.


#
# xbmc irc bot by randolph e. sommerfeld <cyan@rrx.ca>
# permission to copy granted so long as this copyright notice remains.
# email the author <cyan@rrx.ca> with any changes or custom hacks.
# thanks!
#
from socket import *
import string
import time

##### "consts #####
version_notice = "xbox bot v0.1 by randy sommerfeld, running on a real, live xbox!"

##### functions #####

def servercommands(nick,user,host,str):
command = string.upper(str[0:string.find(str, " ")])
cmd = string.split(str," ")
irc_string = str[string.find(str,":")+1:9999999]
if command == "ping":
irc_send("pong " + cmd[1])
elif command == "privmsg":
if string.upper(cmd[2]) == ":xb":
botstr = irc_string[string.find(irc_string," ")+1:9999]
botcommands(nick,user,host,cmd[1],botstr)
elif string.upper(cmd[2]) == ":^aversion^a":
irc_send("notice " + nick + " :^aversion " + version_notice + "^a")

def botcommands(nick,user,host,target,botstr):
tmp_find_string = string.find(botstr," ")
if tmp_find_string == -1:
tmp_find_string = 999999999999
bot_cmd = string.upper(botstr[0:tmp_find_string])
if bot_cmd == "die":
done=1
elif bot_cmd == "version":
privmsg(target,version_notice)
elif bot_cmd == "help":
privmsg(target,help)
#.....etc, each bot command goes here.....

def privmsg(target,msg):
irc_send("privmsg " + target + " :" + msg)

def irc_send(msg):
print("--> " + msg)
s.send(msg + "\r\n")

def irc_getnick(str):
return str[0:string.find(str, "!")]

def irc_getuser(str):
return str[string.find(str, "!")+1:string.find(str, "@")]

def irc_gethost(str):
return str[string.find(str, "@")+1:999]

##### main() #####

s = socket(af_inet, sock_stream)
s.connect(("irc.synchro.net", 6667))
print "connecting to irc..."

irc_send("user xbox * * xbox :i'm running on cyan's xbox :")
irc_send("nick xbox")
irc_send("join #xbox")

done=0
remainder=""
while not done:
data = ""
test_remainder = string.find(remainder, "\r\n")
if test_remainder != -1:
data = remainder[0:test_remainder]
remainder = remainder[test_remainder+2:9999999999999]
else:
time.sleep(1)
remainder = remainder + s.recv(512)
if data:
print("<-- " + data)
strindex=1
strindex = string.find(data, ":")
if strindex == 0:
origin_str = data[1:string.index(data, " ")]
cmd_str = data[string.index(data, " ")+1:999]
is_nuh = string.find(origin_str, "!")
if is_nuh == 1:
servercommands(origin_str,0,0,cmd_str)
else:
nick = irc_getnick(origin_str)
user = irc_getuser(origin_str)
host = irc_gethost(origin_str)
servercommands(nick,user,host,cmd_str)
else:
servercommands(0,0,0,data)


* i know the '999999' thing is lame, and there must be some other way to mean "all the way to the end of the string," but i couldn't find it.
* the ^a is an actual control-a character. i wasn't sure how to insert it into python (i.e. by \0x01, \001, \1 or otherwise) this is used for ctcp.
* i can typically be found on irc.synchro.net as "cyan" in #rrx
* commands in the channel are sent like this: "xb version", and the response is thus put into the channel. commands in msg are sent like this: "/msg xbox version" and then the response is msg'd back to you.
* please email me or talk to me on irc if you make any changes or if you're using this code. it's just a skeleton for now, but it should be enough to get everyone going :)

Hullebulle
2003-12-03, 01:26
thanx for the sample cyan. :)

kraqh3d
2003-12-03, 17:00
first, let me say great work so far on xmbc. since it seems like progress on xbmp is slowing down so i figured it was time to register over here :)

i cant wait to start playing with python. i just installed the 11-29 ***** cvs snapshot. is this sufficient to start displaying information to a window? ideally, python is the way to get the my weather, tv guide, and other fringe features implemented.

and cyan... you can leave off the number after the colon uin the string index... ie:

remainder = remainder[test_remainder+2:]

cyberplague
2003-12-03, 20:20
cyan - thanks for the script

darkie- keep up the good work

now i am in no way a python guru, so i need some help. *as i stated before i am trying to contact and control my replaytv from my xbox. *now i found a script that is written in python, however it uses wxpython for the gui part. *which we don't have on this version. *basically if someone could shove me in the right direction as how to handle this i would be greatful.

the main section that i need from the link below is this one:


################################################## ############################
# upnp ( looks for replay units, sends events to gui )
# fixme: move manipulation of replay_device_list to gui thread
################################################## ############################
class replay_upnp(thread):
def (self):
thread.(self)

self.socket = socket.socket(socket.af_inet, socket.sock_dgram)
self.socket.setblocking(0)
self.running = 1
self.start()

def send_search(self):
self.socket.sendto("m-search * http/1.1\r\nhost: 239.255.255.250:1900\r\nman: \"ssdp:discover\"\r\nst: urn:replaytv-com:device:replaydevice:1\r\nmx: 3\r\n\r\n",
0,('239.255.255.250', 1900))

def run(self):
ticks = 0
while(self.running):
if ticks % 60 == 0:
self.send_search()
ticks = ticks + 1
ready_to_read, ready_to_write, in_error = select.select([self.socket],[],[], 1)
if self.socket in ready_to_read:
data, addr = self.socket.recvfrom(512)
p = data.find('location: ')
loc = ''
if (p):
loc = data[p+10:]
p = loc.find('\n')
if (p):
loc = loc[:p]
loc = loc.strip()
device_info=''
fn=''
sn=''
if (loc):
try:
conn = httplib.httpconnection('%s:80' % addr[0])
conn.request("get", loc)
res = conn.getresponse()
device_info = res.read()
p = device_info.find('<?')
device_info = device_info[p:]
try:
dom = xml.dom.minidom.parsestring(device_info)
fn = dom.getelementsbytagname("friendlyname")[0]
sn = dom.getelementsbytagname("serialnumber")[0]
fn = gettext(fn.childnodes)
sn = gettext(sn.childnodes)
except:
pass
except:
device_info=''
try:
d = replay_device_list[addr[0]]
if fn == 'none' or fn == '':
fn = "(%s)" % addr[0]
try:
#app.frame.panela.setitemtext(d['id'], fn)
wxpostevent(app.frame,resultevent( ('setreplydevicename',d['id'],fn) ))
except:
pass
replay_device_list[addr[0]]={
'id': d['id'],
'loc': loc,
'device_info': device_info,
'friendlyname': fn,
'serialnumber': sn}
log(device_info)
except:
id = 0
try:
id = replay_device_list['_count']
except:
id = 0
replay_device_list['_count'] = id+1
replay_device_list[addr[0]]={
'id': id,
'loc':loc,
'device_info': device_info,
'friendlyname':fn,
'serialnumber': sn}
replay_device_list['_id%s'%id] = addr[0]
if fn == 'none' or fn == '':
fn = "(%s)" % addr[0]
else:
replay_device_list[fn]=addr[0]
#app.frame.panela.insertstringitem(id, fn)
wxpostevent(app.frame,resultevent( ('addreplydevice',id,fn) ))



that sends a broadcast out, and any replaytv will reply. just a shove, and if i get a rtfm comment it is ok. thanks in advance for whatever help you maybe.

http://www.flyingbuttmonkeys.com/replay/replaytvclient.py

^ is what i am basing this off of at the moment, i have a feeling that i just need to start from scratch but i am not sure.

thanks,

cp

adrianmak
2003-12-21, 11:59
how powerful python script can be developed used on xbox ?

Hullebulle
2003-12-21, 20:47
how powerful python script can be developed used on xbox ?
what?

Kuranes
2003-12-22, 19:27
i just wanted to say i'm really excited to see python support in xbmc. i'd love to write some custom code for my xbox, but i don't want to fiddle with proprietary sdks or god-forsaken c++ code. i'm optimistic that xbmc will be a great place for me to host my own hacks!

the real trick will be the nature of the interfaces between xbmc and python. i'd love to be able to implement a new media streaming protocol, put stuff on the screen, write new ui options, etc.

gremlin
2004-01-03, 15:06
hey including python is very very cool... now i can dabble a little more :-) one question about what ya can n can't do with python on the xbmc.... can i..

1) write a program which plays a song (mp3) at a predefined time (ie an alarm clock ). if so, where's the best place to start? (ok oo knowledge / never looked @ python specifically)

thanks!

adrianmak
2004-01-09, 11:18
are all python functions call can be used on xbmc ?

darkie
2004-01-10, 19:47
yes, all functions are supported now (except the tk gui module).

1) write a program which plays a song (mp3) at a predefined time (ie an alarm clock ). if so, where's the best place to start? (ok oo knowledge / never looked @ python specifically)
you could use a timer for that, there is more info on that at www.python.org

and for the people that don't know yet, zlib is already available in the latest cvs version

alx5962
2004-01-11, 20:05
hi
first thank you for this wonderful port of python.
so i wanted to know if support for image files other than png is possible as i'm working on a program that retrieves a gif image on a website and so i cannot display it. otherwise how to convert a gif file to png?

thanks

alex

darkie
2004-01-11, 20:48
python uses the image library from xbmc which does support gif and other formats

alx5962
2004-01-11, 22:56
python uses the image library from xbmc which does support gif and other formats
sorry but i tried to load a gif image, but nothing came on screen. i used the windowexample.py code and replaced it with a gif *image at first to try if gif worked.but it didn't...

update: it works with jpg too so maybe there's a bug here ?
so if it's one i hope it will be fixed soon.
anyway, i'm very happy for now to be able to be able to use python on my xbox !

rayban
2004-01-12, 10:05
is it possible to call picture show or picture slideshow with python script?

cheers, :)

alx5962
2004-01-13, 11:02
so i decided to bypass the gif file for now and choose a jpg one.

do you plan to make a documentation available about the xmbc and xbmcgui librairies soon?

also, i'd like to know how to change font colours and if special effects on it are possible?

last question : it's not possible for now to add a button? from what i read here it was planned but not yet added but i may be wrong...

keep the good work!

darkie
2004-01-13, 20:58
there is a small txt file called python.txt in cvs\docs\ with some library information. and no, buttons are not supported yet.

alx5962
2004-01-14, 00:25
there is a small txt file called python.txt in cvs\docs\ with some library information. and no, buttons are not supported yet.
thank you very much for the info!

i'm very impatient to see buttons supported!
i've started to work hard on a meteo script but as i'm new to python it takes me a long time!

anyway, thank you again for your great work!

fonzi
2004-01-16, 09:42
is playing an m3u file supported or am i doing something wrong
with mediaplay()

regards,
fonzi

darkie
2004-01-16, 17:11
mediaplay can only be used to play a media file, you can't use it to open a playlist

Hullebulle
2004-01-16, 17:31
but you should be able to get the infos you need out of the m3u file with python i think.

darkie
2004-01-16, 19:16
but you should be able to get the infos you need out of the m3u file with python i think. that is what i suggested before :)

alx5962
2004-01-19, 15:28
hi darkie!
how do you type the colour hexstring for text? i tried '#ffffff' and without # too but no colour change, just no more text on screen ???
also i tried to use the black joypad button and so i i looked for the code in the keymal.xml file but it doesn't work, and i think i need a special label (like the show_more_info for the white button in windowexample). so tell me if i'm wrong or not http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/wink.gif

thanks

alex

cyberplague
2004-01-19, 18:38
what (python) libraries are available (i'm thinking specifically of xml parsers and xpath processors)?

if they are unavailible, what are my options as far as getting them included? ie write myself, import current libraries...etc

thanks for the great work, also i would like to help get some documentation up about xbmc as well as the python support. maybe a wiki? let me know.

cp

darkie
2004-01-20, 01:38
try 0xffffffff for white text, and 0xffff0000 for red text.
the first ff is for alpha and the next are for rgb.

as for the black joypad button. you could try the next.

*def onaction(self, action):
* *print('recieved action with number:' + str(action))

when you use the black button python will now print the action number to "scripts output". now, when you have that number you could use that to create your "label".

to cyberplague: a list of all python libraries avaiable is somewhere at http://www.python.org
the only library that is not supported by xbmc is the tk inter lib, which is used for drawing on screen.
if you need some other libraries, use google or something to find them. there are a lot of extra libraries available on the net.

alx5962
2004-01-20, 10:00
thank you very much darkie!

your help is really appreciated!

fonzi
2004-01-23, 10:11
ok , i parsed the playlist file, but how can i play all the files one after one.

this is the code, but it just plays the last file in the list


# loop until eof
for x in lines:
if x.find("#ext") == 0:
continue
print x
xbmc.mediaplay(x)


any sugestions how to program it

darkie
2004-01-23, 12:50
playing a file one after one is not possible atm. you would need access to the xbmc playlist from within python for that, which is not possible yet.

XDX
2004-01-25, 02:55
thanks for the idea... i made a simple python script to download current weather conditions and display them on your screen. *the ui isn't great, but it works.

#display weather forecast on your xbox


########enter your zip code###########
zipcode = '94025' * * * *


import sys, urllib, string, urlparse, re, xbmc, xbmcgui

#will parse out text between given tag
def parsexml( line, tag ):
* *result= re.search('<' + tag + '>.*' + tag + '>', line, re.dotall)
* *try:
* * * *if result.group(0):
* * * * * *mod = string.replace(result.group(0), '<' + tag + '>','')
* * * * * *mod = string.replace(mod, '</' + tag + '>', '')
* * * * * *mod = string.lstrip(mod)
* * * * * *return mod
* *except:
* * * *return


url = 'http://www.rssweather.com/rss.php?config=&forecast=zandh&zipcode=' + zipcode + '&alt=rss20a'
data = urllib.urlopen(url)
currentline= data.read()
itemdivide= string.split(currentline, '<item>')
place= parsexml(itemdivide[0], 'title')

i=1
items= len(itemdivide)
dayforecast=[]
forecast=[]

while i < items:
* *check=parsexml(itemdivide[i], 'category')
* *if check=="current conditions":
* * * *time=parsexml(itemdivide[i], 'pubdate')
* * * *ctemp=parsexml(itemdivide[i], 'description')
* *if check=="weather forecast":
* * * *forecast.append(parsexml(itemdivide[i],'descripti on'))
* * * *dayforecast.append(parsexml(itemdivide[i], 'title'))
* *i=i+1
* *
# now we have all the parts we need so display to the user

dialog= xbmcgui.dialog()
dayforecast.insert(0, 'exit')
dayforecast.insert(0, 'current temperature: ' + ctemp)
dayforecast.insert(0, 'information from: ' + time)
selected= dialog.select(place, dayforecast)
if selected < 3:
* *print 'quitting..'
else:
* *dialog.ok(dayforecast[selected],forecast[selected-3])
* * * * * * * * *

san
2004-01-25, 14:47
there is something called superkaramba for unix flavored os-es. it allows tiny (scripted) programs make your desktop more beautifull by adding things like clocks, systeminfo and weatherinfo on your desktop.

i'm not a python guru but i use this "liquid weather ++" script for superkaramba on my freebsd machine and it works great. it displays the weather in you own location (it's configurable through a gui) and it lools very nice. i don't have the time or the python knowledge to pick this up but perhaps someone else will.

check this url for screenshots and the files:
http://www.kde-look.org/content/show.php?content=6384

alx5962
2004-01-29, 12:14
hi!
i tried to use the onaction def out of a class (as the only way to interact is using the pad) but it crashed xbmc.
so i'm not sure what's the problem and any help would be welcome.

thanks

alex

alx5962
2004-02-02, 00:25
here is the code for my meteo script for france. i dedicate it to darkie as he was a huge help for me http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/wink.gif



import sys, urllib, re, xbmcgui, xbmc, os

baseurl = 'http://www.lachainemeteo.com/imageslcm/frannebp'
baseurl2 = 'http://www.lachainemeteo.com/imageslcm/frantmpp'

dossier = 'q:\\'
action_show_info = 11
action_stop = 13
action_previous_menu = 10

nomfichier = ''

print 'demarrage'

class window(xbmcgui.window):

def (self):
self.straction = xbmcgui.controllabel(100, 100, 200, 200, '', 'font13')
self.addcontrol(self.straction)
global compteur
compteur = 0

def onaction(self, action):
#print('recieved action with number:' + str(action))

if action == action_show_info:
global compteur
if compteur == 0:
print 'ajout compteur 1'
self.chargement('meteoja',0,'pm')
compteur = 1
elif compteur == 1:
print 'ajout compteur 2'
self.chargement('meteojb',1,'am')
compteur = 2
elif compteur == 2:
print 'ajout compteur 2'
self.chargement('meteojc',1,'pm')
compteur = 3

if action == action_stop:
self.sortir()

if action == action_previous_menu:
self.sortir()

def chargement(self,nomfile,journee,periode):
#self.straction.settext('chargement')
nomfichier = nomfile +'1'
global url
url = baseurl + str(journee) + periode + '.jpg'
self.downloadurl(url,nomfichier)
global localfile
localfile = dossier + nomfichier + ".jpg"
self.addcontrol(xbmcgui.controlimage(30,120,320,30 0, localfile))
nomfichier2 = nomfile +'2'
global url2
url2 = baseurl2 + str(journee) + periode + '.jpg'
self.downloadurl(url2,nomfichier2)
global localfile2
localfile2 = dossier + nomfichier2 + ".jpg"
self.addcontrol(xbmcgui.controlimage(345,120,330,3 00, localfile2))
self.supfichier(localfile)
self.supfichier(localfile2)


def sortir(self):
self.straction.settext('au revoir')
self.close()

def downloadurl(self,fichier,nom): * * * *
try:
loc = urllib.urlopener()
loc.retrieve(fichier, dossier + nom + ".jpg")
#print 'download ok'
#self.straction.settext('download ok')

except:
print 'erreur'
self.straction.settext('download failed')

def supfichier(self,fichier):
if os.path.isfile(fichier):
os.remove(fichier)
#print 'fichier sup'



########## main ##########
meteo = window()

c2 = xbmcgui.controllabel(300, 50, 200, 200, u'text', 'font14', '0xff0080c0')
c2.settext('prévisions météo')
meteo.addcontrol(c2)
c3 = xbmcgui.controllabel(260, 80, 200, 200, u'text', 'font14', '0xffff80c0')
c3.settext('offert par la chaine météo')
meteo.addcontrol(c3)
c4 = xbmcgui.controllabel(250, 440, 200, 200, u'text', 'font14')
c4.settext('touche blanche pour changer')
meteo.addcontrol(c4)
c5 = xbmcgui.controllabel(300, 480, 200, 200, u'text', 'font14')
c5.settext('back pour quitter')
meteo.addcontrol(c5)
c6 = xbmcgui.controllabel(260, 510, 200, 200, u'text', 'font14', '0xff666666')
c6.settext('code : alx5962@yahoo.com')
meteo.addcontrol(c6)

meteo.chargement('meteoj',0,'am')
meteo.domodal()
del meteo

alx5962
2004-02-03, 21:39
one more question darkie, i know i'm harrassing you :lol:
i just noticed only font13 and font14 works (i tried smaller ones but nothing on the screen then).
how can i use smaller fonts so?

thank you again !

alex

darkie
2004-02-03, 22:08
only fonts in cvs\skin\mediadir\fonts are supported
that is, font13, font14 and font64.

alx5962
2004-02-03, 22:54
only fonts in cvs\skin\mediadir\fonts are supported
that is, font13, font14 and font64.
thank u for the reply darkie!

darkie
2004-02-08, 01:42
you can't load external dll's (.pyd) yet. i'm busy with that atm.
only problem is that the dll has to be compiled for the xbox, and _sqllite.pyd is probably not.

darkie
2004-02-08, 02:36
darkie are you interested to see the scripts written using your python port?
sure, if you upload them to www.xboxmediaplayer.it/upload i will add them into cvs. this is the only way, cause there isn't a webpage for python scripts yet.


is there a tutorial to compile our own pyd for the xbox? as i really wish to see the pil library ported to our nice console

first i need to create some working examples myself before i can create a tutorial :) . another problem is that pil has to be ported to the xbox first (if it is needed) before you can create a pyd at all

alx5962
2004-02-10, 16:59
hi darkie!
i need your help again ???

i'd like to create a 'pop-up' like window and being able to close it to easily. but i have no idea if we are able to do it using xbmc and also how to do it :(

thank you again for your patience with me darkie :)

alx5962
2004-02-13, 18:15
i guess you have no time to reply to my previous post darkie...

i just noticed settext has to be named setlabel in the new cvs compile. the buttons are a great feature so i really have to include them in thefuture.

if you want to see of one my scripts, check the french tv guide here:
tv guide france (http://friends59.free.fr/python/progtvfrance.zip)

darkie
2004-02-14, 19:51
you can't create custom dialogs (if that is what you mean?)

what you can do is create a new window and close it after pressing "ok?". after pressing ok the window will be destroyed and you will automaticly return to the old window.

just tried your script, very nice.. to bad it is only useful for france :)

alx5962
2004-02-15, 01:13
thank you darkie, without your help i wwould never have started to work on scripts and even learnt python in fact. so thank you again for all!
your idea about the dialog window is very nice, i was more on a new window idea but the dialog could fit well for my need

:d

alx5962
2004-02-15, 23:17
darkie, i just noticed sometimes when a python script crash, xbmc is totally frozen and so i need to restart the xbox.
is this a known bug?

and what do you think about adding a debug log for python? so it would be easier to know where is the problem when the script crashes the xbox.

darkie
2004-02-16, 00:13
darkie, i just noticed sometimes when a python script crash, xbmc is totally frozen and so i need to restart the xbox.
is this a known bug?

if python crashes xbmc will crash to, can't do anything about that. but python shouldnt crash at all *:d

and what do you think about adding a debug log for python? so it would be easier to know where is the problem when the script crashes the xbox.

good idea. will do that.

Kieren
2004-02-18, 19:51
import xbmc, xbmcgui

dialog = xbmcgui.dialog()

list = ['kieren','nickname2','nickname3','nickname4', 'other...']
selected = dialog.select('rename xbox', list)
if selected != -1:
if selected == len(list)-1: list[selected] = 'osk'
if dialog.yesno('rename xbox', 'are you sure you want to rename your xbox', list[selected]):
nickname = open("e:\\udata\\nickname.xbn","w")
nickname.write('\x08\xe0\xac\x0f')
for character in list[selected]:
nickname.write(character + '\x00')
remainingbytes = range(0, 3400 - len(list[selected])*2 - 4)
for count in remainingbytes: nickname.write('\x00')
nickname.close()


is there or will there be any support for the on screen keyboard so i could add a custom names option to the above code?

alx5962
2004-02-18, 22:54
hi darkie!
i just created a new script that reads the google news (every countries work) and display them by categories.
i would be honoured if you accept to be a beta tester for it :d

darkie
2004-02-19, 20:19
is there or will there be any support for the on screen keyboard so i could add a custom names option to the above code?
no. but i can always have a look at it to add it.

darkie,
are you planning to modify the windowexample script soon?
as some functions are not documented like :
setnavigation, removecontrol, setfocus for the window object are not very clear for me and the example is the only way to have infos about how to use them...

no don't have it planned :) . but what still needs to be done is writing better documentation for python (there is none currently).
but since i don't have time at all now, i can't add/create any new code / documentation for python.
maybe someone else is willing to make a start at this?

also, in my script i'm doing a dirty thing : i just add one more controlimage over the previous one to erase the screen in the same class. it uses memory for nothing so and it's too dirty. so how can i do that please?
you can use removecontrol to remove all the controls.
you can also delete the window and create it again to start with a new clean window.

Kieren
2004-02-19, 20:42
cool, thanks

btw i just made a dvd ripper if anyones interested

edit: i'll upload it to cvs

alx5962
2004-02-19, 21:32
thank you darkie!
i figured out how to use removecontrol and it works very nicely now!

do you have an email where i can send you my scripts?

Gamester17
2004-02-20, 12:39
script can be uploaded in file format here (upload url link) (http://www.xboxmediaplayer.it/upload) (please compress the script file/s with zip or rar before upload, thx)

alx5962
2004-02-20, 12:44
hi
i uploaded one of my script (tvguide) last week there and it's not in the cvs... also how to update them once they are uploaded?

bobrooney_78
2004-02-20, 14:17
where can i get these scripts?

i am just curious how they work.

alx5962
2004-02-20, 14:29
check the scripts included in the cvs on sourceforge.
mine are not available yet

Zinger
2004-02-22, 17:26
should this work? or am i doing something wrong?
xbmc.player().play("http://www.somesite.com/playlist.pls")
this does not seem to work for me either
xbmc.player().play("q:/scripts/playlist.pls")

or should i use
xmbc.playlist().play



thanks,
brian

Kieren
2004-02-22, 19:19
never used a playlist but if you apply the same to an mp3 file it only works using \\ rather than /

xbmc.player().play("q:\\scripts\\playlist.pls")

as for playing a playlist on the web you have to download it first, look up some of the examples on how to do this or ask and i'll post one

Zinger
2004-02-23, 04:21
xbmc.player().play("q:\\scripts\\playlist.pls")

does not work either. no error is generated, just does not play. the only thing i've gotten to work is playing the actual stream. also how should i handle playing a different stream. stop the first.

xbmc.player().stop() or something
and then play new stream

i'm having issues with subsequent play requests hanging.

thanks for the info.

Kieren
2004-02-23, 15:15
when you play a new track, the one already playing will stop.

if you want to play the next track in a playlist you can use

xbmc.player().playnext()

edit: tried the code with playlists, it didn't cause an error but also didn't play the playlist. the python readme suggests you might have to create a playlist object which you can then play using the play() function but i've never tried it

darkie
2004-02-23, 19:04
just a quick reply, playlist support in python is written but i did not have the time yet to test / complete it. this is the first thing i'll do when i have some time left for xbmc

would it be possible to include a version number in the future releases? as you added more (nice) features in the latest versions but some scripts don't work anymore. and so with a version number we could alert people their python version is too old to run the script.

will do that.

burriko
2004-02-26, 15:27
i've been trying to close a script using sys.exit(), but it just seems to freeze xbmc. is this a known issue?

is there another way to stop a python script during execution?

alx5962
2004-02-26, 15:35
i've been trying to close a script using sys.exit(), but it just seems to freeze xbmc. *is this a known issue?

is there another way to stop a python script during execution?
del <name of the class> should work
or close() if you are using the xbmc library

darkie
2004-02-26, 15:55
i've been trying to close a script using sys.exit(), but it just seems to freeze xbmc. *is this a known issue?
known issue and it is not a bug. sys.exit() just exits the process in which the script is currently running, and since xbmc and python are both running in the same process xbmc will freeze to.

and you don't have to exit scripts, it is all done automaticly. but it would be nice to clean up everything that is used in the script with del in the end

burriko
2004-02-26, 16:14
thanks for the replies. xbmc.close() did the trick.

Zinger
2004-03-03, 08:22
i was wondering about dummy "imports" that would just print a list instead of displaying the xmbcgui selection dialog, for example. or even wrap an existing windows python dialog.

anyway i'd more appreciate help with a script thats driving me mad. i'm scraping info from shoutcast and presenting in selection dialogs genres/stations and finally retrieving the audio stream from a pls and passing to xmbc. it's only pulling info from selections made not leaching the whole site at once. this all works but after repeated url requests, network response times slow, current playing song starts skipping. then i start to receive socket read errors and have to recycle xmbc to get network moving again. any suggestions?

url code:


req = urllib2.request(url)
req.add_header('authorization', 'basic ')
try:
progress.create("attempting to connect to:\n %s" % url)
time.sleep(2)
urlhandle = urllib2.urlopen(req)
remotedata = urlhandle.read()
urlhandle.close()
return remotedata


thanks,
brian

Zinger
2004-03-04, 01:00
network will eventually start working again if i wait a long time. i'm wondering if there is something else i can do to close the socket connection. i tried adding:


timeout = 20.0
socket.setdefaulttimeout(timeout)


but i does not seem to improve things.

thanks,
brian

of python: the indentation was killing me at first but i'm liking it now. no more hunts for missing braces :}

alx5962
2004-03-05, 21:09
scripts page (in french) (http://www.gueux.net/xbmc-scripts/index.html)

the google script works with english news too, just edit the script!

gaogao
2004-03-08, 11:16
very interesting and promising news here...

btw, wouldn't it be more convenient to have a stand-alone python interpreter, i.e. not needing to get in xbmc to execure phyton code? would it be difficult to separate from xbmc so that we can run a .py from whatever dashboard?

gg

alx5962
2004-03-08, 21:07
my scripts (http://www.gueux.net/xbmc-scripts/index.html)

the bit-torrent client is here, and an english doc included too :)

contrast
2004-03-09, 12:06
this is really great alx !! thanks !

now i have some additions, it would so rock if you could script it..

#1.the updating of the downloading, is it possible to have it sticky somewhere like the red "recording", so that i dont have to go all the way into settings/script/blablabla and press info, then i'm watching a movie or listening to some music..

maybe it should be just under "rec", so that when i record a song, i see them both with the same color (?)
oh man that would be so cool !

#2.it would be great if the bandwidth would update everytime it downloads 10 kb or so.

#3.is it possible to make a bittorrent fileselector so that i don't have to edit the source in the script itself ?

burriko
2004-03-11, 12:21
alx5962 - it might be a good idea to start a new thread about your bittorent client, as this thread has been pulled off topic quite a bit.

btw, can i pm you the link to a nice menu i made for it that makes it really easy to download the last tv show episodes, you could include it in the bitxbox package. i don't want to post it here because i don't think the mods will like it as it links to a torrent site that distributes copyrighted material.

alx5962
2004-03-11, 15:36
bit torrent update (http://www.gueux.net/xbmc-scripts/)

read the readmexbox !

silentyl
2004-03-12, 06:50
nice work with the bt script ...i can just use the .torrent file i've downloaded...by #'ing the other source line instead

a question..is it normal to have sevel pages of output..or is it possible to just use 1 page and refresh it over and over...or maybe press "black button" for just current results like:

upspeed, downspeed, upmb, downmb, % complete

LaSnow
2004-03-23, 16:40
none of my scripts are not working, debug says: os module missing, or something like that.
i didnt install phyton last time i just extracted whole phyton (phyton.rar) in a dir and it was working fine. suddently it stopped working. how do i reinstall ? *i erased everything again and started from scrath but it still say the same.
"no os module" . looked on phyton www but didnt find any answers there.
im a total newbe. how do i reinstall phyton? *please help me, im going nuts, nothing works.

may-day may-day, sos : *ladies and gentlemen, we are about to krash and burn * :(

burriko
2004-03-29, 18:49
is there currently any way to get details about the current song that is playing? i've tried the getdescription(), getduration(), getfilename() methods but they seem to only work if you're creating a playlist in python. i don't want to influence what's being played just find out details about what xbmc is currently playing.
the reason i'm interested in this is that i was going to attempt to write an audioscrobbler (http://www.audioscrobbler.com) plugin, but i'd need to know the title, artist, total length and current position of the currently playing song in xbmc.
could this info be made available to python?

thank you.

alx5962
2004-04-08, 14:26
hi darkie,
working on the documentation i have some requests/questions.

the function getskindir() only returns the skin dir name, but without path. it 's not a real problem except now skins handle pal/ntsc screen size. so maybe it could be nice to know these infos... but this is not a very important thing at all for now.
also i 'd like to know the progress status of the xbox version management of python.

regards

alex

darkie
2004-04-09, 16:12
the function getskindir() only returns the skin dir name, but without path. it 's not a real problem except now skins handle pal/ntsc screen size. so maybe it could be nice to know these infos... but this is not a very important thing at all for now.
ok, will see what i can do, not much time now so don't expect anything new this week
also i 'd like to know the progress status of the xbox version management of python.
no progress has been made for it. will look at it asap, shouldn't be to hard to just add a method like getpythonversion() or so