From 1d57960db00b34a0652ac53444dc6a1de322be54 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Thu, 5 Nov 2009 20:19:19 +0100 Subject: [PATCH] Convertito il parser da espressioni regolari a xml.dom.minidom --- RaiTV/ChannelLoader.py | 26 +++++++++++++++++++++----- RaiTV/VideoWidget.py | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/RaiTV/ChannelLoader.py b/RaiTV/ChannelLoader.py index 05978f2..492168a 100644 --- a/RaiTV/ChannelLoader.py +++ b/RaiTV/ChannelLoader.py @@ -5,6 +5,7 @@ # import urllib2, re, httplib +from xml.dom.minidom import parseString class ChannelList(): @@ -27,9 +28,23 @@ class ChannelList(): def parseChannels(self, xmlfile): """Fai il parse dei canali scaricati dalla rai""" - for channel, url in re.findall(".*\\n.*(\S*)", xmlfile): - url = re.sub(r"&", "&", url) - self.channels.append( (channel,url) ) + dom = parseString(xmlfile) + channels = dom.getElementsByTagName("set") + for c in channels: + ## Recupero il nome del canale + name = c.getElementsByTagName("item")[0].getAttribute("name") + ## Recupero l'url + videounit = c.getElementsByTagName("videoUnit") + url_array = [] + for vu in videounit: + url = vu.getElementsByTagName("url")[0] + if url.childNodes is not []: + url_array.append(url.childNodes[0].data) + + if url_array is not []: + self.channels.append((name, url_array[0])) + + def getChannel(self, channel): @@ -38,8 +53,6 @@ class ChannelList(): ## Scorriamo la lista per trovare il canale desiderato # it = self.channels.get_iter_first() - - if it is None: return None ## Qui c'è poco da fare, la lista è vuota @@ -59,10 +72,13 @@ class ChannelList(): """Ottiene l'URL dello streaming puntato da path nella liststore""" + ## Ottengo l'URL it = self.channels.get_iter(path) url = self.channels.get_value(it, 1) + print "url: " + url + return self.urlToMms(url) def urlToMms(self, url): diff --git a/RaiTV/VideoWidget.py b/RaiTV/VideoWidget.py index 51b82f1..6c319b1 100644 --- a/RaiTV/VideoWidget.py +++ b/RaiTV/VideoWidget.py @@ -16,6 +16,8 @@ class GstPlayer(threading.Thread): self.exit_required = False self.loading = False + self.daemon = True + def set_sink(self, sink): assert self.xid self.imagesink = sink -- 2.1.4