Python Scripts Development

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Cyan Offline
Junior Member
Posts: 4
Joined: Nov 2003
Reputation: 0
Thumbs Up    Post: #31
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. Smile i look forward to seeing what else will come of xbmc.

--cyan
find quote
febs Offline
Senior Member
Posts: 199
Joined: Oct 2003
Reputation: 0
Post: #32
Quote: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
find quote
Nickman Offline
Fan
Posts: 468
Joined: Oct 2003
Reputation: 0
Location: Sweden
Post: #33
(darkie @ nov. 30 2003,19:21 Wrote: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 Smile

so it won't be a waste of time. [Image: wink.gif]

  • Xbox v1.3, 64MB, 120GB HD.
  • ASRock ION 330 Ubuntu XBMC.
  • 40" HDTV 720p, AC3/DTS Receiver.
Read the xbmc online-manual, faq and search the forums before posting.
find quote
fonzi Offline
Junior Member
Posts: 9
Joined: Oct 2003
Reputation: 0
Post: #34
(cyan @ nov. 28 2003,09:12 Wrote: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
find quote
Cyan Offline
Junior Member
Posts: 4
Joined: Nov 2003
Reputation: 0
Post: #35
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.

Quote:#
# 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 :)
find quote
Hullebulle Offline
Posting Freak
Posts: 1,966
Joined: Sep 2003
Reputation: 0
Post: #36
thanx for the sample cyan. Smile

read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
find quote
kraqh3d Offline
Retired Developer
Posts: 7,183
Joined: Dec 2003
Reputation: 4
Location: New York City, USA
Post: #37
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 Smile

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:]

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
cyberplague Offline
Member
Posts: 68
Joined: Nov 2003
Reputation: 0
Post: #38
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:

Quote:##############################################################################
# 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/...vclient.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
find quote
adrianmak Offline
Junior Member
Posts: 13
Joined: Dec 2003
Reputation: 0
Post: #39
how powerful python script can be developed used on xbox ?
find quote
Hullebulle Offline
Posting Freak
Posts: 1,966
Joined: Sep 2003
Reputation: 0
Post: #40
(adrianmak @ dec. 21 2003,10:59 Wrote:how powerful python script can be developed used on xbox ?
what?

read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
find quote
Post Reply