Oke bedankt.
Ik heb nu 1 gevonden die werkt. Maar als ik nu mijn webradio opstart gebeurt er niks. Moet ik daar ook nog iets voor configureren.
mijn kmlBrowse zier er zo uit:
#
# SimpleKML.py is written by Gabriel <gabriel@livinstyle.nl>
#
#
# "I am Gabriel, who stands in the presence of God,
# and I have been sent to speak to you and to
# bring you this good news."
#
#
# This programs is licensed under the GNU Public License
#
# You're welcome to redistribute this software under the
# terms of the GNU General Public Licence version 2.0
# or, at your option, any higher version.
#
# Manus you helped me alot by your VB.net source-code
# Open-Source is the word!
#
#init
import sys, time, string
from os import path, unlink
import xbmc, xbmcgui, Image
import urllib
import xml.dom.minidom
KeyActions = {}
PreloadedImages = {}
ActiveMenu = -1
Menu = []
MenuItemList = []
#scaling init
xscale = 0
yscale = 0
CACHE_DIR = "Q:\\scripts\\SimpleKML\\"
PLAYLIST_FILE = CACHE_DIR + "filename.pls"
ACTION_MOVE_LEFT = 1
ACTION_MOVE_RIGHT = 2
ACTION_MOVE_UP = 3
ACTION_MOVE_DOWN = 4
ACTION_SELECT = 7
ACTION_BACK = 9
ACTION_MENU = 10
ACTION_SKIP_NEXT = 5 #left trigger
ACTION_SKIP_PREVIOUS = 6 #right trigger
ACTION_DISPLAY = 18
def DownloadImage(url):
rawfilename = CACHE_DIR + path.basename(url)
filename = path.abspath(rawfilename)
#if (path.splitext(filename)[1] == ".gif"):
# file = path.splitext(rawfilename)[0] + ".png"
# if path.exists(path.abspath(file)):
# return file
if (path.exists(filename)):
return rawfilename
else:
try:
urllib.urlretrieve(url, filename)
return rawfilename
except:
OnMessage("Could not retrieve image from", url)
return None
def timer_elapsed():
return None
def DownloadPlayList(url):
dialog = xbmcgui.DialogProgress()
dialog.create("KML Browser", "Downloading Playlist...", "Please wait.")
filename = PLAYLIST_FILE
if not dialog.iscanceled():
if (path.exists(filename)):
unlink(filename)
try:
urllib.urlretrieve(url, filename)
dialog.close()
return filename
except:
dialog.close()
OnMessage("Could not retrieve playlist from", url)
return None
else:
return None
def DownloadXmlDocument(url=None):
dialog = xbmcgui.DialogProgress()
if url is None:
url = "http://webradio.kiss-technology.com/webradio2/kml/index.php?reload=true"
try:
dialog.create("KML Browser", "Downloading KML Document...", "Please wait.")
data = urllib.urlopen(url)
kml = data.read()
data.close()
kml = xml.dom.minidom.parseString(kml)
dialog.close()
return kml
except:
dialog.close()
OnMessage("Failed to download XML document:", url)
return None
def OnMessage(m1="", m2="", m3=""):
dialog = xbmcgui.DialogProgress()
#xbmcgui.unlock()
dialog.create("KML Browser", m1, m2, m3)
time.sleep(1)
if dialog.iscanceled():
w.doModal()
w.close()
del w
return
#xbmcgui.lock()
dialog.close()
return
def GetFont(font):
if (font == 1):
return "font18"
else:
return "font14"
def GetColor(pen):
colString = "33333300161b58ff8080804080808080808080bf161b5840161b5866161b58bff9a23940f9a23980f9a239bffd1f1ffffd401ffffd6d1ffffda01ffffdcb1fff000000ff111111ff222222ff333333ff444444ff555555ff666666ff777777ff888888ff999999ffaaaaaaffbbbbbbffccccccffddddddffeeeeeeffffffffff161b5866222761743f43768861658fa08185a6b8a6a8bfd3c6c8d7eaebecf1fe1d1df9ff1d27f9ff1d39f9ff1d50f9ff1d6ef9ff1d8df9ff1da7f9ff1dbbf9ff161b586623255474403c488863583ba086742eb8a78d21d3caa914eae9c209fe060100ff290800ff4b0f00ff6d1600ff8f1d00ffb22400ffd42a00fff73100ff0000ffffff0000ffff00ffff00ff00ff00ffffffffff00ff0099ffffff9900ffff0099ffecbe9bffc3cedcffa5e480ff95b0ceffec986fffecce6affb385aeff4141ddffdd4141ffdd41dcff41dd41ff41dcddffdcdd41ff419eddffdd9e41ffdd419effd6b9a4ffbec4cdffa9d092ff9fb0c2ffd4a088ffd4c185ffb095adff9292fafffa9292fffa92f9ff92fa92ff92f9fafff9fa92ff92d0fafffad092fffa92d0fff5e2d4ffe5e9efffd7f1c8ffd0dce8fff4d1c1fff4e7bfffdcc9daff4d4df6fff64d4dfff64df5ff4df64dff4df5f6fff5f64dff4db2f6fff6b24dfff64db2ffeecfb8ffd4dbe4ffbde7a5ffb3c5d9ffecb499ffecd896ffc5a7c2ff2222e5ffe52222ffe522e4ff22e522ff22e4e5ffe4e522ff2296e5ffe59622ffe52296ffdbb89dffbdc6d0ffa3d487ff97acc3ffd9997affd9c276ffac8aa9ff1919a8ffa81919ffa819a7ff19a819ff19a7a8ffa7a819ff196ea8ffa86e19ffa8196effa08773ff8a9198ff779b63ff6f7e8fff9f7059ff9f8e56ff7e657cff10106fff6f1010ff6f106eff106f10ff106e6fff6e6f10ff10496fff6f4910ff6f1049ff6b594dff5c6065ff4f6742ff49545fff6a4a3bff6a5e39ff544352ff0b0b48ff480b0bff480b48ff0b480bff0b4848ff48480bff0b2f48ff482f0bff480b2fff453a32ff3c3f42ff34432bff2f373eff453026ff453d25ff372c36ff080834ff340808ff340833ff083408ff083334ff333408ff082234ff342208ff340822ff322a24ff2b2d2fff25301eff22272cff31231cff312c1bff271f26ff1b1bb780b71b1b80b71bb6801bb71b801bb6b780b6b71b801b78b780b7781b80b71b7880af937e80979ea68082a96c80798a9c80ae7a6180ae9b5e808a6e8780296241ff5a1b7dffe98509ff2eb86fff1b4198ffdc471effc647abff6a47abff4f7ad6ffd6955fff8095aeff80c3aeff4c7292ffb34441ffb3ff00fff78264ff64391effedc40540edc40580edc405bfedc405ffffffff40ffffff80ffffffbf000000bf000000800000004000000066000000fff9a239ff0000008fffffffff"
value = int(pen)
color = "0x" + colString[(value * 8 + 6):(value * 8 + 8)] + colString[(value * 8):(value * 8 + 6)]
return color
def GetText(el):
for node in el.childNodes:
return node.nodeValue
def innerText(el):
for node in el.childNodes:
return node.data
def GetX(coords):
c = string.split(coords, ",")
x = xscale * int(c[0])
return int(x)
def GetY(coords):
c = string.split(coords, ",")
y = yscale * int(c[1])
return int(y)
def GetWidth(img, noscale=None):
img = path.abspath(img)
im = Image.open(img)
x,y = im.size
if (noscale == None):
x = xscale * x
return int(x)
else:
return int(x)
def GetHeight(img, noscale=None):
img = path.abspath(img)
im = Image.open(img)
x,y = im.size
if (noscale == None):
y = yscale * y
return int(y)
else:
return int(y)
def GetEndPoint(coords):
c = string.split(coords, ",")
return int(c[2]), int(c[3])
def GetMP3Title():
try:
pls = xbmc.PlayList(0)
item = pls.__getitem__(0)
title = item.getdescription()
return title
except:
return " "
def PlayMedia(url):
try:
pls = xbmc.PlayList(0)
pls.clear()
pls.load(DownloadPlayList(url))
player = xbmc.Player()
player.play(pls)
except:
return None
class KMLBrowser(xbmcgui.Window):
def __init__(self):
self.control = ""
def addItem(self, control):
MenuItemList.append(control)
self.addControl(control)
def PreviousMenu(self):
global ActiveMenu
if len(Menu) > 0:
if ActiveMenu >= 0:
self.ExecuteCode(Menu[ActiveMenu]['hide'], self)
ActiveMenu -= 1
if ActiveMenu < 0: ActiveMenu = len(Menu) - 1
if ActiveMenu >= 0:
self.ExecuteCode(Menu[ActiveMenu]['show'], self)
def NextMenu(self):
global ActiveMenu
if len(Menu) > 0:
if ActiveMenu >= 0:
self.ExecuteCode(Menu[ActiveMenu]['hide'], self)
ActiveMenu += 1
if ActiveMenu >= len(Menu): ActiveMenu = 0
if ActiveMenu >= 0:
self.ExecuteCode(Menu[ActiveMenu]['show'], self)
def Process(self, KMLdoc=None):
global ActiveMenu, Menu, MenuItemList, KeyActions, PreloadedImages
if (KMLdoc is None):
OnMessage("KML Document is nothing", "Return home")
self.Process(DownloadXmlDocument())
return
self.Clean()
ActiveMenu = -1
MenuItemList = []
Menu = []
KeyActions = {}
PreloadedImages = {}
for node in KMLdoc.documentElement.childNodes:
if (node.nodeType == node.ELEMENT_NODE):
self.ProcesElement(node, self)
for i in range(len(Menu)):
self.ExecuteCode(Menu[i]['hide'], self)
self.NextMenu()
def ProcesElement(self, el, box):
try:
if (el.nodeName == "BACKGROUND"):
global xscale, yscale
bg = DownloadImage(el.getAttribute("href"))
xscale = float(self.getWidth()) / float(GetWidth(bg, 1))
yscale = float(self.getHeight()) / float(GetHeight(bg, 1))
box.addControl(xbmcgui.ControlImage(0, 0, GetWidth(bg), GetHeight(bg), bg))
elif (el.nodeName == "IMAGE"):
img = PreloadedImages[el.getAttribute("id")]
box.addItem(xbmcgui.ControlImage(GetX(el.getAttribute("coords")), GetY(el.getAttribute("coords")), GetWidth(img), GetHeight(img), img, '0x00FF0000'))
elif (el.nodeName == "TEXT"):
text = GetText(el)
if text == " $$MP3_TITLE$$ ":
self.control = xbmcgui.ControlFadeLabel(GetX(el.getAttribute("coords")), GetY(el.getAttribute("coords")), 480, 40, GetFont(el.getAttribute("font")), GetColor(el.getAttribute("pen")))
self.addItem(self.control)
self.control.addLabel(GetMP3Title())
return
elif text == "C O N N E C T I N G . . .":
return
else:
self.addItem(xbmcgui.ControlLabel(GetX(el.getAttribute("coords")), GetY(el.getAttribute("coords")), 200, 30, text, GetFont(el.getAttribute("font")), GetColor(el.getAttribute("pen"))))
elif (el.nodeName == "MENUITEM"):
self.MakeMenuItem(el, box)
elif (el.nodeName == "ONMETADATA"):
self.ExecuteCode(innerText(el), self)
elif (el.nodeName == "LOADIMAGE"):
PreloadedImages[el.getAttribute("id")] = DownloadImage(el.getAttribute("href"))
elif (el.nodeName == "GOTO"):
url = el.getAttribute("href")
self.Process(DownloadXmlDocument(url))
elif (el.nodeName == "KEY"):
KeyActions[el.getAttribute("id")] = innerText(el.firstChild)
elif (el.nodeName == "PLAYMEDIA"):
try:
PlayMedia(el.getAttribute("href"))
self.control.reset()
self.control.addLabel(GetMP3Title())
except:
OnMessage("Could not start stream:", el.getAttribute("href"))
except:
OnMessage("ERROR!", "Could not parse node:", el.nodeName)
def MakeMenuItem(self, menuItemEl, box):
itm = {}
itm['id'] = menuItemEl.getAttribute('id')
for el in menuItemEl.childNodes:
if (el.nodeName == "ONCLICK"):
itm['click'] = innerText(el)
elif (el.nodeName == "ONHILITE"):
itm['show'] = innerText(el)
elif (el.nodeName == "ONUNHILITE"):
itm['hide'] = innerText(el)
elif (el.nodeName == "ONLEFT"):
itm['left'] = innerText(el)
elif (el.nodeName == "ONRIGHT"):
itm['right'] = innerText(el)
elif (el.nodeName == "ONUP"):
itm['up'] = innerText(el)
elif (el.nodeName == "ONDOWN"):
itm['down'] = innerText(el)
Menu.append(itm)
def ExecuteCode(self, innerXml, box):
try:
doc = xml.dom.minidom.parseString("<root>" + innerXml + "</root>")
for el in doc.documentElement.childNodes:
self.ProcesElement(el, box)
except:
OnMessage("Failed to execute code.", "Return home")
self.Process(DownloadXmlDocument())
def Clean(self):
for i in range(len(MenuItemList)):
self.removeControl(MenuItemList[i])
def onAction(self, action):
if action == ACTION_MOVE_UP:
#xbmcgui.lock()
if len(Menu) > 0:
if (Menu[ActiveMenu].has_key('up')):
self.ExecuteCode(Menu[ActiveMenu]['up'], self)
self.PreviousMenu()
#xbmcgui.unlock()
elif action == ACTION_MOVE_DOWN:
#xbmcgui.lock()
if len(Menu) > 0:
if (Menu[ActiveMenu].has_key('down')):
self.ExecuteCode(Menu[ActiveMenu]['down'], self)
self.NextMenu()
#xbmcgui.unlock()
elif action == ACTION_SELECT:
#xbmcgui.lock()
if ActiveMenu >= 0:
if (Menu[ActiveMenu].has_key('click')):
doc = xml.dom.minidom.parseString("<root>" + Menu[ActiveMenu]['click'] + "</root>")
for node in doc.documentElement.childNodes:
if node.nodeName == "GOTO":
self.Process(DownloadXmlDocument(node.getAttribute("href")))
#xbmcgui.unlock()
elif action == ACTION_BACK:
#xbmcgui.lock()
if (KeyActions.has_key('93')):
self.ExecuteCode(KeyActions['93'], self)
#xbmcgui.unlock()
elif action == ACTION_MOVE_RIGHT:
#xbmcgui.lock()
if (KeyActions.has_key('16388')):
self.ExecuteCode(KeyActions['16388'], self)
#xbmcgui.unlock()
elif action == ACTION_MOVE_LEFT:
#xbmcgui.lock()
if (KeyActions.has_key('16389')):
self.ExecuteCode(KeyActions['16389'], self)
#xbmcgui.unlock()
elif action == ACTION_MENU:
#xbmcgui.lock()
self.Clean()
#xbmcgui.unlock()
self.close()
#Key_ID's :
#73 => Button 0
#74 => Button 1
#75 => Button 2
#76 => Button 3
#77 => Button 4
#79 => Button 5
#80 => Button 6
#81 => Button 7
#82 => Button 8
#83 => Button 9
#84 => Button TITLE MENU
#
#93 => Button RETURN
#94 => Button <<
#95 => Button >>
#96 => Button STEP
#97 => Button AUDIO
#98 => Button SUBPIC
#99 => Button Bouton ZOOM
#100 => Button Bouton ANGLE
#101 => Button REPEAT
#102 => Button MARK
#103 => Button CLEAR
#104 => Button SRCH
#
#16387 => Button PLAY/PAUSE
#16388 => Button NEXT
#16389 => Button PREVIOUS
w = KMLBrowser()
#http://tinystocks.com/k/kiss.php
#http://webradio.kiss-technology.com/webradio2/kml/index.php?reload=true
w.Process(DownloadXmlDocument())
w.doModal()
del w
-----------------
P.s. er hheb gelezen dat dat er iets mee te maken had.