Help - Dbox2Xbox TV Viewer
#1
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
Reply
#2
i know i should have added more info, but i was going round in circles. it turned out that the script worked fine with older version of xbmc, but it has trouble the with xbmc 28-05-2006 t3ch. xbmc fills the cache plays it and when it runs out i guess it stops. also i had to play the file with xbmc.executebuiltin that seemed more stable way of starting the stream without crashing xbmc.
Reply
#3
hi fultotop,
your script looks intresting. but i could not get it to work with my dbox. switching channles works fine, but the stream is not starting. do you have a working version?

thanks,
scooba
Reply
#4
this version works fine, apart from the script locks up after switching channels a number of times. the epg works by pressing info button on remote or y button.

currently having trouble with version 0.15, the latest version can switch between tv mode and radio on the dbox. though when selecting a radio station it locks up or just doesn't play it. does xbmc support playing pes audio streams?

the version of xbmc i'm using is 11-06-06 t3ch

Quote:# dbox2xbox tv viewer ver 0.14c
# ------------------------------------------------------------------------------
# import libraries
import urllib, time
import xbmc, xbmcgui
# ------------------------------------------------------------------------------
# set dbox2 ip address
dboxip = '192.168.1.24'
port = '31337'
# ------------------------------------------------------------------------------
# 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?ext'
chepg_page = 'http://' + dboxip + '/control/epg?id='
timer_page = 'http://' + dboxip + '/control/timer'
# 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'
record_stop = 'http://' + dboxip + '/control/setmode?record=stop&stopplayback=false'
record_start = 'http://' + dboxip + '/control/setmode?record=start&stopplayback=false'
reboot_dbox = 'http://' + dboxip + '/control/reboot'
standby_on = 'http://' + dboxip + '/control/standby?on'
standby_off = 'http://' + dboxip + '/control/standby?off'
lcd_disp_on = 'http://' + dboxip + '/control/lcd?lock=1&clear=1&xpos=8&ypos=37&size=20&font=2&text=xbmc dbox2xbox&update=1l'
lcd_disp_off = 'http://' + dboxip +'/control/lcd?lock=0'
start_spts = 'http://' + dboxip +'/control/system?setaviaextplayback=spts'
# xbmc user interface
action_unknown = 0
action_y_button = 34
action_select_item = 7
action_b_button = 9
action_previous_menu = 10
action_show_info = 11
action_pause = 12
action_stop = 13
action_display = 18
action_play = 79
# ------------------------------------------------------------------------------
# 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_pids (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_dboxepg(): # s = channel number not id

epginfo_unsplit = []
epginfo_splitup = []
epg_return = []

# get web page /control/info from dbox.
f = urllib.urlopen(epg_page)

# 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()

for x in epginfo_unsplit[:]:
epg_return.append(x.split(" ", 4))

return epg_return
# ------------------------------------------------------------------------------
# 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(chepg_page + chid)

# read from the object, storing the page's contents in 'temp_status'.
linecount = 0
for line in f:
linecount = linecount + 1
if linecount == 1:
data1 = line.rstrip('\n')
if linecount == 2:
data2 = line.rstrip('\n')
if linecount == 3:
data3 = line.rstrip('\n')
if linecount == 4:
data4 = line.rstrip('\n')
if linecount == 5:
data5 = line.rstrip('\n')
new_rec = data1.split(" ", 2), data2, data4
epginfo_unsplit.append(new_rec)
linecount = 0
f.close()

# search through list epg, get programmes after current time
epg_return = []
search_rawtime = int(get_dboxinfo(rawtime_page))

for x in epginfo_unsplit:
programme_finishtime = int(x[0][1]) + int(x[0][2])
if programme_finishtime >= search_rawtime:
epg_return.append(x)

return epg_return
# ------------------------------------------------------------------------------
# define function setup_channel this function sets up the dbox ready to stream
def setup_stream(s): # s = channel number not id

# stop dbox2 stream
stream = get_dboxinfo(stop_stream)
# change dbox2 channel
change = change_channel(s)
# start dbox2 stream
stream = get_dboxinfo(start_stream)
# get channel pids from dbox2
pids = get_pids()

# generate link and store in varible httplink
httplink = str('http://' + dboxip + ':' + port +'/' + hex(int(pids[0]))[2:] + ',' + hex(int(pids[1]))[2:])
return httplink
# ------------------------------------------------------------------------------
# define function search_storedepg
def search_storedepg(s): # s = channel number not id

on_now = 'no epg found'
chid = channels[s][0]

for x in epg[:]:
if x[:][0] == chid:
duration = int(x[:][2]) / 60
already_gone = (int(rawtime) - int(x[:][1])) / 60
on_now = str(x[:][4]) + ' - ' + str(already_gone) + '/' + str(duration) + ' mins'

return str(on_now)
# ------------------------------------------------------------------------------
# define function get_currchannel returns current channel number
def get_currchannel():

ch_count = -1
chid = get_dboxinfo(getonidsid_page)

for x in epg[:]:
ch_count = ch_count + 1
if x[:][0] == chid:
on_now = ch_count

return int(on_now)
# ------------------------------------------------------------------------------
#define function get_recordlink returns link to record program
def get_reclink(s, p):

search_epg = get_channelepg(s)
channelname = str(channels[s][1])
channelid = str(channels[s][0])
programmeinfo = str(search_epg[p][1])
start_time = int(search_epg[p][0][1])
end_time = int(search_epg[p][0][1]) + int(search_epg[p][0][2])
announce_time = int(search_epg[p][0][1]) - (5 * 60)
programmeinfo = time.ctime(start_time)[11:][:5] + '-' + time.ctime(end_time)[11:][:5] + ' - ' + str(search_epg[p][1])

reclink = timer_page + '?action=new&alarm=' + str(start_time) + '&stop=' + str(end_time) + '&announce=' + str(announce_time) + '&type=5&rep=0' + '&channel_id=' + str(channelid)

return reclink
# ------------------------------------------------------------------------------
# define xbmc function display_programme - records program from epg
def display_programme(s, p): # s = channel number, p = epg number

search_epg = get_channelepg(s)
channelname = str(channels[s][1])
programmeinfo = str(search_epg[p][1])
start_time = int(search_epg[p][0][1])
end_time = int(search_epg[p][0][1]) + int(search_epg[p][0][2])
programmeinfo = time.ctime(start_time)[11:][:5] + '-' + time.ctime(end_time)[11:][:5] + ' - ' + str(search_epg[p][1])
programmedetails = str(search_epg[p][2])

class programmeinfo(xbmcgui.windowdialog):

def (proginfo):
proginfo.channelname = str(channels[s][1])
proginfo.headertext = str('programme info')
proginfo.setcoordinateresolution(6)
proginfo.bg = xbmcgui.controlimage(180,85,520,370, 'panel2.png')
proginfo.addcontrol(proginfo.bg)
proginfo.header = xbmcgui.controllabel(352,136,255,25, proginfo.headertext, 'font12', '0xffffffff')
proginfo.addcontrol(proginfo.header)
proginfo.channel_name = xbmcgui.controllabel(215,205,255,25, channelname, 'font12', '0xffffffff')
proginfo.addcontrol(proginfo.channel_name)
proginfo.programme_name = xbmcgui.controllabel(215,225,375,25, programmeinfo, 'font12', '0xffffffff')
proginfo.addcontrol(proginfo.programme_name)
proginfo.textbox = xbmcgui.controltextbox(215,265,375,151, 'font12', '0xffffffff')
proginfo.addcontrol(proginfo.textbox)
proginfo.textbox.settext(programmedetails)

def onaction(proginfo, action):

if action == action_previous_menu or action == action_b_button:
proginfo.removecontrol(proginfo.bg)
proginfo.removecontrol(proginfo.header)
proginfo.close()

info_on = programmeinfo()
info_on.domodal()
del info_on
# ------------------------------------------------------------------------------
# define xbmc function yesno dialog box
def yes_no(title, message):
dialog = xbmcgui.dialog()

if dialog.yesno(title, message):
return 'yes'
else:
return 'no'
# ------------------------------------------------------------------------------
# define xbmc function display_channel_epg - records program from epg
def display_channel_epg(s): # s = channel number not id

highlighted_channel = str(channels[s][1])
class whatson(xbmcgui.windowdialog):

def (chepg):
chepg.curr_epg = get_channelepg(s)
chepg.setcoordinateresolution(6)
chepg.bg = xbmcgui.controlimage(158,25,520,500, 'panel2.png')
chepg.addcontrol(chepg.bg)
chepg.header = xbmcgui.controllabel(325,95,255,25, highlighted_channel, 'font14', '0xffffffff')
chepg.addcontrol(chepg.header)
chepg.list = xbmcgui.controllist(190,130,400,320)
chepg.addcontrol(chepg.list)
chepg.setfocus(chepg.list)

for x in chepg.curr_epg:
listitem = xbmcgui.listitem()
start_time = int(x[0][1])
end_time = int(x[0][1]) + int(x[0][2])
listitem.setlabel(time.ctime(start_time)[11:][:5] + '-' + time.ctime(end_time)[11:][:5] + ' - ' + x[1])
chepg.list.additem(listitem)

def onaction(chepg, action):
if action == action_select_item:
chepg.record = yes_no('record', chepg.curr_epg[chepg.list.getselectedposition()][1])
if chepg.record == 'yes':
record_http = get_reclink(s, chepg.list.getselectedposition())
send_dbox2 = get_dboxinfo(record_http)

if action == action_show_info or action == action_y_button:
show_programme = display_programme(s, chepg.list.getselectedposition())

if action == action_previous_menu or action == action_b_button:
chepg.removecontrol(chepg.bg)
chepg.removecontrol(chepg.list)
chepg.removecontrol(chepg.header)
chepg.close()

show_epg = whatson()
show_epg.domodal()
del show_epg
# ------------------------------------------------------------------------------
# global varibles used in functions for channels & epg
channels = get_channels(channellist_page)
epg = get_dboxepg()
rawtime = get_dboxinfo(rawtime_page)
highlighted_channel = ''
highlight_position = 0
# ------------------------------------------------------------------------------
# xbmc part of code program

# turn message on dbox2
change_lcd = get_dboxinfo(lcd_disp_on)
start_spts = get_dboxinfo(start_spts)

# define dboxtv class
class dboxtv(xbmcgui.window):
def (self):
self.setcoordinateresolution(6)
self.bg = xbmcgui.controlimage(0,0,720,576, 'background.png')
self.addcontrol(self.bg)
self.header = xbmcgui.controllabel(75,67,255,25, "dbox2xbox tv viewer 0.14", 'font13', '0xffffffff')
self.addcontrol(self.header)
self.list = xbmcgui.controllist(212,130,455,416)
self.addcontrol(self.list)
self.setfocus(self.list)
self.display = 0

epg_count = -1

for x in channels:
epg_count = epg_count + 1
on_now = search_storedepg(epg_count)
listitem = xbmcgui.listitem()
listitem.setlabel(x[1] + ' - ' + on_now)
self.list.additem(listitem)

def onaction(self, action):

if action == action_previous_menu or action == action_b_button:
self.removecontrol(self.bg)
self.removecontrol(self.list)
self.removecontrol(self.header)
self.close()

if action == action_select_item:
self.stream_playing = xbmc.player().isplaying()
if self.stream_playing == 1:
xbmc.player().stop()
self.position = self.list.getselectedposition()
self.stream = setup_stream(self.position)
xbmc.player().play(self.stream)

if action == action_show_info or action == action_y_button:
display_epg = display_channel_epg(self.list.getselectedposition())

dbox = dboxtv()
dbox.domodal()
# turn lcd off
change_lcd = get_dboxinfo(lcd_disp_off)
del dbox



Reply

Logout Mark Read Team Forum Stats Members Help
Help - Dbox2Xbox TV Viewer0