[hbbtv] upgraded.
[vuplus_dvbapp] / lib / python / Plugins / Extensions / HbbTV / aitreader.py
1 import os, xml.dom.minidom
2 from enigma import iServiceInformation
3
4 import vbcfg
5
6 DUMPBIN = vbcfg.PLUGINROOT + "/dumpait"
7 class eAITSectionReader:
8         def __init__(self, demux, pmtid, sid):
9                 self.mVuplusBox = False
10                 self.mInfo = None
11                 self.mAppList  = []
12                 self.mDocument = None
13                 self.mCommand  = "%s --demux=%s --pmtid=%x --serviceid=%x"%(DUMPBIN, demux, pmtid, sid)
14
15         def __text(self, nodelist):
16                 rc = []
17                 for node in nodelist:
18                         if node.nodeType == node.TEXT_NODE:
19                                 rc.append(node.data)
20                 return ''.join(rc)
21
22         def __item(self, application, name):
23                 for item in application.getElementsByTagName(name):
24                         return self.__text(item.childNodes)
25                 return None
26
27         def __application(self, application):
28                 item = {}
29
30                 if self.mVuplusBox:
31                         item["name"]    = str(application[1])
32                         item["url"]     = str(application[2])
33                         item["control"] = int(application[0])
34                         item["orgid"]   = int(application[3])
35                         item["appid"]   = int(application[4])
36                         item["profile"] = int(application[5])
37                 else:
38                         item["name"]    = str(self.__item(application, "name"))
39                         item["url"]     = str(self.__item(application, "url"))
40                         item["control"] = int(self.__item(application, "control"))
41                         item["orgid"]   = int(self.__item(application, "orgid"))
42                         item["appid"]   = int(self.__item(application, "appid"))
43                         item["profile"] = int(self.__item(application, "profile"))
44                 return item
45
46         def doParseApplications(self):
47                 l = []
48
49                 if self.mVuplusBox:
50                         for application in self.mInfo.getInfoObject(iServiceInformation.sHBBTVUrl):
51                                 item = self.__application(application)
52                                 l.append(item)
53                 else:
54                         for application in self.mDocument.getElementsByTagName("application"):
55                                 item = self.__application(application)
56                                 l.append(item)
57                 self.mAppList = l
58
59         def getApplicationList(self):
60                 return self.mAppList
61
62         def doOpen(self, info, is_vuplusbox):
63                 if is_vuplusbox:
64                         self.mVuplusBox = is_vuplusbox
65                         self.mInfo = info
66                         return True
67
68                 document = ""
69                 try:    document = os.popen(self.mCommand).read()
70                 except Exception, ErrMsg:
71                         vbcfg.ERR(ErrMsg)
72                         return False
73                 if len(document) == 0:
74                         return False
75                 document = document.decode("cp1252").encode("utf-8")
76                 try:
77                         self.mDocument = xml.dom.minidom.parseString(document)
78                 except Exception, ErrMsg:
79                         vbcfg.ERR("XML parse: %s" % ErrMsg)
80                         return False
81                 return True
82
83         def doDump(self):
84                 for x in self.getApplicationList():
85                         print "Name  :", x["name"]
86                         print "URL   :", x["url"]
87                         print "OrgID :", x["orgid"]
88                         print "AppID :", x["appid"]
89                         print "Control Code :", x["control"]
90                         print "Profile Code :", x["profile"]
91                         print ""
92
93 def unit_test(demux, pmtid, sid):
94         reader = eAITSectionReader(demux, pmtid, sid)
95         if reader.doOpen():
96                 reader.doParseApplications()
97                 reader.doDump()
98         else:
99                 vbcfg.ERR("no data!!")
100
101 #unit_test('0', 0x17d4, 0x2b66)
102