[MerlinSkinThemes] - add support for globals
[enigma2-plugins.git] / serienfilm / src / ServiceTime.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached, ElementError
3 from enigma import iServiceInformation, eServiceReference
4
5 class ServiceTime(Converter, object):
6         STARTTIME = 0
7         ENDTIME = 1
8         DURATION = 2
9
10         def __init__(self, type):
11 #               print("ServiceTimeSF init: (%s, %s)" %(sstr(self), type))
12                 Converter.__init__(self, type)
13                 if type == "EndTime":
14                         self.type = self.ENDTIME
15                 elif type == "StartTime":
16                         self.type = self.STARTTIME
17                 elif type == "Duration":
18                         self.type = self.DURATION
19                 else:
20                         raise ElementError("'%s' is not <StartTime|EndTime|Duration> for ServiceTime converter" % type)
21
22         @cached
23         def getTime(self):
24 #               print("ServiceTimeSF.getTime %x, self=%s" % (id(self.getTime), sstr(self)))
25                 service = self.source.service
26                 info = self.source.info
27                 
28                 if not info or not service:
29                         return None
30
31                 if self.type == self.STARTTIME:
32                         return info.getInfo(service, iServiceInformation.sTimeCreate)
33                 elif self.type == self.ENDTIME:
34                         begin = info.getInfo(service, iServiceInformation.sTimeCreate)
35                         len = info.getLength(service)
36                         return begin + len
37                 elif self.type == self.DURATION:
38                         da = info.getLength(service)
39 #                       print "[SF-Plugin] ServiceTimeSF.getTime srv=%x,%x, getLength = %d -- %s" % (service.type, service.flags, da, sstr(self))
40                         if da == -1 and service.type == (eServiceReference.idUser | eServiceReference.idDVB):
41                                 return None             # otherwise -1:59
42                         return info.getLength(service)
43
44         time = property(getTime)