2006-06-20, 20:14
here 's my dbox2xbox 0.15 script
done :
channel list
stream channels
epg
set timers
delete timers
switch between tv & radio mode
restart dbox, sectonsd
lock & unlock lcd
to fix:
i carn't get xbmc to play the radio mode channels they use a pes stream, not sure if it's the script or xbmc.
done :
channel list
stream channels
epg
set timers
delete timers
switch between tv & radio mode
restart dbox, sectonsd
lock & unlock lcd
to fix:
i carn't get xbmc to play the radio mode channels they use a pes stream, not sure if it's the script or xbmc.
Quote:# dbox2xbox tv viewer ver 0.15
# ------------------------------------------------------------------------------
# import libraries
import urllib, time
import xbmc, xbmcgui
# ------------------------------------------------------------------------------
# set dbox2 ip address
dboxip = '192.168.1.24'
# ------------------------------------------------------------------------------
# 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'
get_mode = 'http://' + dboxip + '/control/getmode'
setmode_radio = 'http://' + dboxip + '/control/setmode?radio'
setmode_tv = 'http://' + dboxip + '/control/setmode?tv'
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'
start_pes = 'http://' + dboxip +'/control/system?setaviaextplayback=pes'
# 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
action_left = 1
action_right = 2
# ------------------------------------------------------------------------------
# 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 get_timer(s) s = dbox control/channels page link
def get_timer(s):
# create temp arrays
timer_unsplit = []
timer_splitup = []
# get web page /control/timer from dbox.
f = urllib.urlopen(s)
# read from the object, return the page's contents in 'timer_splitup'.
for line in f:
timer_unsplit.append(line.rstrip('\n'))
f.close()
for x in timer_unsplit[:]:
timer_splitup.append(x.split(" ", 7))
return timer_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
change = change_channel(s)
pids = get_pids()
if get_dboxinfo(get_mode)[:2] == 'tv':
httplink = str('http://' + dboxip + ':31337/' + hex(int(pids[0]))[2:] + ',' + hex(int(pids[1]))[2:])
else:
httplink = str('http://' + dboxip + ':31338/' + 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_channelnumber returns current channel number
def get_channelnumber(s): # s = channel id not number
ch_count = -1
for x in epg[:]:
ch_count = ch_count + 1
if x[:][0] == s:
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 function get_timer_programme returns program name to specific timer
def get_timer_programme(s): # s = channel id not number
chann_no = get_channelnumber(s)
guide = get_epg(chann_no)
print guide
programme_name = ''
return programme_name
# ------------------------------------------------------------------------------
# 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.bg = xbmcgui.controlimage(200,85,520,370, 'panel2.png')
proginfo.addcontrol(proginfo.bg)
proginfo.header = xbmcgui.controllabel(380,138,255,25, proginfo.headertext, 'font12', '0xffffffff')
proginfo.addcontrol(proginfo.header)
proginfo.channel_name = xbmcgui.controllabel(230,205,255,25, channelname, 'font12', '0xffffffff')
proginfo.addcontrol(proginfo.channel_name)
proginfo.programme_name = xbmcgui.controllabel(230,225,360,25, programmeinfo, 'font12', '0xffffffff')
proginfo.addcontrol(proginfo.programme_name)
proginfo.textbox = xbmcgui.controltextbox(230,265,380,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 ok dialog box
def ok(title, line1, line2, line3):
dialog = xbmcgui.dialog()
dialog.ok(title, line1, line2, line3)
# ------------------------------------------------------------------------------
# define xbmc function select dialog box
def smallmenu(title, listofitems):
dialog = xbmcgui.dialog()
return dialog.select(title, listofitems)
# ------------------------------------------------------------------------------
# define function write_strm()
def write_strm(stream_link):
f = open('q:/scripts/dbox2xbox.strm', 'w')
f.write(stream_link)
f.close()
# ------------------------------------------------------------------------------
# xbmc function update_globals() updates global varibles
def update_globals():
try:
global channels
channels = get_channels(channellist_page)
global epg
epg = get_dboxepg()
global rawtime
rawtime = get_dboxinfo(rawtime_page)
global highlighted_channel
highlighted_channel = ''
global highlight_position
highlight_position = 0
global dbox_timer
dbox_timer = get_timer(timer_page)
except:
ok('error', 'error communicating with dbox: ' + dboxip, '', '')
# ------------------------------------------------------------------------------
# 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.bg = xbmcgui.controlimage(200,25,520,500, 'panel2.png')
chepg.addcontrol(chepg.bg)
chepg.header = xbmcgui.controllabel(355,95,255,25, highlighted_channel, 'font13', '0xffffffff')
chepg.addcontrol(chepg.header)
chepg.list = xbmcgui.controllist(230,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:
if yes_no('record', chepg.curr_epg[chepg.list.getselectedposition()][1]) == 'yes':
record_http = get_reclink(s, chepg.list.getselectedposition())
send_dbox2 = get_dboxinfo(record_http)
global dbox_timer
dbox_timer = get_timer(timer_page)
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
# ------------------------------------------------------------------------------
# define xbmc function display_timers - displays timers
def display_dboxtimer(timerlist): # timerlist = stored timer list
class timermenu(xbmcgui.windowdialog):
def (dboxtimer):
dboxtimer.bg = xbmcgui.controlimage(200,25,520,500, 'panel2.png')
dboxtimer.addcontrol(dboxtimer.bg)
dboxtimer.header = xbmcgui.controllabel(390,95,255,25, 'dbox timer', 'font13', '0xffffffff')
dboxtimer.addcontrol(dboxtimer.header)
dboxtimer.list = xbmcgui.controllist(230,130,400,320)
dboxtimer.addcontrol(dboxtimer.list)
dboxtimer.setfocus(dboxtimer.list)
for x in timerlist:
dboxtimer.start_time = int(x[5])
dboxtimer.end_time = int(x[6])
listitem = xbmcgui.listitem()
listitem.setlabel(time.ctime(dboxtimer.start_time)[11:][:5] + '-' + time.ctime(dboxtimer.end_time)[11:][:5] + ' - ' + x[7])
dboxtimer.list.additem(listitem)
def onaction(dboxtimer, action):
if action == action_select_item:
if yes_no('delete timer', 'are you sure') == 'yes':
dboxtimer.position = dboxtimer.list.getselectedposition()
get_dboxinfo(timer_page + '?action=remove&id=' + dbox_timer[dboxtimer.position][0])
dboxtimer.list.reset()
global dbox_timer
dbox_timer = get_timer(timer_page)
timerlist = dbox_timer
for x in timerlist:
dboxtimer.start_time = int(x[5])
dboxtimer.end_time = int(x[6])
listitem = xbmcgui.listitem()
listitem.setlabel(time.ctime(dboxtimer.start_time)[11:][:5] + '-' + time.ctime(dboxtimer.end_time)[11:][:5] + ' - ' + x[7])
dboxtimer.list.additem(listitem)
dboxtimer.setfocus(dboxtimer.list)
if action == action_previous_menu or action == action_b_button:
dboxtimer.removecontrol(dboxtimer.bg)
dboxtimer.removecontrol(dboxtimer.list)
dboxtimer.removecontrol(dboxtimer.header)
dboxtimer.close()
show_timer = timermenu()
show_timer.domodal()
del show_timer
# ------------------------------------------------------------------------------
# define xbmc function dislay_tools_buttons()
def display_tools_buttons():
class toolsmenu(xbmcgui.windowdialog):
def (tools):
tools.bg = xbmcgui.controlimage(200,45,520,445, 'panel2.png')
tools.addcontrol(tools.bg)
tools.header = xbmcgui.controllabel(390,107,255,25, 'dbox tools', 'font13', '0xffffffff')
tools.addcontrol(tools.header)
tools.button0 = xbmcgui.controlbutton(275,200,150,35, 'tv mode')
tools.addcontrol(tools.button0)
tools.button1 = xbmcgui.controlbutton(435,200,150,35, 'radio mode')
tools.addcontrol(tools.button1)
tools.button2 = xbmcgui.controlbutton(275,245,150,35, 'release lcd')
tools.addcontrol(tools.button2)
tools.button3 = xbmcgui.controlbutton(435,245,150,35, 'lock lcd')
tools.addcontrol(tools.button3)
tools.button4 = xbmcgui.controlbutton(275,290,150,35, 'restart sectionsd')
tools.addcontrol(tools.button4)
tools.button5 = xbmcgui.controlbutton(435,290,150,35, 'restart dbox2')
tools.addcontrol(tools.button5)
tools.button0.controlright(tools.button1)
tools.button0.controldown(tools.button2)
tools.button1.controlleft(tools.button0)
tools.button1.controldown(tools.button3)
tools.button2.controlup(tools.button0)
tools.button2.controldown(tools.button4)
tools.button2.controlright(tools.button3)
tools.button3.controlup(tools.button1)
tools.button3.controldown(tools.button5)
tools.button3.controlleft(tools.button2)
tools.button4.controlup(tools.button2)
tools.button4.controlright(tools.button5)
tools.button5.controlup(tools.button3)
tools.button5.controlleft(tools.button4)
tools.setfocus(tools.button0)
def oncontrol(tools, control):
if control == tools.button0:
ok('tv mode', 'this will change the dbox to watch tv channels.', 'this function will automatically stop any stream that', 'is currently playing.')
if xbmc.player().isplaying() == 1:
xbmc.player().stop()
try:
tools.worktv = get_dboxinfo(setmode_tv)
tools.spts = get_dboxinfo(start_spts)
ok('tv mode', 'swicth to tv: ' + tools.worktv, 'spts streaming activated: ' + tools.spts, 'please now refresh channel list!')
except:
ok('error', 'error switching to tv mode', 'dbox communication error', 'could try restarting dbox.')
if control == tools.button1:
ok('radio mode', 'this will change the dbox to listen radio stations.', 'this function will automatically stop any stream that', 'is currently playing.')
if xbmc.player().isplaying() == 1:
xbmc.player().stop()
try :
tools.workradio = get_dboxinfo(setmode_radio)
tools.workpes = get_dboxinfo(start_pes)
ok('radio mode', 'switch to radio: ' + tools.workradio, 'pes streaming activated: ' + tools.workpes, 'please now refresh channel list!')
except:
ok('error', 'error switching to radio mode', 'dbox communication error', 'could try restarting dbox.')
if control == tools.button2:
ok('unlock lcd', 'this will unlock the dbox lcd', '', '')
tools.workok = get_dboxinfo(lcd_disp_off)
ok('unlock lcd', tools.workok, '', '')
if control == tools.button3:
ok('lock lcd', 'this will lock the dbox lcd', '', '')
tools.workok = get_dboxinfo(lcd_disp_on)
ok('lock lcd', tools.workok, '', '')
if control == tools.button4:
ok('restart sectionsd', 'this will take a few sections to update the epg', '', '')
tools.workok = restart_sectionsd()
ok('restart sectionsd', tools.workok, '', '')
if control == tools.button5:
ok('restart dbox', 'caution : this will restart your dbox', 'please wait a minute before returning menu.', '')
tools.workok = get_dboxinfo(reboot_dbox)
ok('restart dbox', tools.workok, '', '')
def onaction(tools, action):
if action == action_previous_menu or action == action_b_button:
tools.removecontrol(tools.bg)
tools.removecontrol(tools.header)
tools.removecontrol(tools.button0)
tools.removecontrol(tools.button1)
tools.removecontrol(tools.button2)
tools.removecontrol(tools.button3)
tools.removecontrol(tools.button4)
tools.removecontrol(tools.button5)
tools.close()
show_tools = toolsmenu()
show_tools.domodal()
del show_tools
# ------------------------------------------------------------------------------
# xbmc main part of code program
# ------------------------------------------------------------------------------
# setup lcd & start dbox spts or pes mode
get_dboxinfo(lcd_disp_on)
update_globals()
if get_dboxinfo(get_mode)[:2] == 'tv':
get_dboxinfo(start_spts)
else:
get_dboxinfo(start_pes)
# 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.15", 'font13', '0xffffffff')
self.addcontrol(self.header)
self.button0 = xbmcgui.controlbutton(50,120,150,35, 'dbox2 tools')
self.addcontrol(self.button0)
self.button1 = xbmcgui.controlbutton(50,160,150,35, 'dbox2 timer')
self.addcontrol(self.button1)
self.button2 = xbmcgui.controlbutton(50,200,150,35, 'refresh list')
self.addcontrol(self.button2)
self.list = xbmcgui.controllist(212,130,455,416)
self.addcontrol(self.list)
self.list.setpagecontrolvisible(0)
self.button0.controldown(self.button1)
self.button1.controlup(self.button0)
self.button1.controldown(self.button2)
self.button2.controlup(self.button1)
self.focus_on = 'list'
self.setfocus(self.list)
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 oncontrol(self, control):
if control == self.button0:
display_tools_buttons()
if control == self.button1:
display_dboxtimer(dbox_timer)
if control == self.button2:
update_globals()
self.list.reset()
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_left:
if self.focus_on == 'list':
self.setfocus(self.button0)
self.focus_on = 'buttons'
if action == action_right:
if self.focus_on == 'buttons':
self.setfocus(self.list)
self.focus_on = 'list'
if action == action_previous_menu or action == action_b_button:
self.removecontrol(self.bg)
self.removecontrol(self.list)
self.removecontrol(self.header)
self.removecontrol(self.button0)
self.removecontrol(self.button1)
self.close()
if action == action_select_item:
if self.focus_on == 'list':
if xbmc.player().isplaying() == 1:
xbmc.player().stop()
self.position = self.list.getselectedposition()
try:
self.stream = setup_stream(self.position)
except:
ok('error', 'error setting up the stream.', '', '')
try:
xbmc.player().play(self.stream)
except:
ok('error', 'error playing stream : ' + self.stream, '', '')
if action == action_show_info or action == action_y_button:
display_channel_epg(self.list.getselectedposition())
dbox = dboxtv()
dbox.domodal()
# turn lcd off
get_dboxinfo(lcd_disp_off)
del dbox