1 # -*- coding: utf-8 -*-
2 from re import compile as re_compile
3 from os import path as os_path, symlink, listdir, unlink, readlink, remove
5 from xml.etree.cElementTree import parse as cet_parse
6 from Tools.Directories import pathExists, fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE, SCOPE_HDD, SCOPE_CURRENT_PLUGIN, SCOPE_CURRENT_SKIN
7 #WEBTV_STATIONS = "/etc/enigma2/webtv_stations.xml"
8 WEBTV_STATIONS = resolveFilename(SCOPE_CURRENT_PLUGIN, "Extensions/dreamMediathek/webtv_stations.xml")
10 class WebTVStations():
11 """Manages WebTVStations declared in a XML-Document."""
13 print "[WebTVStations] INIT"
14 self.webtv_stations = {}
16 def getWebTVStations(self, callback = None):
18 self.webtv_stations = {}
20 if not os_path.exists(WEBTV_STATIONS):
22 tree = cet_parse(WEBTV_STATIONS).getroot()
24 def getValue(definitions, default):
26 Len = len(definitions)
27 return Len > 0 and definitions[Len-1].text or default
29 for tvstation in tree.findall("tvstation"):
30 data = { 'provider': None, 'title': None, 'streamurl': None }
32 data['provider'] = getValue(tvstation.findall("provider"), False).encode("UTF-8")
33 data['title'] = getValue(tvstation.findall("title"), False).encode("UTF-8")
34 data['streamurl'] = getValue(tvstation.findall("streamurl"), False).encode("UTF-8")
36 print "TVSTATION--->",data
37 self.webtv_stations[data['title']] = data
39 print "[WebTVStations] Error reading Stations:", e
41 def getWebTVStationsList(self):
42 return sorted(self.webtv_stations.iterkeys())
44 iWebTVStations = WebTVStations()