2006-05-30, 22:15
i'm new at python & i'm having trouble getting xbmc to play streams from my dbox. i've had output of a stream for about 1-2 secs and then it stops. it never displays full screen only in a box on the left at the bottom.
Quote:# dbox2xbox tv viewer ver 0.1
# ------------------------------------------------------------------------------
# import libraries
import urllib
import xbmc, xbmcgui
# ------------------------------------------------------------------------------
# set dbox2 ip address
dboxip = '192.168.1.24'
port = '31339'
# ------------------------------------------------------------------------------
# setup glabal varibles for dbox web server pages
channellist_page = 'http://' + dboxip + '/control/channellist'
zapto_page = 'http://' + dboxip + '/control/zapto?'
pid_page = 'http://' + dboxip + '/control/zapto?getpids'
epg_page = 'http://' + dboxip + '/control/epg?id='
# setup varibles for use with function get_dboxinfo(s)
info_page = 'http://' + dboxip + '/control/info'
getonidsid_page = 'http://' + dboxip + '/control/getonidsid'
getdate_page = 'http://' + dboxip + '/control/getdate'
gettime_page = 'http://' + dboxip + '/control/gettime'
rawtime_page = 'http://' + dboxip + '/control/gettime?rawtime'
start_stream = 'http://' + dboxip + '/control/zapto?startplayback'
stop_stream = 'http://' + dboxip + '/control/zapto?stopplayback'
stream_status = 'http://' + dboxip + '/control/zapto?statusplayback'
# ------------------------------------------------------------------------------
# define function get_dboxinfo(s) s = webpage to be returned
def get_dboxinfo(s):
# get web page /control/info from dbox.
f = urllib.urlopen(s)
# read from the object, return the page's contents in 'temp_info'.
temp_info = f.read()
f.close()
return temp_info.rstrip('\n')
# ------------------------------------------------------------------------------
# define function get_channels(s) s = dbox control/channels page link
def get_channels(s):
# create temp arrays
channels_unsplit = []
channels_splitup = []
# get web page /control/channellist from dbox.
f = urllib.urlopen(s)
# read from the object, return the page's contents in 'channel_splitup'.
for line in f:
channels_unsplit.append(line.rstrip('\n'))
f.close()
for x in channels_unsplit[:]:
channels_splitup.append(x.split(" ", 1))
return channels_splitup
# ------------------------------------------------------------------------------
# define function change_channel (http://dboxip/control/zapto)
def change_channel(s): # s = channel number not id
chid = channels[s][0]
# get web page /control/info from dbox.
f = urllib.urlopen(zapto_page + chid)
# read from the object, storing the page's contents in 'temp_status'.
temp_status = f.read()
f.close()
return temp_status.rstrip('\n')
# ------------------------------------------------------------------------------
# define function get_pid (http://dboxip/control/zapto)
def get_pids(): # s = channel number not id
temp_pid = []
# get web page /control/info from dbox.
f = urllib.urlopen(pid_page)
# read from the object, storing the page's contents in 'temp_status'.
for line in f:
if line <> '\n':
temp_pid.append(line.rstrip('\n'))
f.close()
return temp_pid
# ------------------------------------------------------------------------------
# define function restart_sectionsd(http://dboxip/control/zapto)
def restart_sectionsd():
# get web page /control/zaopto from dbox and stop sectionsd.
f = urllib.urlopen(zapto_page + 'stopsectionsd')
temp_status = f.read()
f.close()
# get web page /control/zaopto from dbox and start sectionsd.
f = urllib.urlopen(zapto_page + 'startsectionsd')
temp_status = f.read()
f.close()
return temp_status.rstrip('\n')
# ------------------------------------------------------------------------------
# define function get_epg(http://dboxip/control/epg)
def get_channelepg(s): # s = channel number not id
chid = channels[s][0]
epginfo_unsplit = []
epginfo_splitup = []
# get web page /control/info from dbox.
f = urllib.urlopen(epg_page + chid)
# read from the object, storing the page's contents in 'temp_status'.
for line in f:
if line <> '\n':
epginfo_unsplit.append(line.rstrip('\n'))
f.close()
linecount = 0
listcount = -1
for x in epginfo_unsplit[:]:
linecount = linecount + 1
if linecount <> 1:
epginfo_splitup.append(x.split(" ", 0))
if linecount == 3:
linecount = 0
else:
epginfo_splitup.append(x.split(" ", 2))
# search through list epg, get current & next programme
found = 0
listcount = 0
search_rawtime = get_dboxinfo(rawtime_page)
epg_return = []
while found == 0:
if int(search_rawtime) >= int(epginfo_splitup[listcount][1]) and int(search_rawtime) <= (int(epginfo_splitup[listcount][1]) +
int(epginfo_splitup[listcount][2])):
epg_return.append(epginfo_splitup[listcount])
epg_return.append(epginfo_splitup[listcount + 1])
epg_return.append(epginfo_splitup[listcount + 2])
epg_return.append(epginfo_splitup[listcount + 3])
epg_return.append(epginfo_splitup[listcount + 4])
epg_return.append(epginfo_splitup[listcount + 5])
found = 1
listcount = listcount + 3
return epg_return
# ------------------------------------------------------------------------------
# define function setup_channel
def setup_stream(s): # s = channel number not id
playback_stop = get_dboxinfo(stop_stream)
change = change_channel(s)
playback_start = get_dboxinfo(start_stream)
pids = get_pids()
httplink = 'http://' + dboxip + ':' + port +'/' + hex(int(pids[0]))[2:] + ',' + hex(int(pids[1]))[2:]
return httplink
# ------------------------------------------------------------------------------
#
# xbmc program
#
channels = get_channels(channellist_page)
class dboxtv(xbmcgui.windowdialog):
def (self):
self.setcoordinateresolution(6)
self.bg = xbmcgui.controlimage(158,25,520,500, 'panel2.png')
self.addcontrol(self.bg)
self.header = xbmcgui.controllabel(320,95,255,25, "dbox tv viewer", 'font14', '0xffffffff')
self.addcontrol(self.header)
self.list = xbmcgui.controllist(190,130,400,320)
self.addcontrol(self.list)
self.setfocus(self.list)
for x in channels:
listitem = xbmcgui.listitem()
listitem.setlabel(x[1])
self.list.additem(listitem)
def oncontrol(self, control):
if control == self.list:
self.position = self.list.getselectedposition()
self.removecontrol(self.bg)
self.removecontrol(self.list)
self.removecontrol(self.header)
xbmc.player(xbmc.player_core_mplayer).play(str(setup_stream(self.position)))
self.close()
dbox = dboxtv()
dbox.domodal()
del dbox