add /web/epgbouquet.xml
[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     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, bouqetref):
40         return self.getEPGNowNext(bouqetref)
41     
42     def getEPGNext(self, bouqetref):
43         return self.getEPGNowNext(bouqetref, False)
44     
45     def getEPGNowNext(self, bouqetref, now=True):
46         print "getting EPG NOW/NEXT", bouqetref
47         serviceHandler = eServiceCenter.getInstance()
48         list = serviceHandler.list(eServiceReference(bouqetref))
49         services = list and list.getContent('S')
50         
51         search = ['IBDTSERN']
52         for service in services:
53             if now:
54                 search.append((service,0,-1))
55             else:
56                 search.append((service,1,-1))        
57         
58         events = self.epgcache.lookupEvent(search)
59         if events:
60                 return events
61         else:
62                 return []
63     
64     def getEPGofService(self, ref, options = 'IBDTSERN'):
65         print "getting EPG of Service", cmd
66         events = self.epgcache.lookupEvent([options ,(ref,0,-1,-1)]);
67         if events:
68                 return events
69         else:
70                 return []
71     
72     def getEPGofBouquet(self, bouqetref):
73         print "[EPG.py] getting EPG for Bouquet", bouqetref
74         
75         serviceHandler = eServiceCenter.getInstance()
76         sl = serviceHandler.list(eServiceReference(bouqetref))
77         services = sl and sl.getContent('S')
78         
79         search = ['IBDTSERN']
80         
81         for service in services:
82             search.append((service,0,-1,-1))
83         
84         events = self.epgcache.lookupEvent(search)
85         
86         if events:
87             return events
88         else:
89             return []
90         
91         
92     def searchEvent(self, cmd):
93         print "getting EPG by title",cmd
94         events = self.epgcache.search(('IBDTSERN',256,eEPGCache.PARTIAL_TITLE_SEARCH,cmd,1));
95         if events:
96             return events
97         else:
98             return []
99         
100     list = property(do_func)
101     lut = {"EventID": 0, "TimeStart": 1,"Duration": 2, "Title": 3, "Description": 4, "DescriptionExtended": 5, "ServiceReference": 6, "ServiceName": 7 }
102
103