bb6fbc90f678c54955563c9f4fe2eb9829c701aa
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / EventName.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached
3 from Components.Converter.genre import getGenreStringLong, getGenreStringSub
4
5 class EventName(Converter, object):
6         NAME = 0
7         SHORT_DESCRIPTION = 1
8         EXTENDED_DESCRIPTION = 2
9         FULL_DESCRIPTION = 3
10         ID = 4
11         NAME_NOW = 5
12         NAME_NEXT = 6
13         GENRE = 7
14         RATING = 8
15         SRATING = 9
16         PDC = 10
17         PDCTIME = 11
18         PDCTIMESHORT = 12
19         ISRUNNINGSTATUS = 13
20
21         def __init__(self, type):
22                 Converter.__init__(self, type)
23                 if type == "Description":
24                         self.type = self.SHORT_DESCRIPTION
25                 elif type == "ExtendedDescription":
26                         self.type = self.EXTENDED_DESCRIPTION
27                 elif type == "FullDescription":
28                         self.type = self.FULL_DESCRIPTION
29                 elif type == "ID":
30                         self.type = self.ID
31                 elif type == "NameNow":
32                         self.type = self.NAME_NOW
33                 elif type == "NameNext":
34                         self.type = self.NAME_NEXT
35                 elif type == "Genre":
36                         self.type = self.GENRE
37                 elif type == "Rating":
38                         self.type = self.RATING
39                 elif type == "SmallRating":
40                         self.type = self.SRATING
41                 elif type == "Pdc":
42                         self.type = self.PDC
43                 elif type == "PdcTime":
44                         self.type = self.PDCTIME
45                 elif type == "PdcTimeShort":
46                         self.type = self.PDCTIMESHORT
47                 elif type == "IsRunningStatus":
48                         self.type = self.ISRUNNINGSTATUS
49                 else:
50                         self.type = self.NAME
51
52         @cached
53         def getBoolean(self):
54                 event = self.source.event
55                 if event is None:
56                         return False
57                 if self.type == self.PDC:
58                         if event.getPdcPil():
59                                 return True
60                 return False
61
62         boolean = property(getBoolean)
63
64         @cached
65         def getText(self):
66                 event = self.source.event
67                 if event is None:
68                         return ""
69
70                 if self.type == self.NAME:
71                         return event.getEventName()
72                 elif self.type == self.SRATING:
73                         rating = event.getParentalData()
74                         if rating is None:
75                                 return ""
76                         else:
77                                 country = rating.getCountryCode()
78                                 age = rating.getRating()
79                                 if age == 0:
80                                         return _("All ages")
81                                 elif age > 15:
82                                         return _("bc%s") % age
83                                 else:
84                                         age += 3
85                                         return " %d+" % age
86                 elif self.type == self.RATING:
87                         rating = event.getParentalData()
88                         if rating is None:
89                                 return ""
90                         else:
91                                 country = rating.getCountryCode()
92                                 age = rating.getRating()
93                                 if age == 0:
94                                         return _("Rating undefined")
95                                 elif age > 15:
96                                         return _("Rating defined by broadcaster - %d") % age
97                                 else:
98                                         age += 3
99                                         return _("Minimum age %d years") % age
100                 elif self.type == self.GENRE:
101                         genre = event.getGenreData()
102                         if genre is None:
103                                 return ""
104                         else:
105                                 return getGenreStringSub(genre.getLevel1(), genre.getLevel2())
106                 elif self.type == self.NAME_NOW:
107                         return pgettext("now/next: 'now' event label", "Now") + ": " + event.getEventName()
108                 elif self.type == self.NAME_NEXT:
109                         return pgettext("now/next: 'next' event label", "Next") + ": " + event.getEventName()
110                 elif self.type == self.SHORT_DESCRIPTION:
111                         return event.getShortDescription()
112                 elif self.type == self.EXTENDED_DESCRIPTION:
113                         return event.getExtendedDescription() or event.getShortDescription()
114                 elif self.type == self.FULL_DESCRIPTION:
115                         description = event.getShortDescription()
116                         extended = event.getExtendedDescription()
117                         if description and extended:
118                                 description += '\n'
119                         return description + extended
120                 elif self.type == self.ID:
121                         return str(event.getEventId())
122                 elif self.type == self.PDC:
123                         if event.getPdcPil():
124                                 return _("PDC")
125                         return ""
126                 elif self.type in (self.PDCTIME, self.PDCTIMESHORT):
127                         pil = event.getPdcPil()
128                         if pil:
129                                 if self.type == self.PDCTIMESHORT:
130                                         return _("%02d:%02d") % ((pil & 0x7C0) >> 6, (pil & 0x3F))
131                                 return _("%d.%02d. %02d:%02d") % ((pil & 0xF8000) >> 15, (pil & 0x7800) >> 11, (pil & 0x7C0) >> 6, (pil & 0x3F))
132                         return ""
133                 elif self.type == self.ISRUNNINGSTATUS:
134                         if event.getPdcPil():
135                                 running_status = event.getRunningStatus()
136                                 if running_status == 1:
137                                         return "not running"
138                                 if running_status == 2:
139                                         return "starts in a few seconds"
140                                 if running_status == 3:
141                                         return "pausing"
142                                 if running_status == 4:
143                                         return "running"
144                                 if running_status == 5:
145                                         return "service off-air"
146                                 if running_status in (6,7):
147                                         return "reserved for future use"
148                                 return "undefined"
149                         return ""
150
151         text = property(getText)