remove unneeded N/A
[enigma2.git] / lib / python / Components / Converter / ServiceInfo.py
1 from Components.Converter.Converter import Converter
2 from enigma import iServiceInformation, iPlayableService
3 from Components.Element import cached
4
5 class ServiceInfo(Converter, object):
6         HAS_TELETEXT = 0
7         IS_MULTICHANNEL = 1
8         IS_CRYPTED = 2
9         IS_WIDESCREEN = 3
10         SUBSERVICES_AVAILABLE = 4
11
12         def __init__(self, type):
13                 Converter.__init__(self, type)
14                 self.type = {
15                                 "HasTelext": self.HAS_TELETEXT,
16                                 "IsMultichannel": self.IS_MULTICHANNEL,
17                                 "IsCrypted": self.IS_CRYPTED,
18                                 "IsWidescreen": self.IS_WIDESCREEN,
19                                 "SubservicesAvailable": self.SUBSERVICES_AVAILABLE,
20                         }[type]
21
22                 self.interesting_events = {
23                                 self.HAS_TELETEXT: [iPlayableService.evUpdatedInfo],
24                                 self.IS_MULTICHANNEL: [iPlayableService.evUpdatedInfo],
25                                 self.IS_CRYPTED: [iPlayableService.evUpdatedInfo],
26                                 self.IS_WIDESCREEN: [iPlayableService.evUpdatedEventInfo],
27                                 self.SUBSERVICES_AVAILABLE: [iPlayableService.evUpdatedEventInfo]
28                         }[self.type]
29
30         @cached
31         def getServiceInfoValue(self, info, what):
32                 v = info.getInfo(what)
33                 if v != -2:
34                         return "N/A"
35                 return info.getInfoString(what)
36
37         @cached
38         def getBoolean(self):
39                 service = self.source.service
40                 info = service and service.info()
41                 if not info:
42                         return False
43                 
44                 if self.type == self.HAS_TELETEXT:
45                         tpid = info.getInfo(iServiceInformation.sTXTPID)
46                         return tpid != -1
47                 elif self.type == self.IS_MULTICHANNEL:
48                         # FIXME. but currently iAudioTrackInfo doesn't provide more information.
49                         audio = service.audioTracks()
50                         if audio:
51                                 n = audio.getNumberOfTracks()
52                                 for x in range(n):
53                                         i = audio.getTrackInfo(x)
54                                         description = i.getDescription();
55                                         if description.find("AC3") != -1 or description.find("DTS") != -1:
56                                                 return True
57                         return False
58                 elif self.type == self.IS_CRYPTED:
59                         return info.getInfo(iServiceInformation.sIsCrypted) == 1
60                 elif self.type == self.IS_WIDESCREEN:
61                         return info.getInfo(iServiceInformation.sAspect) in [3, 4, 7, 8, 0xB, 0xC, 0xF, 0x10]
62                 elif self.type == self.SUBSERVICES_AVAILABLE:
63                         subservices = service.subServices()
64                         return subservices and subservices.getNumberOfSubservices() > 0
65
66         boolean = property(getBoolean)
67
68         def changed(self, what):
69                 if what[0] != self.CHANGED_SPECIFIC or what[1] in self.interesting_events:
70                         Converter.changed(self, what)