servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / python / Components / Converter / RdsInfo.py
1 from enigma import iRdsDecoder, iPlayableService
2 from Components.Converter.Converter import Converter
3 from Components.Element import cached
4
5 class RdsInfo(Converter, object):
6         RASS_INTERACTIVE_AVAILABLE = 0
7         RTP_TEXT_CHANGED = 1
8         RADIO_TEXT_CHANGED = 2
9
10         def __init__(self, type):
11                 Converter.__init__(self, type)
12                 self.type, self.interesting_events = {
13                                 "RadioText": (self.RADIO_TEXT_CHANGED, (iPlayableService.evUpdatedRadioText,)),
14                                 "RtpText": (self.RTP_TEXT_CHANGED, (iPlayableService.evUpdatedRtpText,)),
15                                 "RasInteractiveAvailable": (self.RASS_INTERACTIVE_AVAILABLE, (iPlayableService.evUpdatedRassInteractivePicMask,))
16                         }[type]
17
18         @cached
19         def getText(self):
20                 decoder = self.source.decoder
21                 text = ""
22                 if decoder:
23                         if self.type == self.RADIO_TEXT_CHANGED:
24                                 text = decoder.getText(iRdsDecoder.RadioText)
25                         elif self.type == self.RTP_TEXT_CHANGED:
26                                 text = decoder.getText(iRdsDecoder.RtpText)
27                         else:
28                                 print "unknown RdsInfo Converter type", self.type
29                 return text
30
31         text = property(getText)
32
33         @cached
34         def getBoolean(self):
35                 decoder = self.source.decoder
36                 if self.type == self.RASS_INTERACTIVE_AVAILABLE:
37                         mask = decoder and decoder.getRassInteractiveMask()
38                         return (mask and mask[0] & 1 and True) or False
39                 elif self.type == self.RADIO_TEXT_CHANGED:
40                         return (len(decoder.getText(iRdsDecoder.RadioText)) and True) or False
41                 elif self.type == self.RTP_TEXT_CHANGED:
42                         return (len(decoder.getText(iRdsDecoder.RtpText)) and True) or False
43         boolean = property(getBoolean)
44
45         def changed(self, what):
46                 if what[0] != self.CHANGED_SPECIFIC or what[1] in self.interesting_events:
47                         Converter.changed(self, what)