DreamMediathek Play Web and ipTV streams, example xml
[enigma2-plugins.git] / dreammediathek / src / ServiceXML.py
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
4
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")
9
10 class WebTVStations():
11         """Manages WebTVStations declared in a XML-Document."""
12         def __init__(self):
13                 print "[WebTVStations] INIT"
14                 self.webtv_stations = {}
15
16         def getWebTVStations(self, callback = None):
17                 webtv_stations = []
18                 self.webtv_stations = {}
19
20                 if not os_path.exists(WEBTV_STATIONS):
21                         return
22                 tree = cet_parse(WEBTV_STATIONS).getroot()
23
24                 def getValue(definitions, default):
25                         ret = ""
26                         Len = len(definitions)
27                         return Len > 0 and definitions[Len-1].text or default
28
29                 for tvstation in tree.findall("tvstation"):
30                         data = { 'provider': None, 'title': None, 'streamurl': None }
31                         try:
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")
35
36                                 print "TVSTATION--->",data
37                                 self.webtv_stations[data['title']] = data
38                         except Exception, e:
39                                 print "[WebTVStations] Error reading Stations:", e
40
41         def getWebTVStationsList(self):
42                 return sorted(self.webtv_stations.iterkeys())
43
44 iWebTVStations = WebTVStations()
45