1d7a71309710278999684677441bf9db64fbe977
[vuplus_dvbapp] / lib / python / Plugins / Extensions / HbbTV / aitreader.py
1 import os, xml.dom.minidom
2
3 DUMPBIN = "/usr/lib/enigma2/python/Plugins/Extensions/HbbTV/dumpait"
4 class eAITSectionReader:
5         def __init__(self, demux, pmtid, sid):
6                 self.mAppList  = []
7                 self.mDocument = None
8                 self.mCommand  = "%s --demux=%s --pmtid=%x --serviceid=%x"%(DUMPBIN, demux, pmtid, sid)
9
10         def __text(self, nodelist):
11                 rc = []
12                 for node in nodelist:
13                         if node.nodeType == node.TEXT_NODE:
14                                 rc.append(node.data)
15                 return ''.join(rc)
16
17         def __item(self, application, name):
18                 for item in application.getElementsByTagName(name):
19                         return self.__text(item.childNodes)
20                 return None
21
22         def __application(self, application):
23                 item = {}
24                 item["name"]    = str(self.__item(application, "name"))
25                 item["url"]     = str(self.__item(application, "url"))
26                 item["control"] = int(self.__item(application, "control"))
27                 item["orgid"]   = int(self.__item(application, "orgid"))
28                 item["appid"]   = int(self.__item(application, "appid"))
29                 item["profile"] = int(self.__item(application, "profile"))
30                 #print item
31                 return item
32
33         def doParseApplications(self):
34                 l = []
35                 for application in self.mDocument.getElementsByTagName("application"):
36                         item = self.__application(application)
37                         l.append(item)
38                 self.mAppList = l
39
40         def getApplicationList(self):
41                 return self.mAppList
42
43         def doOpen(self):
44                 document = ""
45                 try:    document = os.popen(self.mCommand).read()
46                 except Exception, ErrMsg:
47                         print ErrMsg
48                         return False
49                 if len(document) == 0:
50                         return False
51                 document = document.decode("cp1252").encode("utf-8")
52                 #print document
53                 self.mDocument = xml.dom.minidom.parseString(document)
54                 return True
55
56         def doDump(self):
57                 for x in self.getApplicationList():
58                         print "Name  :", x["name"]
59                         print "URL   :", x["url"]
60                         print "OrgID :", x["orgid"]
61                         print "AppID :", x["appid"]
62                         print "Control Code :", x["control"]
63                         print "Profile Code :", x["profile"]
64                         print ""
65
66 def unit_test(demux, pmtid, sid):
67         reader = eAITSectionReader(demux, pmtid, sid)
68         if reader.doOpen():
69                 reader.doParseApplications()
70                 reader.doDump()
71         else:   print "no data!!"
72
73 #unit_test('0', 0x17d4, 0x2b66)
74