move service related epg-now/next to separate call (http://dreambox/web/epgservicenex...
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / EPG.py
1 from Components.Sources.Source import Source
2 from ServiceReference import ServiceReference
3 from enigma import eServiceCenter, eServiceReference, eEPGCache
4
5 class EPG( Source):
6     BOUQUETNOW=0
7     BOUQUETNEXT=1
8     SERVICENOW=2
9     SERVICENEXT=3
10     SERVICE=4
11     TITLE=5
12     BOUQUET=6
13
14
15     def __init__(self, navcore, func=BOUQUETNOW):
16         self.func = func
17         Source.__init__(self)        
18         self.navcore = navcore
19         self.epgcache = eEPGCache.getInstance()
20         self.command = None
21         
22     def handleCommand(self, cmd):
23         self.command = cmd
24
25     def do_func(self):
26         if not self.command is None:
27             if self.func is self.TITLE:
28                 func = self.searchEvent
29             elif self.func is self.SERVICE:
30                 func = self.getEPGofService
31             elif self.func is self.BOUQUETNOW:
32                 func = self.getBouquetEPGNow
33             elif self.func is self.BOUQUETNEXT:
34                 func = self.getBouquetEPGNext
35             elif self.func is self.BOUQUET:
36                 func = self.getEPGofBouquet
37             elif self.func is self.SERVICENOW:
38                 func = self.getServiceEPGNow
39             elif self.func is self.SERVICENEXT:
40                 func = self.getServiceEPGNext
41             
42             return func(self.command)
43         else:
44             return []
45     
46     def getBouquetEPGNow(self, ref):
47         return self.getEPGNowNext(ref)
48     
49     def getBouquetEPGNext(self, ref):
50         return self.getEPGNowNext(ref, False)
51     
52     def getServiceEPGNow(self, ref):
53         return self.getEPGNowNext(ref, True, True)
54     
55     def getServiceEPGNext(self, ref):
56         return self.getEPGNowNext(ref, False, True)
57     
58     def getEPGNowNext(self, ref, now=True, service=False):
59         print "[WebComponents.EPG] getting EPG NOW/NEXT", ref
60         search = ['IBDTSERN']
61
62         if service:
63             if now:
64                 search.append((ref, 0, -1))
65             else:
66                 search.append((ref, 1, -1))
67                
68             events = self.epgcache.lookupEvent(search)
69             if events:
70                 return events
71                 
72         else:
73             serviceHandler = eServiceCenter.getInstance()
74             list = serviceHandler.list(eServiceReference(ref))
75             services = list and list.getContent('S')
76             search = ['IBDTSERN']
77             
78             if len(services) > 0: # It's a Bouquet
79                 for service in services:
80                     if now:
81                         search.append((service,0,-1))
82                     else:
83                         search.append((service,1,-1))
84          
85             
86             events = self.epgcache.lookupEvent(search)
87             if events:
88                 return events
89
90         return []
91         
92     
93     def getEPGofService(self, ref, options = 'IBDTSERN'):
94         print "getting EPG of Service", ref
95         events = self.epgcache.lookupEvent([options ,(ref,0,-1,-1)]);
96         if events:
97                 return events
98         else:
99                 return []
100     
101     def getEPGofBouquet(self, bouqetref):
102         print "[WebComponents.EPG] getting EPG for Bouquet", bouqetref
103         
104         serviceHandler = eServiceCenter.getInstance()
105         sl = serviceHandler.list(eServiceReference(bouqetref))
106         services = sl and sl.getContent('S')
107         
108         search = ['IBDTSERN']
109         
110         for service in services:
111             search.append((service,0,-1,-1))
112         
113         events = self.epgcache.lookupEvent(search)
114         
115         if events:
116             return events
117         else:
118             return []
119         
120         
121     def searchEvent(self, cmd):
122         print "[WebComponents.EPG] getting EPG by title",cmd
123         events = self.epgcache.search(('IBDTSERN',256,eEPGCache.PARTIAL_TITLE_SEARCH,cmd,1));
124         if events:
125             return events
126         else:
127             return []
128         
129     list = property(do_func)
130     lut = {"EventID": 0, "TimeStart": 1,"Duration": 2, "Title": 3, "Description": 4, "DescriptionExtended": 5, "ServiceReference": 6, "ServiceName": 7 }
131
132