745a453c914bc4dc5c70f1598f7ec9b69360b350
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / PliExtraInfo.py
1 # shamelessly copied from pliExpertInfo (Vali, Mirakels, Littlesat)
2
3 from enigma import iServiceInformation, iPlayableService
4 from Components.Converter.Converter import Converter
5 from Components.Element import cached
6 from Components.config import config
7 from Tools.Transponder import ConvertToHumanReadable
8 from Tools.GetEcmInfo import GetEcmInfo
9 from Poll import Poll
10
11 def addspace(text):
12         if text:
13                 text += " "
14         return text
15
16 class PliExtraInfo(Poll, Converter, object):
17         def __init__(self, type):
18                 Converter.__init__(self, type)
19                 Poll.__init__(self)
20                 self.type = type
21                 self.poll_interval = 1000
22                 self.poll_enabled = True
23                 self.caid_data = (
24                         ( "0x100",  "0x1ff", "Seca",    "S" ),
25                         ( "0x500",  "0x5ff", "Via",     "V" ),
26                         ( "0x600",  "0x6ff", "Irdeto",  "I" ),
27                         ( "0x900",  "0x9ff", "NDS",     "Nd"),
28                         ( "0xb00",  "0xbff", "Conax",   "Co"),
29                         ( "0xd00",  "0xdff", "CryptoW", "Cw"),
30                         ("0x1700", "0x17ff", "Beta",    "B" ),
31                         ("0x1800", "0x18ff", "Nagra",   "N" ),
32                         ("0x2600", "0x2600", "Biss",    "Bi"),
33                         ("0x4ae0", "0x4ae1", "Dre",     "D" )
34                 )
35                 self.ecmdata = GetEcmInfo()
36                 self.feraw = self.fedata = self.updateFEdata = None
37
38         def getCryptoInfo(self,info):
39                 if (info.getInfo(iServiceInformation.sIsCrypted) == 1):
40                         data = self.ecmdata.getEcmData()
41                         self.current_source = data[0]
42                         self.current_caid = data[1]
43                         self.current_provid = data[2]
44                         self.current_ecmpid = data[3]
45                 else:
46                         self.current_source = ""
47                         self.current_caid = "0"
48                         self.current_provid = "0"
49                         self.current_ecmpid = "0"
50
51         def createCryptoBar(self,info):
52                 res = ""
53                 available_caids = info.getInfoObject(iServiceInformation.sCAIDs)
54
55                 for caid_entry in self.caid_data:
56                         if int(self.current_caid, 16) >= int(caid_entry[0], 16) and int(self.current_caid, 16) <= int(caid_entry[1], 16):
57                                 color="\c0000??00"
58                         else:
59                                 color = "\c007?7?7?"
60                                 try:
61                                         for caid in available_caids:
62                                                 if caid >= int(caid_entry[0], 16) and caid <= int(caid_entry[1], 16):
63                                                         color="\c00????00"
64                                 except:
65                                         pass
66
67                         if res: res += " "
68                         res += color + caid_entry[3]
69
70                 res += "\c00??????"
71                 return res
72
73         def createCryptoSpecial(self,info):
74                 caid_name = "FTA"
75                 try:
76                         for caid_entry in self.caid_data:
77                                 if int(self.current_caid, 16) >= int(caid_entry[0], 16) and int(self.current_caid, 16) <= int(caid_entry[1], 16):
78                                         caid_name = caid_entry[2]
79                                         break
80                         return caid_name + ":%04x:%04x:%04x:%04x" % (int(self.current_caid,16),int(self.current_provid,16),info.getInfo(iServiceInformation.sSID),int(self.current_ecmpid,16))
81                 except:
82                         pass
83                 return ""
84
85         def createResolution(self,info):
86                 xres = info.getInfo(iServiceInformation.sVideoWidth)
87                 if xres == -1:
88                         return ""
89                 yres = info.getInfo(iServiceInformation.sVideoHeight)
90                 mode = ("i", "p", "")[info.getInfo(iServiceInformation.sProgressive)]
91                 fps  = str((info.getInfo(iServiceInformation.sFrameRate) + 500) / 1000)
92                 return str(xres) + "x" + str(yres) + mode + fps
93
94         def createVideoCodec(self,info):
95                 return ("MPEG2", "MPEG4", "MPEG1", "MPEG4-II", "VC1", "VC1-SM", "")[info.getInfo(iServiceInformation.sVideoType)]
96
97         def createFrequency(self,fedata):
98                 frequency = fedata.get("frequency")
99                 if frequency:
100                         return str(frequency / 1000)
101                 return ""
102
103         def createSymbolRate(self,fedata):
104                 symbolrate = fedata.get("symbol_rate")
105                 if symbolrate:
106                         return str(symbolrate / 1000)
107                 return ""
108
109         def createPolarization(self,fedata):
110                 polarization = fedata.get("polarization_abbreviation")
111                 if polarization:
112                         return polarization
113                 return ""
114
115         def createFEC(self,fedata):
116                 fec = fedata.get("fec_inner")
117                 if fec:
118                         return fec
119                 return ""
120
121         def createModulation(self,fedata):
122                 modulation = fedata.get("modulation")
123                 if modulation:
124                         return modulation
125                 return ""
126
127         def createTunerType(self,feraw):
128                 tunertype = feraw.get("tuner_type")
129                 if tunertype:
130                         return tunertype
131                 return ""
132
133         def createTunerSystem(self,fedata):
134                 tunersystem = fedata.get("system")
135                 if tunersystem:
136                         return tunersystem
137                 return ""
138
139         def createOrbPos(self,feraw):
140                 orbpos = feraw.get("orbital_position")
141                 if orbpos > 1800:
142                         return str((float(3600 - orbpos)) / 10.0) + "W"
143                 elif orbpos > 0:
144                         return str((float(orbpos)) / 10.0) + "E"
145                 return ""
146
147         def createProviderName(self,info):
148                 return info.getInfoString(iServiceInformation.sProvider)
149
150         @cached
151         def getText(self):
152
153                 service = self.source.service
154                 if service is None:
155                         return ""
156                 info = service and service.info()
157
158                 if not info:
159                         return ""
160
161                 if self.type == "CryptoInfo":
162                         self.getCryptoInfo(info)
163                         if config.usage.show_cryptoinfo.value:
164                                 return addspace(self.createCryptoBar(info)) + self.createCryptoSpecial(info)
165                         else:
166                                 return addspace(self.createCryptoBar(info)) + addspace(self.current_source) + self.createCryptoSpecial(info)
167
168                 if self.type == "CryptoBar":
169                         self.getCryptoInfo(info)
170                         return self.createCryptoBar(info)
171
172                 if self.type == "CryptoSpecial":
173                         self.getCryptoInfo(info)
174                         return self.createCryptoSpecial(info)
175
176                 if self.type == "ResolutionString":
177                         return self.createResolution(info)
178
179                 if self.type == "VideoCodec":
180                         return self.createVideoCodec(info)
181
182                 if self.updateFEdata:
183                         feinfo = service.frontendInfo()
184                         if feinfo:
185                                 self.feraw = feinfo.getAll(False)
186                                 if self.feraw:
187                                         self.fedata = ConvertToHumanReadable(self.feraw)
188
189                 feraw=self.feraw
190                 fedata=self.fedata
191
192                 if not feraw or not fedata:
193                         return ""
194
195                 if self.type == "All":
196                         self.getCryptoInfo(info)
197                         if config.usage.show_cryptoinfo.value:
198                                 return addspace(self.createProviderName(info)) + addspace(self.createTunerSystem(fedata)) + addspace(self.createFrequency(fedata)) + addspace(self.createPolarization(fedata))\
199                                 + addspace(self.createSymbolRate(fedata)) + addspace(self.createFEC(fedata)) + addspace(self.createModulation(fedata)) + self.createOrbPos(feraw) + "\n"\
200                                 + addspace(self.createCryptoBar(info)) + addspace(self.createCryptoSpecial(info)) + "\n"\
201                                 + addspace(self.createVideoCodec(info)) + self.createResolution(info)
202                         else:
203                                 return addspace(self.createProviderName(info)) + addspace(self.createTunerSystem(fedata)) + addspace(self.createFrequency(fedata)) + addspace(self.createPolarization(fedata))\
204                                 + addspace(self.createSymbolRate(fedata)) + addspace(self.createFEC(fedata)) + addspace(self.createModulation(fedata)) + self.createOrbPos(feraw) + "\n"\
205                                 + addspace(self.createCryptoBar(info)) + self.current_source + "\n"\
206                                 + addspace(self.createCryptoSpecial(info)) + addspace(self.createVideoCodec(info)) + self.createResolution(info)
207
208                 if self.type == "ServiceInfo":  
209                         return addspace(self.createProviderName(info)) + addspace(self.createTunerSystem(fedata)) + addspace(self.createFrequency(fedata)) + addspace(self.createPolarization(fedata))\
210                         + addspace(self.createSymbolRate(fedata)) + addspace(self.createFEC(fedata)) + addspace(self.createModulation(fedata)) + addspace(self.createOrbPos(feraw))\
211                         + addspace(self.createVideoCodec(info)) + self.createResolution(info)
212
213                 if self.type == "TransponderFrequency":
214                         return self.createFrequency(fedata)
215
216                 if self.type == "TransponderSymbolRate":
217                         return self.createSymbolRate(fedata)
218
219                 if self.type == "TransponderPolarization":
220                         return self.createPolarization(fedata)
221
222                 if self.type == "TransponderFEC":
223                         return self.createFEC(fedata)
224
225                 if self.type == "TransponderModulation":
226                         return self.createModulation(fedata)
227
228                 if self.type == "OrbitalPosition":
229                         return self.createOrbPos(feraw)
230
231                 if self.type == "TunerType":
232                         return self.createTunerType(feraw)
233
234                 if self.type == "TunerSystem":
235                         return self.createTunerSystem(fedata)
236
237                 return _("invalid type")
238
239         text = property(getText)
240
241         @cached
242         def getBool(self):
243                 service = self.source.service
244                 info = service and service.info()
245
246                 if not info:
247                         return False
248
249                 if self.type == "CryptoCaidSecaAvailable":
250                         request_caid = "S"
251                         request_selected = False
252                 elif self.type == "CryptoCaidViaAvailable":
253                         request_caid = "V"
254                         request_selected = False
255                 elif self.type == "CryptoCaidIrdetoAvailable":
256                         request_caid = "I"
257                         request_selected = False
258                 elif self.type == "CryptoCaidNDSAvailable":
259                         request_caid = "Nd"
260                         request_selected = False
261                 elif self.type == "CryptoCaidConaxAvailable":
262                         request_caid = "Co"
263                         request_selected = False
264                 elif self.type == "CryptoCaidCryptoWAvailable":
265                         request_caid = "Cw"
266                         request_selected = False
267                 elif self.type == "CryptoCaidBetaAvailable":
268                         request_caid = "B"
269                         request_selected = False
270                 elif self.type == "CryptoCaidNagraAvailable":
271                         request_caid = "N"
272                         request_selected = False
273                 elif self.type == "CryptoCaidBissAvailable":
274                         request_caid = "Bi"
275                         request_selected = False
276                 elif self.type == "CryptoCaidDreAvailable":
277                         request_caid = "D"
278                         request_selected = False
279                 elif self.type == "CryptoCaidSecaSelected":
280                         request_caid = "S"
281                         request_selected = True
282                 elif self.type == "CryptoCaidViaSelected":
283                         request_caid = "V"
284                         request_selected = True
285                 elif self.type == "CryptoCaidIrdetoSelected":
286                         request_caid = "I"
287                         request_selected = True
288                 elif self.type == "CryptoCaidNDSSelected":
289                         request_caid = "Nd"
290                         request_selected = True
291                 elif self.type == "CryptoCaidConaxSelected":
292                         request_caid = "Co"
293                         request_selected = True
294                 elif self.type == "CryptoCaidCryptoWSelected":
295                         request_caid = "Cw"
296                         request_selected = True
297                 elif self.type == "CryptoCaidBetaSelected":
298                         request_caid = "B"
299                         request_selected = True
300                 elif self.type == "CryptoCaidNagraSelected":
301                         request_caid = "N"
302                         request_selected = True
303                 elif self.type == "CryptoCaidBissSelected":
304                         request_caid = "Bi"
305                         request_selected = True
306                 elif self.type == "CryptoCaidDreSelected":
307                         request_caid = "D"
308                         request_selected = True
309                 else:
310                         return False
311
312                 if info.getInfo(iServiceInformation.sIsCrypted) != 1:
313                         return False
314
315                 data = self.ecmdata.getEcmData()
316
317                 if data is None:
318                         return False
319
320                 current_caid    = data[1]
321
322                 available_caids = info.getInfoObject(iServiceInformation.sCAIDs)
323
324                 for caid_entry in self.caid_data:
325                         if caid_entry[3] == request_caid:
326                                 if(request_selected):
327                                         if int(current_caid, 16) >= int(caid_entry[0], 16) and int(current_caid, 16) <= int(caid_entry[1], 16):
328                                                 return True
329                                 else: # request available
330                                         try:
331                                                 for caid in available_caids:
332                                                         if caid >= int(caid_entry[0], 16) and caid <= int(caid_entry[1], 16):
333                                                                 return True
334                                         except:
335                                                 pass
336
337                 return False
338
339         boolean = property(getBool)
340
341         def changed(self, what):
342                 if what[0] == self.CHANGED_SPECIFIC:
343                         if what[1] in (iPlayableService.evEnd, iPlayableService.evStart, iPlayableService.evUpdatedInfo):
344                                 self.updateFEdata = True
345                         Converter.changed(self, what)
346                 elif what[0] == self.CHANGED_POLL and self.updateFEdata is not None:
347                         self.updateFEdata = False
348                         Converter.changed(self, what)
349