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