Add possibility to check for playability of service(s)
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / ServicePlayable.py
1 from enigma import eServiceCenter, eServiceReference
2 from Components.Sources.Source import Source
3
4 class ServicePlayable(Source):
5         
6         SINGLE = 0
7         BOUQUET = 1
8         
9         def __init__(self, session, type=SINGLE):
10                 Source.__init__(self)
11                 
12                 self.session = session
13                 self.sci = eServiceCenter.getInstance()
14                 self.command = None
15                 self.info = None
16                 self.type = type
17                         
18         
19         def handleCommand(self, cmd):
20                 self.command = cmd
21
22
23         def convertStrTrueFalse(self, int):
24                 if int > 0:
25                         return str(True)
26                 else:
27                         return str(False)
28
29         
30         def isServicePlayable(self, refToPlay, refPlaying=None):        
31                 if self.info is None:
32                         self.info = self.sci.info(refToPlay)
33                 
34                 if refPlaying is None:
35                         return self.convertStrTrueFalse( self.info.isPlayable(refToPLay) )
36                 else:
37                         return self.convertStrTrueFalse( self.info.isPlayable(refToPlay, refPlaying))
38                         
39                 return false
40
41
42         def getPlayableServices(self, refToPlay, refPlaying=None):              
43                 list = []
44                 
45                 if self.type == self.BOUQUET: #Bouquet
46                         slist = self.sci.list(refToPlay)
47                         services = slist and slist.getContent('S')
48                                 
49                         if services:                            
50                                 list.extend([   
51                                         (service, self.isServicePlayable(eServiceReference(service), refPlaying)) for service in services
52                                 ])
53                                 
54                 else: #Single service
55                         playable = self.isServicePlayable(refToPlay, refPlaying)
56                         list.append((refToPlay.toString(), playable))
57                         
58                 return list
59         
60
61         def getList(self):
62                 list = []
63
64                 if 'sRef' in self.command:
65                         refToPlay = eServiceReference(self.command['sRef'])
66                         
67                         if 'sRefPlaying' in self.command:
68                                 refPlaying = eServiceReference(self.command['sRef'])                            
69                                 list = self.getPlayableServices(refToPlay, refPlaying)
70                                 
71                         else:
72                                 list = self.getPlayableServices(refToPlay)
73                 
74                 return list
75                 
76         
77         list = property(getList)
78         lut = { "ServiceReference" : 0,
79                         "ServicePlayable" : 1
80                         }