[MerlinSkinThemes] - add support for globals
[enigma2-plugins.git] / serienfilm / src / MovieInfo.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached, ElementError
3 from enigma import iServiceInformation, eServiceReference
4 from ServiceReference import ServiceReference
5 from MovieList import MovieList
6
7 class MovieInfo(Converter, object):
8         MOVIE_SHORT_DESCRIPTION = 0 # meta description when available.. when not .eit short description
9         MOVIE_META_DESCRIPTION = 1 # just meta description when available
10         MOVIE_REC_SERVICE_NAME = 2 # name of recording service
11         MOVIE_REC_FILESIZE = 3 # filesize of recording
12
13         def __init__(self, type):
14                 if type == "ShortDescription":
15                         self.type = self.MOVIE_SHORT_DESCRIPTION
16                 elif type == "MetaDescription":
17                         self.type = self.MOVIE_META_DESCRIPTION
18                 elif type == "RecordServiceName":
19                         self.type = self.MOVIE_REC_SERVICE_NAME
20                 elif type == "FileSize":
21                         self.type = self.MOVIE_REC_FILESIZE
22                 else:
23                         raise ElementError("'%s' is not <ShortDescription|MetaDescription|RecordServiceName|FileSize> for MovieInfo converter" % type)
24                 Converter.__init__(self, type)
25
26         @cached
27         def getText(self):
28                 service = self.source.service
29                 info = self.source.info
30                 if info and service:
31                         if self.type == self.MOVIE_SHORT_DESCRIPTION:
32                                 if service.type == (eServiceReference.idUser | eServiceReference.idDVB):
33                                         s = MovieList.getVirtDirStatistics(info.getName(service))
34                                         if s:
35                                                 return s
36                                 event = self.source.event
37                                 if event:
38                                         descr = info.getInfoString(service, iServiceInformation.sDescription)
39                                         if descr == "":
40                                                 return event.getShortDescription()
41                                         else:
42                                                 return descr
43                         elif self.type == self.MOVIE_META_DESCRIPTION:
44                                 return info.getInfoString(service, iServiceInformation.sDescription)
45                         elif self.type == self.MOVIE_REC_SERVICE_NAME:
46                                 rec_ref_str = info.getInfoString(service, iServiceInformation.sServiceref)
47                                 return ServiceReference(rec_ref_str).getServiceName()
48                         elif self.type == self.MOVIE_REC_FILESIZE:
49                                 filesize = info.getInfoObject(service, iServiceInformation.sFileSize)
50                                 if filesize is not None:
51                                         return "%d MB" % (filesize / (1024*1024))
52                 return ""
53
54         text = property(getText)