Ver Mensaje Individual
Antiguo 28/08/2004, 21:09   #20
JulKeZ
Usuario Registrado
 
Fecha de ingreso: 23/jun/2003
Mensajes: 21
JulKeZ está en el buen camino
A continuación os pongo el script para que aparezca la lista de canales directamente.

Sólo hay que ponerlo en un archivo .py y subirlo a la carpeta correspondiente en la Xbox.

Lo único que teneis que modificar es la Ip de vuestro PC. Lo único que he tocado yo del código ha sido cargar la lista directamente y comentar la parte en que gestiona la vuelta a la lista de favoritos.

#MyTheatre Python client for XBMC
#Version 1.0 by marplar

############################################################
#Set the IP and port for the computer running MyTheatre here
URL = 'http://192.168.3.1:8000'
############################################################

import urllib, time, xbmc, xbmcgui
from HTMLParser import HTMLParser
#get actioncodes from keymap.xml
ACTION_PREVIOUS_MENU = 10
ACTION_SELECT_ITEM = 7

#Reads AVBroadcaster web page and creates list of favorite groups or channels
class MyParser(HTMLParser):

#Read tag
def handle_starttag(self, tag, attrs):
#Create dictionary of tag attributes
attrdict=dict(attrs)
if tag == 'html':
#Initialse list
self.parselist = []
self.chtype = ''
elif tag == 'a':
#Hyperlink tag - get link
self.href=attrdict['href']
elif tag == 'td' and len(attrdict) == 2 and self.tag == 'tr':
#Table tag - check colour to determine if encrypted
if attrdict['bgcolor'] == '#00BF00':
self.encrypt = ' '
else:
self.encrypt = '!'
#Store tag type
self.tag=tag

#Read data (outside tag)
def handle_data(self,data):
if self.tag == 'title':
#Add title to list
self.parselist.append(['Title', data])
#Store title to determine if page is favorite group list or channels
self.title = data
elif self.tag == 'center':
#Get channel type (V/R) and add to encrypted flag (!/ )
self.chtype=data + self.encrypt + ' '
elif self.tag == 'a':
#Hyperlink data
if self.href[:16] == '/list.htm?favid=':
#Link is for favorite lists
if data[:9] == 'Next page' and len(self.parselist) > 10:
#Add next page link to list
self.parselist.append(['NextPage', data, self.href])
elif self.title == 'Favorite groups list':
# Add favorite group name and link to list
self.parselist.append(['FavList', data, self.href])
elif self.href[:17] == '/set_ch.htm?chid=':
#Link is for channel
self.parselist.append(['Channel', self.chtype + data,self.href])

def close(self):
#Return list to caller
return self.parselist
self.close()


class MyClass(xbmcgui.Window):
def __init__(self):
#Set default mode
self.TVRadioMode = 'TV Only'
self.EncryptMode = 'All Channels'
#Set up screen
self.addControl(xbmcgui.ControlImage(0,0,800,600, 'background.png'))
#self.addControl(xbmcgui.ControlLabel(50, 100, 10, 100, 'my', 'font14', '0xFFFF2000'))
#self.addControl(xbmcgui.ControlLabel(75, 100, 100, 100, 'Theatre', 'font14', '0xFF000000'))
self.strTitle = xbmcgui.ControlLabel(300, 50, 200, 200, '', 'font14', '0xFFA5FF00')
self.addControl(self.strTitle)
self.butTVRadio = xbmcgui.ControlButton(50, 200, 150, 35, self.TVRadioMode, 'button-focus.png', 'button-nofocus.png')
self.addControl(self.butTVRadio)
self.butEncrypt = xbmcgui.ControlButton(50, 260, 150, 35, self.EncryptMode, 'button-focus.png', 'button-nofocus.png')
self.addControl(self.butEncrypt)
self.list = xbmcgui.ControlList(300, 100, 300, 400)
self.addControl(self.list)
self.list.controlLeft(self.butTVRadio)
self.butTVRadio.controlRight(self.list)
self.butTVRadio.controlDown(self.butEncrypt)
self.butEncrypt.controlUp(self.butTVRadio)
self.butEncrypt.controlRight(self.list)
#Get favorites group list
self.MyParser=MyParser()
self.file = '/list.htm?favid=0'
self.ParseList(URL)
self.setFocus(self.list)

#Read html page
def GetList(self,URL,file):
opener = urllib.FancyURLopener({})
try:
doc = opener.open(URL + file)
webpage = doc.read() # read file
doc.close()
self.MyParser.feed(webpage)
listings=self.MyParser.close()
return listings
except:
self.message('Unable to retrieve channel list')
return ' '

#Check if stream is being received
def TestChannel(self, URL):
opener = urllib.FancyURLopener({})
try:
doc = opener.open(URL + '/dvbcore.mpg')
datacount = len(doc.readline())
doc.close
if datacount > 0:
return 'OK'
else:
return ' '
except:
return ' '

#Display Listing
def ParseList(self,URL):
#Get listings
self.listings =self.GetList(URL,self.file)
#Check if list is complete
while self.listings[len(self.listings)-1][0] == 'NextPage':
nextpage = self.GetList(URL, self.listings[len(self.listings)-1][2])
self.listings.pop(len(self.listings)-1) #Remove NextPage from original list
nextpage.pop(0) #Remove Title from extended list
self.listings.extend(nextpage) #Join original and extended lists

#Filter Channels to show TV/Radio and FTA/Encryted
count = 0
while count < len(self.listings):
if self.listings[count][0] == 'Channel':
if self.ParseCheckMode(self.listings[count][1]) == 0:
self.listings.pop(count)
else:
count = count + 1
else:
count = count + 1

#Populate list
self.list.reset()
for listing in self.listings:
if listing[0] == 'Title':
self.strTitle.setLabel('Digital +')
else:
self.list.addItem(listing[1])



#Check Channel to show TV/Radio and FTA/Encryted
def ParseCheckMode(self, listing):
if self.TVRadioMode == 'TV Only' and listing[0:1] <> 'V':
return 0
elif self.TVRadioMode == 'Radio Only' and listing[0:1] <> 'R':
return 0
elif self.EncryptMode == 'FTA Only' and listing[1:2] =='!':
return 0
elif self.TVRadioMode == 'TV and Radio':
if listing[0:1] <> 'V' and listing[0:1] <> 'R':
return 0
else:
return 1

#Handle user input
def onControl(self, control):
if control == self.list:
#User selected group/channel list
try:
listingspos = self.list.getSelectedPosition()+1
if self.listings[listingspos][0] == 'Channel':
#User selected channel change
dialog = xbmcgui.DialogProgress()
dialog.create('MyTheatre', 'Tuning to ' + self.listings[listingspos][1][3:])
self.GetList(URL, self.listings[listingspos][2])
searchpos = 0
#Wait for stream to be detected
while searchpos <= 95 and dialog.iscanceled() == 0 and self.TestChannel(URL) != 'OK':
searchpos = searchpos + 5
dialog.update(searchpos)
time.sleep(1)

if searchpos < 100 and dialog.iscanceled() == 0:
#Play stream
dialog.close()
xbmc.Player().play(URL + '/dvbcore.mpg')
elif dialog.iscanceled() == 0:
#Time out
dialog.close()
self.message('Channel not decryptable or not broadcasting')
else:
#User cancelled
dialog.close()
else:
#User selected group list
self.file = self.listings[self.list.getSelectedPosition()+1][2]
self.ParseList(URL)
except:
self.message('Error tuning Channel.')

elif control == self.butTVRadio:
#User selected TV/Radio mode button - toggle button and display list
if self.TVRadioMode == 'TV and Radio':
self.TVRadioMode = 'TV Only'
elif self.TVRadioMode == 'TV Only':
self.TVRadioMode = 'Radio Only'
else:
self.TVRadioMode = 'TV and Radio'

self.butTVRadio.setLabel(self.TVRadioMode)
self.ParseList(URL)

elif control == self.butEncrypt:
#User selected Encrypt mode button - toggle button and display list
if self.EncryptMode == 'All Channels':
self.EncryptMode = 'FTA Only'
else:
self.EncryptMode = 'All Channels'

self.butEncrypt.setLabel(self.EncryptMode)
self.ParseList(URL)

def onAction(self, action):
#User selected back - show favourite groups or exit
if action == ACTION_PREVIOUS_MENU:
#if self.listings[1][0] == 'Channel':
# self.file = '/list.htm'
# self.ParseList(URL)
# self.setFocus(self.list)
#else:
self.close()

#Display message
def message(self, message):
dialog = xbmcgui.Dialog()
dialog.ok(" MyTheatre", message)

###############
#Main
###############
mydisplay = MyClass()
mydisplay.doModal()
del mydisplay
JulKeZ está desconectado
Respuesta rápida a este mensaje
Responder Citando Subir