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