• 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 10
Python Inside
#46
(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
  • ASRock ION 330 OpenELEC XBMC Frodo.
  • 47" LG HDTV1080p, AC3/DTS Receiver.
  • 96" Epson LCD 1080p projector
  • 2x Raspbery Pi with XBMC
#47
(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
#48
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 <[email protected]>
# permission to copy granted so long as this copyright notice remains.
# email the author <[email protected]> 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 :)
#49
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!
#50
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 xbins 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.
#51
just did another update to python.

actions are now send to a window created with python. this means that when you press back on your remote control, the script will recieve action_previous_menu which is defined in keymap.xml.

i have updated windowexample.py to give you some idea.
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.


Image
#52
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
#53
darkie, should the zlib module be working? i get the error "importerror: no module named zlib" when trying to import it.

thanks.
#54
zlib isn't added to python yet.
but it is on my todo list.

darkie
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.


Image
#55
how powerful python script can be developed used on xbox ?
#56
(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!
#57
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.
#58
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!
#59
are all python functions call can be used on xbmc ?
#60
yes, all functions are supported now (except the tk gui module).

Quote: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 http://www.python.org

and for the people that don't know yet, zlib is already available in the latest cvs version
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.


Image
  • 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 10

Logout Mark Read Team Forum Stats Members Help
Python Inside0