Author: duncan
Date: Thu Mar 6 16:55:43 2008
New Revision: 10474
Log:
Added caching to the TV guide
Update calls to get_programs
Modified:
branches/rel-1/freevo/src/helpers/recordserver.py
branches/rel-1/freevo/src/tv/channels.py
branches/rel-1/freevo/src/tv/epg_types.py
branches/rel-1/freevo/src/tv/plugins/xawtv.py
branches/rel-1/freevo/src/tv/tvguide.py
Modified: branches/rel-1/freevo/src/helpers/recordserver.py
==============================================================================
--- branches/rel-1/freevo/src/helpers/recordserver.py (original)
+++ branches/rel-1/freevo/src/helpers/recordserver.py Thu Mar 6 16:55:43 2008
@@ -231,7 +231,7 @@
@kaa.rpc.expose('getScheduledRecordings')
def getScheduledRecordings(self):
- _debug_('getScheduledRecordings()', 1)
+ _debug_('getScheduledRecordings()', 2)
file_ver = None
schedule = None
Modified: branches/rel-1/freevo/src/tv/channels.py
==============================================================================
--- branches/rel-1/freevo/src/tv/channels.py (original)
+++ branches/rel-1/freevo/src/tv/channels.py Thu Mar 6 16:55:43 2008
@@ -272,7 +272,7 @@
chan_name = config.TV_CHANNELS[self.chan_index][1]
chan_id = config.TV_CHANNELS[self.chan_index][0]
- channels = epg_xmltv.get_guide().get_programs(start=time.time(),
stop=time.time(), chanids=[chan_id])
+ channels = epg_xmltv.get_guide().get_programs(time.time(),
time.time(), chan_id)
if channels and channels[0] and channels[0].programs:
if showtime:
@@ -295,7 +295,7 @@
chan_name = config.TV_CHANNELS[self.chan_index][1]
chan_id = config.TV_CHANNELS[self.chan_index][0]
- channels = epg_xmltv.get_guide().get_programs(start=time.time(),
stop=time.time(), chanids=[chan_id])
+ channels = epg_xmltv.get_guide().get_programs(time.time(),
time.time(), chan_id)
if channels and channels[0] and channels[0].programs:
start_t = channels[0].programs[0].start
Modified: branches/rel-1/freevo/src/tv/epg_types.py
==============================================================================
--- branches/rel-1/freevo/src/tv/epg_types.py (original)
+++ branches/rel-1/freevo/src/tv/epg_types.py Thu Mar 6 16:55:43 2008
@@ -38,7 +38,6 @@
# changes are made to the file format.
EPG_VERSION = 6
-
class TvProgram:
channel_id = None
@@ -247,22 +246,29 @@
self.chan_dict[program.channel_id].programs += [program]
- def get_programs(self, start=0, stop=2147483647, chanids=None):
+ def get_programs(self, start=0, stop=2147483647, channel_id=None):
"""
Get all programs that occur at least partially between the start and
stop
timeframe.
@param start: is 0, get all programs from the start.
@param stop: is 2147483647, get all programs until the end.
- @param chanids: can be used to select only certain channel id's, all
channels are returned otherwise.
+ @param channel_id: can be used to select a channel id, all channels
are returned otherwise.
@returns: a list of channels (TvChannel)
"""
- _debug_('get_programs(start=%r, stop=%r, chanids=%r)' %
(time.strftime('%H:%M', time.localtime(start)),
- time.strftime('%H:%M', time.localtime(stop)), chanids))
+ _debug_('get_programs(start=%r, stop=%r, channel_id=%r)' %
(time.strftime('%H:%M', time.localtime(start)),
+ time.strftime('%H:%M', time.localtime(stop)), channel_id))
+
+ global channel_cache
+ channels = channel_cache.cached(start, stop, channel_id)
+ if channels is not None:
+ _debug_('cached channels=%r' % (channels,))
+ return channels
+ channel_cache.reset(start, stop, channel_id)
channels = []
for chan in self.chan_list:
- if chanids and (not chan.id in chanids):
+ if channel_id and chan.id != channel_id:
continue
c = TvChannel(chan.id, chan.displayname, chan.tunerid, chan.logo,
chan.times)
@@ -271,8 +277,10 @@
c.programs = filter(f, chan.programs)
channels.append(c)
+ channel_cache.add(chan.id, c)
- _debug_('get_programs: channels=%r' % (channels,))
+ _debug_('channels=%r' % (channels,))
+ #print 'channels=%r' % (channels,)
return channels
@@ -291,3 +299,72 @@
def __repr__(self):
return '<TvGuide %r>' % (self.EPG_VERSION)
+
+
+
+class ChannelCache:
+ """
+ This class caches the list of channels for get_programs
+ """
+ def __init__(self):
+ self.channel_id = None
+ self.timestamp = float(0)
+ self.start = None
+ self.stop = None
+ self.channel_ids = []
+ self.channels = []
+
+
+ def reset(self, start, stop, channel_id):
+ """
+ Reset the cache to empty
+ """
+ self.channel_id = channel_id
+ if self.channel_id is None:
+ self.timestamp = float(time.time())
+ self.start = start
+ self.stop = stop
+ self.channel_ids = []
+ self.channels = []
+
+
+ def add(self, channel_id, channel):
+ """
+ Add a channel to the cache
+ """
+ if self.channel_id is None:
+ self.channel_ids.append(channel_id)
+ self.channels.append(channel)
+
+
+ def cached(self, start, stop, channel_id):
+ """
+ get the cached channel list for the channel_id
+
+ @param start: start time of the channels
+ @param channel_id: the channel to fetch from the cache
+ @returns: None if the cache is out of date otherwise the list of
channels
+ """
+ if time.time() - self.timestamp > 20:
+ #print 'cache is out of date: %r' % int(time.time() -
self.timestamp)
+ return None
+ if start != self.start:
+ #print 'cache has a different start time: %r != %r' % (start,
self.start)
+ return None
+ if stop != self.stop:
+ #print 'cache has a different stop time: %r != %r' % (stop,
self.stop)
+ return None
+ if len(self.channels) == 0:
+ #print 'cache is empty'
+ return None
+ if channel_id is not None:
+ if channel_id not in self.channel_ids:
+ #print 'cache does not contain channel %r' % (channel_id,)
+ return None
+ n = self.channel_ids.index(channel_id)
+ #print 'cached channel=%r' % (self.channels[n:n+1],)
+ return self.channels[n:n+1]
+ #print 'cached channels=%r' % (self.channels[:],)
+ return self.channels[:]
+
+channel_cache = ChannelCache()
Modified: branches/rel-1/freevo/src/tv/plugins/xawtv.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/xawtv.py (original)
+++ branches/rel-1/freevo/src/tv/plugins/xawtv.py Thu Mar 6 16:55:43 2008
@@ -99,7 +99,7 @@
chan_name = config.TV_CHANNELS[self.tuner_chidx][1]
chan_id = config.TV_CHANNELS[self.tuner_chidx][0]
- channels = epg.get_guide().get_programs(start=time.time(),
stop=time.time(), chanids=[chan_id])
+ channels = epg.get_guide().get_programs(time.time(), time.time(),
chan_id)
if channels and channels[0] and channels[0].programs:
start_s = time.strftime(config.TV_TIME_FORMAT,
time.localtime(channels[0].programs[0].start))
Modified: branches/rel-1/freevo/src/tv/tvguide.py
==============================================================================
--- branches/rel-1/freevo/src/tv/tvguide.py (original)
+++ branches/rel-1/freevo/src/tv/tvguide.py Thu Mar 6 16:55:43 2008
@@ -67,7 +67,7 @@
msgtext = _('Preparing the program guide')
guide = tv.epg_xmltv.get_guide(PopupBox(text=msgtext))
# getting channels
- channels = guide.get_programs(start=start_time+1, stop=stop_time-1)
+ channels = guide.get_programs(start_time+1, stop_time-1)
if not channels:
AlertBox(text=_('TV Guide is corrupt!')).show()
return
@@ -359,7 +359,7 @@
# we need to determine the program,
# that is running now at the selected channel
- programs = self.guide.get_programs(start=start_time+1,
stop=stop_time-1, chanids=old_selected.channel_id)
+ programs = self.guide.get_programs(start_time+1, stop_time-1,
old_selected.channel_id)
if len(programs) > 0 and len(programs[0].programs) > 0:
selected = programs[0].programs[0]
@@ -379,7 +379,7 @@
start_channel = self.start_channel
# we need to determine the new selected program
- programs = self.guide.get_programs(start=new_start_time+1,
stop=new_end_time-1, chanids=self.start_channel)
+ programs = self.guide.get_programs(new_start_time+1, new_end_time-1,
self.start_channel)
if len(programs) > 0 and len(programs[0].programs) > 0:
selected = programs[0].programs[0]
@@ -397,8 +397,7 @@
"""
_debug_('rebuild(start_time=%r, stop_time=%r, start_channel=%r,
selected=%r)' % (start_time, stop_time, start_channel, selected), 1)
self.guide = tv.epg_xmltv.get_guide()
- #channels = self.guide.get_programs(start=start_time+1,
stop=stop_time-1, chanids=[start_channel])
- channels = self.guide.get_programs(start=start_time+1,
stop=stop_time-1, chanids=None)
+ channels = self.guide.get_programs(start_time+1, stop_time-1)
table = [ ]
@@ -413,7 +412,7 @@
# table header
table += [ ['Chan'] ]
for i in range(int(self.n_cols)):
- table[0] += [ start_time + self.col_time * i* 60 ]
+ table[0] += [ start_time + self.col_time * i * 60 ]
table += [ self.selected ] # the selected program
@@ -479,9 +478,9 @@
channel = self.guide.chan_dict[last_prg.channel_id]
if full_scan:
- all_programs = self.guide.get_programs(start_time-24*60*60,
stop_time+24*60*60, [ channel.id ])
+ all_programs = self.guide.get_programs(start_time-24*60*60,
stop_time+24*60*60, channel.id)
else:
- all_programs = self.guide.get_programs(start_time+1, stop_time-1,
[ channel.id ])
+ all_programs = self.guide.get_programs(start_time+1, stop_time-1,
channel.id)
# Current channel programs
programs = all_programs[0].programs
@@ -503,7 +502,7 @@
else:
return self.change_program(value, True)
else:
- if i+value >= 0:
+ if i + value >= 0:
prg = programs[i+value]
elif full_scan:
prg = programs[0]
@@ -564,7 +563,7 @@
channel = self.guide.chan_list[channel_pos]
- programs = self.guide.get_programs(start_time+1, stop_time-1, [
channel.id ])
+ programs = self.guide.get_programs(start_time+1, stop_time-1,
channel.id)
programs = programs[0].programs
prg = None
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog