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