web/epgnow & web/epgnext can now handle a Reference for a single service correctly...
[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     NEXT=1
8     SERVICE=2
9     TITLE=3
10     BOUQUET=4
11     
12     def __init__(self, navcore, func=NOW):
13         self.func = func
14         Source.__init__(self)        
15         self.navcore = navcore
16         self.epgcache = eEPGCache.getInstance()
17         self.command = None
18         
19     def handleCommand(self, cmd):
20         self.command = cmd
21
22     def do_func(self):
23         if not self.command is None:
24             if self.func is self.TITLE:
25                 func = self.searchEvent
26             elif self.func is self.SERVICE:
27                 func = self.getEPGofService
28             elif self.func is self.NOW:
29                 func = self.getEPGNow
30             elif self.func is self.NEXT:
31                 func = self.getEPGNext
32             elif self.func is self.BOUQUET:
33                 func = self.getEPGofBouquet
34             
35             return func(self.command)
36         else:
37             return []
38     
39     def getEPGNow(self, ref):
40         return self.getEPGNowNext(ref)
41     
42     def getEPGNext(self, ref):
43         return self.getEPGNowNext(ref, False)
44     
45     def getEPGNowNext(self, ref, now=True):
46         print "getting EPG NOW/NEXT", ref
47         search = ['IBDTSERN']
48         
49         if now:
50             search.append((ref, 0, -1))
51         else:
52             search.append((ref, 1, -1))
53            
54         events = self.epgcache.lookupEvent(search)
55         if events:
56             return events
57                 
58         else:
59             serviceHandler = eServiceCenter.getInstance()
60             list = serviceHandler.list(eServiceReference(ref))
61             services = list and list.getContent('S')
62             search = ['IBDTSERN']
63             
64             if len(services) > 0: # It's a Bouquet
65                 for service in services:
66                     if now:
67                         search.append((service,0,-1))
68                     else:
69                         search.append((service,1,-1))
70          
71             
72             events = self.epgcache.lookupEvent(search)
73             if events:
74                     return events
75
76         return []
77         
78     
79     def getEPGofService(self, ref, options = 'IBDTSERN'):
80         print "getting EPG of Service", ref
81         events = self.epgcache.lookupEvent([options ,(ref,0,-1,-1)]);
82         if events:
83                 return events
84         else:
85                 return []
86     
87     def getEPGofBouquet(self, bouqetref):
88         print "[EPG.py] getting EPG for Bouquet", bouqetref
89         
90         serviceHandler = eServiceCenter.getInstance()
91         sl = serviceHandler.list(eServiceReference(bouqetref))
92         services = sl and sl.getContent('S')
93         
94         search = ['IBDTSERN']
95         
96         for service in services:
97             search.append((service,0,-1,-1))
98         
99         events = self.epgcache.lookupEvent(search)
100         
101         if events:
102             return events
103         else:
104             return []
105         
106         
107     def searchEvent(self, cmd):
108         print "getting EPG by title",cmd
109         events = self.epgcache.search(('IBDTSERN',256,eEPGCache.PARTIAL_TITLE_SEARCH,cmd,1));
110         if events:
111             return events
112         else:
113             return []
114         
115     list = property(do_func)
116     lut = {"EventID": 0, "TimeStart": 1,"Duration": 2, "Title": 3, "Description": 4, "DescriptionExtended": 5, "ServiceReference": 6, "ServiceName": 7 }
117
118