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