@
twinther
Great plugin! I've been using it in the UK with data from the RadioTimes web site (via a third party app to create the XMLTV file and it works great)
I've also been looking into optimising the speed (on top of the changes from timpinkawa) it and have a few comments.
In the getProgramList() you can make use of a member variable dictionary to cache the program lists to memory giving virtually instant (< 0.1sec) retrieval of the program list (although obviously this could potentially use a lot of memory, in the UK 14 days of 50 channels is about 18000 programs which increases memory usage of XBMC by about 12MB, so not a big deal for this size of data)
(I've just noticed you make use of the start and end dates in the latest code when querying the database, I haven't found that necessary when caching the data to memory)
You've updated the code quite a lot but something like this should do the trick:
Code:
#in Source __init__
self.cache = dict()
#in _retrieveProgramListFromDatabase(self, channel, startTime):
key = '%s-%s' % (self.KEY, channel.id.replace('/', ''))
if key in self.cache:
return self.cache[key]
programList = list()
c = self.conn.cursor()
c.execute('SELECT * FROM programs WHERE channel=? AND source=?', [channel.id, self.KEY])
for row in c:
program = Program(channel, row['title'], row['start_date'], row['end_date'], row['description'], row['image_large'], row['image_small'])
programList.append(program)
self.cache[key] = programList
return programList
#the appropriate key in self.cache will also need to be cleared whenever the database is updated
Also just a couple of minor bugs, in gui.py when you set the position of the current time you don't take into account the day so you get the line at the "NOW" time regardless of the day;
Code:
# move timebar to current time
timeDelta = datetime.datetime.today() - self.viewStartDate
c = self.getControl(4100)
(x, y) = c.getPosition()
if timeDelta.days == 0:
c.setPosition(self._secondsToXposition(timeDelta.seconds), y)
else:
c.setPosition(-100, y)
In _scheduleNotification in notification.py again you ignore the day so the notification can appear 24 hours early;
Code:
t = self._timeToNotification(program)
timeToNotification = ((t.days * 86400) + t.seconds) / 60
if timeToNotification < 0:
return
Also in the Notification class in the scheduleNotifications function you can grab the channel list just once and then
pass it into _processSingleNotification function (even better is to have the list as a member variable)
And in the onAction() of the TVGuide class, if you add this
Code:
elif action.getId() == 159: #KEY_HOME
self.viewStartDate = datetime.datetime.today()
self.viewStartDate -= datetime.timedelta(minutes = self.viewStartDate.minute % 30)
self.onRedrawEPG(self.page, self.viewStartDate)
Then pressing the Home key will return the guide to the current time, which I use a lot!
HTH