Update of /cvsroot/freevo/freevo/src/tv
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20248/tv
Modified Files:
channels.py program.py tvguide.py
Log Message:
start extract channellist to be independed
Index: program.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/tv/program.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** program.py 17 Nov 2004 19:42:10 -0000 1.1
--- program.py 5 Dec 2004 17:10:06 -0000 1.2
***************
*** 44,47 ****
--- 44,48 ----
import recordings
import favorite
+ import channels
class ProgramItem(Item):
***************
*** 49,67 ****
A tv program item for the tv guide and other parts of the tv submenu.
"""
! def __init__(self, title, start, stop, subtitle='', description='',
! id=None, channel = None, parent=None):
Item.__init__(self, parent, skin_type='video')
! self.title = title
! self.name = self.title
! self.start = start
! self.stop = stop
!
! self.channel = channel
! self.prog_id = id
! self.info['subtitle'] = subtitle
! self.info['description'] = description
! key = '%s%s%s' % (channel.chan_id, start, stop)
if recordings.recordings.has_key(key):
self.scheduled = recordings.recordings[key]
--- 50,67 ----
A tv program item for the tv guide and other parts of the tv submenu.
"""
! def __init__(self, program, parent=None):
Item.__init__(self, parent, skin_type='video')
+ self.program = program
+ self.title = program.title
+ self.name = program.title
+ self.start = program.start
+ self.stop = program.stop
! self.channel = program.channel
! self.prog_id = program.id
! self.info['subtitle'] = program.subtitle
! self.info['description'] = program.description
! key = '%s%s%s' % (program.channel.chan_id, program.start,
program.stop)
if recordings.recordings.has_key(key):
self.scheduled = recordings.recordings[key]
***************
*** 98,102 ****
compare function, return 0 if the objects are identical, 1 otherwise
"""
! if not isinstance(other, ProgramItem):
return 1
--- 98,102 ----
compare function, return 0 if the objects are identical, 1 otherwise
"""
! if not isinstance(other, (ProgramItem, channels.Program)):
return 1
Index: tvguide.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/tv/tvguide.py,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** tvguide.py 5 Dec 2004 13:01:12 -0000 1.63
--- tvguide.py 5 Dec 2004 17:10:06 -0000 1.64
***************
*** 10,13 ****
--- 10,16 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.64 2004/12/05 17:10:06 dischi
+ # start extract channellist to be independed
+ #
# Revision 1.63 2004/12/05 13:01:12 dischi
# delete old tv variables, rename some and fix detection
***************
*** 128,131 ****
--- 131,135 ----
from application import MenuApplication
from item import Item
+ from program import ProgramItem
import logging
***************
*** 155,159 ****
self.CHAN_NO_DATA = _('This channel has no data loaded')
self.last_update = 0
!
def start(self, parent):
--- 159,163 ----
self.CHAN_NO_DATA = _('This channel has no data loaded')
self.last_update = 0
!
def start(self, parent):
***************
*** 173,180 ****
start_time = self.current_time - 1800
stop_time = self.current_time + 3*3600
- config.TV_CHANNELLIST.import_programs(start_time, stop_time)
! self.channel = config.TV_CHANNELLIST.get()
! self.selected = self.channel.get(self.current_time)[0]
box.destroy()
--- 177,186 ----
start_time = self.current_time - 1800
stop_time = self.current_time + 3*3600
! # current channel is the first one
! self.channel = config.TV_CHANNELLIST[0]
!
! # current program is the current running
! self.selected = ProgramItem(self.channel.get(self.current_time)[0])
box.destroy()
***************
*** 220,244 ****
if event == MENU_UP:
! config.TV_CHANNELLIST.up()
! self.channel = config.TV_CHANNELLIST.get()
! try:
! self.selected = self.channel.get(self.current_time)[0]
! except Exception, e:
! print e
! print self.current_time
self.refresh()
elif event == MENU_DOWN:
! config.TV_CHANNELLIST.down()
! self.channel = config.TV_CHANNELLIST.get()
! try:
! self.selected = self.channel.get(self.current_time)[0]
! except Exception, e:
! print e
! print self.current_time
self.refresh()
elif event == MENU_LEFT:
! self.selected = self.channel.prev(self.selected)
if self.selected.start:
self.current_time = self.selected.start + 1
--- 226,240 ----
if event == MENU_UP:
! self.channel = config.TV_CHANNELLIST.get(-1, self.channel)
! self.selected =
ProgramItem(self.channel.get(self.current_time)[0])
self.refresh()
elif event == MENU_DOWN:
! self.channel = config.TV_CHANNELLIST.get(1, self.channel)
! self.selected =
ProgramItem(self.channel.get(self.current_time)[0])
self.refresh()
elif event == MENU_LEFT:
! self.selected = ProgramItem(self.channel.get_relative(-1,
self.selected.program))
if self.selected.start:
self.current_time = self.selected.start + 1
***************
*** 248,252 ****
elif event == MENU_RIGHT:
! self.selected = self.channel.next(self.selected)
if self.selected.start:
self.current_time = self.selected.start + 1
--- 244,248 ----
elif event == MENU_RIGHT:
! self.selected = ProgramItem(self.channel.get_relative(1,
self.selected.program))
if self.selected.start:
self.current_time = self.selected.start + 1
***************
*** 262,270 ****
elif event == TV_SHOW_CHANNEL:
! items = []
! # channel = config.TV_CHANNELLIST.get_settings_by_id(self.chan_id)
! # for prog in channel.get(time.time(), -1):
! for prog in self.selected.get(time.time(), -1):
! items.append(prog)
cmenu = menu.Menu(self.channel.name, items)
# FIXME: the percent values need to be calculated
--- 258,262 ----
elif event == TV_SHOW_CHANNEL:
! items = self.channel.get(time.time(), -1)
cmenu = menu.Menu(self.channel.name, items)
# FIXME: the percent values need to be calculated
Index: channels.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/tv/channels.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** channels.py 5 Dec 2004 13:01:12 -0000 1.36
--- channels.py 5 Dec 2004 17:10:06 -0000 1.37
***************
*** 42,57 ****
# freevo imports
- import config
import sysconfig
! import plugin
log = logging.getLogger('tv')
- # tv imports
- from program import ProgramItem
-
EPGDB = sysconfig.datafile('epgdb')
- _channels = None
_epg = None
--- 42,52 ----
# freevo imports
import sysconfig
! import recordings
log = logging.getLogger('tv')
EPGDB = sysconfig.datafile('epgdb')
_epg = None
***************
*** 67,185 ****
- def get_new_epg():
- """
- Return a fresh instance of the EPG database.
- """
- global _epg
- _epg = pyepg.get_epg(EPGDB)
-
- return _epg
-
-
- def get_lockfile(which):
- """
- In this function we must figure out which device these settings use
- because we are allowed to have multiple settings for any particular
- device, usually for different inputs (tuner, composite, svideo).
- """
-
- dev_lock = False
- settings = config.TV_CARDS.get(which)
-
- if not settings:
- log.info('No settings for %s' % which)
-
- if isinstance(settings, config.DVBCard):
- dev = settings.adapter
- dev_lock = True
-
- elif isinstance(settings, config.TVCard):
- dev = settings.vdev
- dev_lock = True
-
- else:
- print 'Unknown settings for %s!! This could cause problems!' % which
-
- if dev_lock:
- lockfile = os.path.join(config.FREEVO_CACHEDIR, 'lock.%s' % \
- dev.replace(os.sep, '_'))
- else:
- lockfile = os.path.join(config.FREEVO_CACHEDIR, 'lock.%s' % which)
-
- log.info('lockfile for %s is %s' % (which, lockfile))
- return lockfile
-
-
- def lock_device(which):
- """
- """
-
- lockfile = get_lockfile(which)
-
- if os.path.exists(lockfile):
- return False
-
- else:
- try:
- open(lockfile, 'w').close()
- return True
- except:
- print 'ERROR: cannot open lockfile for %s' % which
- traceback.print_exc()
- return False
-
-
- def unlock_device(which):
- """
- """
-
- lockfile = get_lockfile(which)
-
- if os.path.exists(lockfile):
- try:
- os.remove(lockfile)
- return True
- except:
- print 'ERROR: cannot remove lockfile for %s' % which
- traceback.print_exc()
- return False
-
- else:
- return False
-
-
- def is_locked(which):
- """
- """
-
- lockfile = get_lockfile(which)
-
- if os.path.exists(lockfile):
- return True
-
- else:
- return False
-
-
- def get_actual_channel(channel_id, which):
- """
- """
-
- for chan in get_channels().get_all():
- if chan.id == channel_id:
- for u in chan.uri:
- if u.split(':')[0] == which:
- return u.lstrip('%s:' % which)
-
-
- def get_chan_displayname(channel_id):
-
- for chan in get_channels().get_all():
- if chan.chan_id == channel_id:
- return chan.name
-
- return 'Unknown'
-
-
def when_listings_expire():
--- 62,65 ----
***************
*** 201,230 ****
! def get_dummy_programs(channel, start, stop):
"""
! Return some default ProgramItems with intervals no longer than a
! set default.
"""
! default_prog_interval = 30 * 60
! dummies = []
! d_start = start
! d_stop = 0
!
! sec_after_last = start % default_prog_interval
! sec_until_next = default_prog_interval - sec_after_last
!
! while(d_stop < stop):
! d_stop = d_start + sec_until_next
! if d_stop > stop:
! d_stop = stop
!
! dummies.append(ProgramItem(u'NO DATA', d_start, d_stop,
! id=-1, channel = channel))
! sec_until_next = default_prog_interval
! d_start = d_stop
! return dummies
--- 81,110 ----
! class Program:
"""
! A tv program item for the tv guide and other parts of the tv submenu.
"""
! def __init__(self, title, start, stop, subtitle='', description='',
! id=None, channel = None, parent=None):
! self.title = title
! self.name = self.title
! self.start = start
! self.stop = stop
! self.channel = channel
! self.id = id
! self.subtitle = subtitle
! self.description = description
! key = '%s%s%s' % (channel.chan_id, start, stop)
! if recordings.recordings.has_key(key):
! self.scheduled = recordings.recordings[key]
! else:
! self.scheduled = False
+ # TODO: add category support (from epgdb)
+ self.categories = ''
+ # TODO: add ratings support (from epgdb)
+ self.ratings = ''
***************
*** 235,249 ****
"""
def __init__(self, id, display_name, access_id):
! self.chan_id = id
! self.access_id = ''
! self.uri = []
! self.programs = []
! self.logo = ''
!
! if isinstance(access_id, list) or isinstance(access_id, tuple):
! for a_id in access_id:
! self.__add_uri__(a_id)
! else:
! self.__add_uri__(access_id)
# XXX Change this to config.TV_CHANNEL_DISPLAY_FORMAT or something as
--- 115,122 ----
"""
def __init__(self, id, display_name, access_id):
! self.chan_id = id
! self.access_id = access_id
! self.programs = []
! self.logo = ''
# XXX Change this to config.TV_CHANNEL_DISPLAY_FORMAT or something as
***************
*** 253,327 ****
! def __add_uri__(self, uri):
! """
! Add a URI to the internal list where to find that channel.
! Also save the access_id because many people, mostly North Americans,
! like to use it (usually in the display).
! """
! if uri.find(':') == -1:
! self.access_id = uri
! defaults = []
! if isinstance(config.TV_DEFAULT_DEVICE, list) or \
! isinstance(config.TV_DEFAULT_DEVICE, tuple):
! for s in config.TV_DEFAULT_DEVICE:
! defaults.append(s)
! else:
! defaults.append(config.TV_DEFAULT_DEVICE)
!
! for which in defaults:
! try:
! int(which[-1:])
! except ValueError:
! # This means that TV_DEFAULT_DEVICE does NOT end with
! # a number (it is dvb/tv/ivtv) so we add this channel
! # to all matching TV_CARDS.
! for s in config.TV_CARDS:
! if s.find(which) == 0:
! self.__add_uri__('%s:%s' % (s, uri))
! return
!
! self.uri.append('%s:%s' % (which, uri))
! else:
! self.access_id = uri.split(':')[1]
! self.uri.append(uri)
! def player(self):
"""
! return player object for playing this channel
"""
! for u in self.uri:
! device, uri = u.split(':')
! print device, uri
! # try all internal URIs
! for p in plugin.getbyname(plugin.TV, True):
! print p
! # FIXME: better handling for rate == 1 or 2
! if p.rate(self, device, uri):
! return p, device, uri
! return None
!
! def settings(self):
! """
! return a dict of settings for this channel
! """
! settings = {}
! for u in self.uri:
! type = u.split(':')[0]
! settings[type] = config.TV_CARDS.get(type)
! return settings
! def sort_programs(self):
! f = lambda a, b: cmp(a.start, b.start)
! self.programs.sort(f)
! def import_programs(self, start, stop=-1, progs=[]):
"""
! Get programs from the database to create ProgramItems from then
add them to our local list. If there are gaps between the programs
we will add dummy programs to fill it (TODO).
--- 126,164 ----
! def sort_programs(self):
! f = lambda a, b: cmp(a.start, b.start)
! self.programs.sort(f)
! def __get_dummy_programs(self, start, stop):
"""
! Return some default Program with intervals no longer than a
! set default.
"""
! default_prog_interval = 30 * 60
! dummies = []
! d_start = start
! d_stop = 0
! sec_after_last = start % default_prog_interval
! sec_until_next = default_prog_interval - sec_after_last
! while(d_stop < stop):
! d_stop = d_start + sec_until_next
! if d_stop > stop:
! d_stop = stop
! dummies.append(Program(u'NO DATA', d_start, d_stop,
! id=-1, channel = self))
+ sec_until_next = default_prog_interval
+ d_start = d_stop
! return dummies
! def __import_programs(self, start, stop=-1, progs=[]):
"""
! Get programs from the database to create Program from then
add them to our local list. If there are gaps between the programs
we will add dummy programs to fill it (TODO).
***************
*** 333,339 ****
progs = get_epg().get_programs(self.chan_id, start, stop)
for p in progs:
! i = ProgramItem(p.title, p.start, p.stop, subtitle=p.subtitle,
! description=p['description'], id=p.id,
! channel=self)
new_progs.append(i)
--- 170,176 ----
progs = get_epg().get_programs(self.chan_id, start, stop)
for p in progs:
! i = Program(p.title, p.start, p.stop, subtitle=p.subtitle,
! description=p['description'], id=p.id,
! channel=self)
new_progs.append(i)
***************
*** 344,348 ****
l = len(new_progs)
if not l:
! dummy_progs = get_dummy_programs(self, start, stop)
else:
for p in new_progs:
--- 181,185 ----
l = len(new_progs)
if not l:
! dummy_progs = self.__get_dummy_programs(start, stop)
else:
for p in new_progs:
***************
*** 351,355 ****
# fill gaps before
if p.start > start:
! n = get_dummy_programs(self, start, p.start)
dummy_progs += n
--- 188,192 ----
# fill gaps before
if p.start > start:
! n = self.__get_dummy_programs(start, p.start)
dummy_progs += n
***************
*** 358,362 ****
next_p = new_progs[i+1]
if p.stop < next_p.start:
! n = get_dummy_programs(self, p.stop, next_p.start)
dummy_progs += n
--- 195,199 ----
next_p = new_progs[i+1]
if p.stop < next_p.start:
! n = self.__get_dummy_programs(p.stop, next_p.start)
dummy_progs += n
***************
*** 364,368 ****
# fill gaps at the end
if p.stop < stop:
! n = get_dummy_programs(self, p.stop, stop)
dummy_progs += n
--- 201,205 ----
# fill gaps at the end
if p.stop < stop:
! n = self.__get_dummy_programs(p.stop, stop)
dummy_progs += n
***************
*** 384,397 ****
p = self.programs[0]
if p.start > start:
! self.import_programs(start, p.start)
# see if we're missing programs after end
p = self.programs[-1]
if stop == -1:
! self.import_programs(p.stop, stop)
else:
if p.stop < stop:
! self.import_programs(p.stop, stop)
else:
! self.import_programs(start, stop)
# return the needed programs
--- 221,234 ----
p = self.programs[0]
if p.start > start:
! self.__import_programs(start, p.start)
# see if we're missing programs after end
p = self.programs[-1]
if stop == -1:
! self.__import_programs(p.stop, stop)
else:
if p.stop < stop:
! self.__import_programs(p.stop, stop)
else:
! self.__import_programs(start, stop)
# return the needed programs
***************
*** 414,457 ****
- def next(self, prog):
- """
- return next program after 'prog'
- """
- # print 'next: programs len %d' % len(self.programs)
- # for p in self.programs:
- # print 'P: %s' % p
- # print 'next: at prog %s' % prog
-
- pos = self.programs.index(prog)
- # print 'next: at pos %d' % pos
-
- if pos < len(self.programs)-1:
- # print 'next: which is less than %d' % (len(self.programs)-1)
- # return self.programs[pos+1]
- next_prog = self.programs[pos+1]
- # print 'next: nex_prog %s' % next_prog
- return next_prog
- else:
- i_start = self.programs[len(self.programs)-1].stop
- self.import_programs(i_start, i_start+3*3600)
-
- if self.programs.index(prog) < len(self.programs)-1:
- return self.programs[pos+1]
-
- # print 'next: returning prog %s' % prog
- return prog
- def prev(self, prog):
- """
- return previous program before 'prog'
- """
- pos = self.programs.index(prog)
- if pos > 0:
- return self.programs[pos-1]
- else:
- i_stop = self.programs[0].start
- self.import_programs(i_stop-3*3600, i_stop)
- return self.programs[self.programs.index(prog)-1]
--- 251,269 ----
+ def get_relative(self, pos, prog):
+ new_pos = self.programs.index(prog) + pos
+ if new_pos < 0:
+ # requested program before start
+ self.__import_programs(prog.start-3*3600, prog.start)
+ return self.get_relative(pos, prog)
+ if new_pos >= len(self.programs):
+ # requested program after end
+ last = self.programs[-1]
+ self.__import_programs(last.stop, last.stop+3*3600)
+ return self.get_relative(pos, prog)
+ return self.programs[new_pos]
+
***************
*** 464,469 ****
"""
! def __init__(self):
! self.selected = 0
self.channel_list = []
self.channel_dict = {}
--- 276,280 ----
"""
! def __init__(self, TV_CHANNELS=[], TV_CHANNELS_EXCLUDE=[]):
self.channel_list = []
self.channel_dict = {}
***************
*** 477,481 ****
# Check TV_CHANNELS and add them to the list
! for c in config.TV_CHANNELS:
self.add_channel(Channel(c[0], c[1], c[2:]))
--- 288,292 ----
# Check TV_CHANNELS and add them to the list
! for c in TV_CHANNELS:
self.add_channel(Channel(c[0], c[1], c[2:]))
***************
*** 483,487 ****
# will be added if not already in the list
for c in self.epg.get_channels():
! if String(c['id']) in config.TV_CHANNELS_EXCLUDE:
# Skip channels that we explicitly do not want.
continue
--- 294,298 ----
# will be added if not already in the list
for c in self.epg.get_channels():
! if String(c['id']) in TV_CHANNELS_EXCLUDE:
# Skip channels that we explicitly do not want.
continue
***************
*** 493,522 ****
- def get_settings_by_id(self, chan_id):
- """
- """
- settings = []
- chan = self.channel_dict.get(chan_id)
- if chan:
- for u in c.uri:
- which = u.split(':')[0]
- settings.append(which)
-
- return settings
-
-
- def get_settings_by_name(self, chan_name):
- """
- """
- settings = []
- for c in self.channel_list:
- if c.name == chan_name:
- for u in c.uri:
- which = u.split(':')[0]
- settings.append(which)
-
- return settings
-
-
def add_channel(self, channel):
"""
--- 304,307 ----
***************
*** 530,580 ****
! def import_programs(self, start, stop=-1):
! """
! """
! e = self.epg.get_programs([], start, stop)
! for c in self.channel_list:
! id = c.chan_id
! c.import_programs(start, stop, filter(lambda x: x[1] == id, e))
!
!
! def down(self):
! """
! go one channel up
! """
! self.selected = (self.selected + 1) % len(self.channel_list)
!
!
! def up(self):
! """
! go one channel down
! """
! self.selected = (self.selected + len(self.channel_list) - 1) % \
! len(self.channel_list)
!
!
! def set(self, pos):
! """
! set channel
! """
! self.selected = pos
!
!
! def get(self, id=None):
! """
! return channel with id or whichever is selected
! """
!
! if id:
! chan = self.channel_dict.get(id)
! if chan: return chan
!
! return self.channel_list[self.selected]
def get_all(self):
- """
- return all channels
- """
return self.channel_list
--- 315,332 ----
! def __getitem__(self, key):
! return self.channel_list[key]
def get_all(self):
return self.channel_list
+
+ def get(self, pos, start=None):
+ if not start:
+ start = self.channel_list[0]
+ cpos = self.channel_list.index(start)
+ pos = (cpos + pos) % len(self.channel_list)
+ return self.channel_list[pos]
+
+
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog