Add web/epgnext - returns epgnext of bouquet (similar to epgnow)
[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     NOW=0
7     NEXT=1
8     SERVICE=2
9     TITLE=3
10     
11     def __init__(self, navcore,func=NOW):
12         self.func = func
13         Source.__init__(self)        
14         self.navcore = navcore
15         self.epgcache = eEPGCache.getInstance()
16         
17     def handleCommand(self,cmd):
18         self.command = cmd
19
20     def do_func(self):
21         if self.func is self.TITLE:
22             func = self.searchEvent
23         elif self.func is self.SERVICE:
24             func = self.getEPGofService
25         elif self.func is self.NOW:
26             func = self.getEPGNow
27         elif self.func is self.NEXT:
28             func = self.getEPGNext
29             
30         return func(self.command)
31     
32     def getEPGNow(self,bouqetref):
33         return self.getEPGNowNext(bouqetref)
34     
35     def getEPGNext(self, bouqetref):
36         return self.getEPGNowNext(bouqetref, False)
37     
38     def getEPGNowNext(self, bouqetref, now=True):
39         print "getting EPG NOW/NEXT", bouqetref
40         serviceHandler = eServiceCenter.getInstance()
41         list = serviceHandler.list(eServiceReference(bouqetref))
42         services = list and list.getContent('S')
43         
44         search = ['IBDTSERN']
45         for service in services:
46             if now:
47                 search.append((service,0,-1))
48             else:
49                 search.append((service,1,-1))        
50         
51         events = self.epgcache.lookupEvent(search);
52         if events:
53                 return events
54         else:
55                 return []
56     
57     def getEPGofService(self,cmd):
58         print "getting EPG of Service", cmd
59         events = self.epgcache.lookupEvent(['IBDTSERN',(cmd,0,-1,-1)]);
60         if events:
61                 return events
62         else:
63                 return []
64     
65     def searchEvent(self,cmd):
66         print "getting EPG by title",cmd
67         events = self.epgcache.search(('IBDTSERN',256,eEPGCache.PARTIAL_TITLE_SEARCH,cmd,1));
68         if events:
69             return events
70         else:
71             return []
72         
73     list = property(do_func)
74     lut = {"EventID": 0, "TimeStart": 1,"Duration": 2, "Title": 3, "Description": 4, "DescriptionExtended": 5, "ServiceReference": 6, "ServiceName": 7 }
75
76