Kodi Community Forum
Python Scripts Development - 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: Python Scripts Development (/showthread.php?tid=2045)

Pages: 1 2 3 4 5 6 7 8


- Cyan - 2003-11-28

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


- febs - 2003-11-28

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


- Nickman - 2003-11-30

(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


- fonzi - 2003-12-01

(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


- Cyan - 2003-12-02

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


- Hullebulle - 2003-12-03

thanx for the sample cyan. Smile


- kraqh3d - 2003-12-03

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


- cyberplague - 2003-12-03

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/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

how powerful python script can be developed used on xbox ?


- Hullebulle - 2003-12-21

(adrianmak @ dec. 21 2003,10:59 Wrote:how powerful python script can be developed used on xbox ?
what?


- Kuranes - 2003-12-22

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

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

are all python functions call can be used on xbmc ?


- darkie - 2004-01-10

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


- alx5962 - 2004-01-11

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