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