Intital CVS Version by 3c5x9
[enigma2-plugins.git] / webinterface / src / usr / lib / enigma2 / python / Components / Sources / EPG.py
1 from enigma import *
2
3 from Source import Source
4 from ServiceReference import ServiceReference
5
6 class EPG( Source):
7     def __init__(self, navcore):
8         Source.__init__(self)
9         self.navcore = navcore
10         self.epgcache = eEPGCache.getInstance()
11     def handleCommand(self,cmd):
12         print "EPG.handleCommand %s" %cmd   
13         self.command = cmd
14
15     def getEPGNowNext(self):
16         print "getting EPG of Service ",self.command
17         events = self.epgcache.lookupEvent(['IBDTSERN',(self.command,0,0,-1)]);
18         if events:
19                 return self.convertToDictonary(events[:2])
20         else:
21                 return False
22     
23     def getEPGofService(self):
24         print "getting EPG of Service ",self.command
25         events = self.epgcache.lookupEvent(['IBDTSERN',(self.command,0,-1,-1)]);
26         if events:
27                 return self.convertToDictonary(events)
28         else:
29                 return False
30     
31     def searchEvent(self):
32         print "searchEvent",self.command
33         events = self.epgcache.search(('IBDTSERN',1024,eEPGCache.PARTIAL_TITLE_SEARCH,self.command,1));
34         if events:
35             return self.convertToDictonary(events)
36         else:
37             return False
38     def convertToDictonary(self,EventList):
39         result=[]
40         for x in EventList:
41             row = {}                        
42             row['EventID']=self.convertIfEmpty(x[0])
43             row['TimeStart']=self.convertIfEmpty(x[1])
44             row['Duration']=self.convertIfEmpty(x[2])
45             row['Title']=self.convertIfEmpty(x[3])
46             row['Description']=self.convertIfEmpty(x[4])
47             row['DescriptionExtended']=self.convertIfEmpty(x[5])
48             row['ServiceReference']=self.convertIfEmpty(x[6])
49             row['ServiceName']=self.convertIfEmpty(x[7])
50             result.append(row)                                    
51         return result
52     def convertIfEmpty(self,string):
53         if string == "":
54             return "N/A"
55         else:
56             return string.__str__()
57     epg = property(searchEvent,getEPGofService,getEPGNowNext)