-multiple partnerboxes support
[enigma2-plugins.git] / partnerbox / src / Services.py
1 #
2 #  Partnerbox E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2009
7 #  Support: www.dreambox-tools.info
8 #
9 #  This program is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU General Public License
11 #  as published by the Free Software Foundation; either version 2
12 #  of the License, or (at your option) any later version.
13 #
14 #  This program is distributed in the hope that it will be useful,
15 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #  GNU General Public License for more details.
18 #
19
20 from Components.Sources.Source import Source
21 from Components.Sources.ServiceList import ServiceList
22 from Screens.ChannelSelection import service_types_tv
23 from enigma import eServiceReference, eEPGCache
24
25
26 class E2EPGListAllData:
27         def __init__(self, servicereference = "", servicename = "", eventid = 0, eventstart = 0, eventduration = 0, eventtitle = "", eventdescription = "", eventdescriptionextended = ""):
28                 self.servicereference = servicereference
29                 self.servicename = servicename
30                 self.eventid = eventid
31                 self.eventstart = eventstart
32                 self.eventduration = eventduration
33                 self.eventtitle = eventtitle
34                 self.eventdescription = eventdescription
35                 self.eventdescriptionextended = eventdescriptionextended
36
37 class E2ServiceList:
38         def __init__(self, servicereference = "", servicename = ""):
39                 self.servicereference = servicereference
40                 self.servicename = servicename
41
42 class Services( Source ):
43         def __init__(self, session):
44                 Source.__init__(self)
45                 self.session = session
46                 self.servicelist = {}
47                 self.epgcache = eEPGCache.getInstance()
48         
49         def buildList(self, ref, epg):
50                 self.servicelist = ServiceList(ref, command_func = self.getServiceList, validate_commands=False)
51                 list = self.servicelist.getServicesAsList()
52                 E2List = [] 
53                 for index in range(len(list)): 
54                         item = list[index]
55                         servicereference = item[0]
56                         servicename = item[1]
57                         eventstart = 0
58                         eventduration = 0
59                         eventtitle = ""
60                         eventid = 0
61                         eventdescription = ""
62                         eventdescriptionextended = ""
63                         if epg:
64                                 epgref = item[0]
65                                 events = self.epgcache.lookupEvent(['IBDTSERNX', (epgref, 0, -1)])
66                                 if events:
67                                         if events[0][0] is not None:
68                                                 eventid =  events[0][0]
69                                         if events[0][1] is not None:
70                                                 eventstart =  events[0][1]
71                                         if events[0][2] is not None:
72                                                 eventduration =  events[0][2]
73                                         if events[0][3] is not None:
74                                                 eventtitle = events[0][3]
75                                         if events[0][4] is not None:
76                                                 eventdescription= events[0][4]
77                                         if events[0][5] is not None:
78                                                 eventdescriptionextended= events[0][5]
79                                 E2List.append(E2EPGListAllData(servicereference = servicereference, servicename = servicename, eventstart = eventstart, eventduration = eventduration, eventtitle = eventtitle, eventid = eventid, eventdescription= eventdescription, eventdescriptionextended = eventdescriptionextended))
80                         else:
81                                         E2List.append(E2ServiceList(servicereference = item[0], servicename = item[1]))
82                 return E2List
83
84         def buildEPGList(self, ref):
85                 E2List = [] 
86                 events = self.epgcache.lookupEvent(['IBDTSERN',(ref,0,-1,-1)]);
87                 if events:
88                         for item in events:
89                                 servicereference = ""
90                                 servicename = ""
91                                 eventstart = 0
92                                 eventduration = 0
93                                 eventtitle = ""
94                                 eventid = 0
95                                 eventdescription = ""
96                                 eventdescriptionextended = ""
97                                 if item[6] is not None:
98                                         servicereference = item[6]
99                                 if item[7] is not None:
100                                         servicename = item[7]
101                                 if item[1] is not None:
102                                         eventstart = item[1]
103                                 if item[2] is not None:
104                                         eventduration = item[2]
105                                 if item[3] is not None:
106                                         eventtitle = item[3]
107                                 if item[0] is not None:
108                                         eventid = item[0]
109                                 if item[4] is not None:
110                                         eventdescription = item[4]
111                                 if item[5] is not None:
112                                         eventdescriptionextended = item[5]
113                                 if eventstart != 0:
114                                         E2List.append(E2EPGListAllData(servicereference = servicereference, servicename = servicename, eventstart = eventstart, eventduration = eventduration, eventtitle = eventtitle, eventid = eventid, eventdescription= eventdescription, eventdescriptionextended = eventdescriptionextended))
115                 return E2List
116         
117         def getServiceList(self, ref):
118                 self.servicelist.root = ref