[EPGSearch] - include PluginDescriptor.WHERE_CHANNEL_SELECTION_RED for other plugins...
[enigma2-plugins.git] / dreammediathek / src / ServiceXML.py
1 # -*- coding: utf-8 -*-
2 from os.path import exists
3 from xml.etree.cElementTree import parse as cet_parse
4 from Tools.Directories import resolveFilename, SCOPE_CURRENT_PLUGIN
5
6 WEBTV_STATIONS = resolveFilename(SCOPE_CURRENT_PLUGIN, "Extensions/dreamMediathek/webtv_stations.xml")
7
8
9 class WebTVStations():
10         """Manages WebTVStations declared in a XML-Document."""
11         def __init__(self):
12                 print "[WebTVStations] INIT"
13                 self.webtv_stations = {}
14
15         def getWebTVStations(self, callback=None):
16                 self.webtv_stations = {}
17
18                 if not exists(WEBTV_STATIONS):
19                         return
20                 tree = cet_parse(WEBTV_STATIONS).getroot()
21
22                 def getValue(definitions, default):
23                         Len = len(definitions)
24                         return Len > 0 and definitions[Len-1].text or default
25
26                 for tvstation in tree.findall("tvstation"):
27                         data = { 'provider': None, 'title': None, 'streamurl': None }
28                         try:
29                                 data['provider'] = getValue(tvstation.findall("provider"), False).encode("UTF-8")
30                                 data['title'] = getValue(tvstation.findall("title"), False).encode("UTF-8")
31                                 data['streamurl'] = getValue(tvstation.findall("streamurl"), False).encode("UTF-8")
32
33                                 print "TVSTATION--->",data
34                                 self.webtv_stations[data['title']] = data
35                         except Exception, e:
36                                 print "[WebTVStations] Error reading Stations:", e
37
38         def getWebTVStationsList(self):
39                 return sorted(self.webtv_stations.iterkeys())
40
41 iWebTVStations = WebTVStations()