Author: rshortt
Date: Mon Mar 13 19:47:47 2006
New Revision: 8085
Modified:
trunk/tvserver/bin/freevo-epg
trunk/tvserver/bin/freevo-tvserver
trunk/tvserver/src/config.py
trunk/tvserver/src/epg.py
trunk/tvserver/src/recorder.py
trunk/tvserver/src/server.py
Log:
kaa.epg2 changes
Modified: trunk/tvserver/bin/freevo-epg
==============================================================================
--- trunk/tvserver/bin/freevo-epg (original)
+++ trunk/tvserver/bin/freevo-epg Mon Mar 13 19:47:47 2006
@@ -99,33 +99,33 @@
# once the update is finished.
guide.signals["updated"].connect(sys.exit)
- if epg.config.use_xmltv == 1 and \
- os.path.isdir(os.path.dirname(epg.config.xmltv_file.split()[0])):
+ if epg.config.xmltv.activate == 1 and \
+
os.path.isdir(os.path.dirname(epg.config.xmltv.data_file.split()[0])):
- if epg.config.xmltv_grabber and \
- os.path.isfile(epg.config.xmltv_grabber.split()[0]):
+ if epg.config.xmltv.grabber and \
+ os.path.isfile(epg.config.xmltv.grabber.split()[0]):
# NOTE: should the grabbing code be put into a seperate module
# so other programs can cal it?
- log.info('grabbing listings using %s',
epg.config.xmltv_grabber)
+ log.info('grabbing listings using %s',
epg.config.xmltv.grabber)
xmltvtmp = '/tmp/TV.xml.tmp'
- ec = os.system('%s --output %s --days %s' %
(epg.config.xmltv_grabber,
+ ec = os.system('%s --output %s --days %s' %
(epg.config.xmltv.grabber,
xmltvtmp,
-
epg.config.xmltv_days))
+
epg.config.xmltv.days))
if os.path.exists(xmltvtmp) and ec == 0:
- if os.path.isfile(epg.config.xmltv_sort):
+ if os.path.isfile(epg.config.xmltv.sort):
log.info('sorting listings')
- os.system('%s --output %s %s' % (epg.config.xmltv_sort,
+ os.system('%s --output %s %s' % (epg.config.xmltv.sort,
xmltvtmp+'.1',
xmltvtmp))
shutil.move(xmltvtmp+'.1', xmltvtmp)
else:
- log.info('not configured to use xmltv_sort, skipping')
+ log.info('not configured to use tv_sort, skipping')
- shutil.move(xmltvtmp, epg.config.xmltv_file)
+ shutil.move(xmltvtmp, epg.config.xmltv.data_file)
else:
log.error('xmltv grabbing failed and returned exit code
%d.', ec >> 8)
@@ -134,32 +134,45 @@
'updating your xmltv: http://www.xmltv.org/')
else:
- log.info('not configured to run xmltv_grabber')
+ log.info('not configured to run XMLTV grabber')
- if not os.path.isfile(epg.config.xmltv_file):
- log.error('problem with xmltv_file, not updating EPG')
+ if not os.path.isfile(epg.config.xmltv.data_file):
+ log.error('problem with xmltv.data_file, not updating EPG')
else:
- log.debug('xmltv_file: %s', epg.config.xmltv_file)
+ log.debug('xmltv_file: %s', epg.config.xmltv.data_file)
log.info('loading data into EPG...')
- guide.update("xmltv", str(epg.config.xmltv_file))
+ guide.update("xmltv", str(epg.config.xmltv.data_file))
else:
log.info('not configured to use xmltv')
- if epg.config.use_zap2it == 1:
- guide.update("zap2it", username=str(epg.config.zap2it_username),
- passwd=str(epg.config.zap2it_password))
+ if epg.config.zap2it.activate == 1:
+ guide.update("zap2it", username=str(epg.config.zap2it.username),
+ passwd=str(epg.config.zap2it.password))
else:
log.info('not configured to use Zap2it')
- log.info('connecting to tvserver')
- mbus = freevo.ipc.Instance()
- mbus.signals['new-entity'].connect(new_entity)
- kaa.notifier.OneShotTimer(updated, False).start(2)
+ if epg.config.vdr.activate == 1:
+ log.info('configured to use VDR')
+ guide.update("vdr", vdr_dir=str(epg.config.vdr.dir),
+ channels_file=str(epg.config.vdr.channels_file),
+ epg_file=str(epg.config.vdr.epg_file),
+ host=str(epg.config.vdr.host),
port=int(epg.config.vdr.port),
+ access_by=str(epg.config.vdr.access_by),
+ limit_channels=str(epg.config.vdr.limit_channels))
+
+ else:
+ log.info('not configured to use VDR')
+
+
+ #log.info('connecting to tvserver')
+ #mbus = freevo.ipc.Instance()
+ #mbus.signals['new-entity'].connect(new_entity)
+ #kaa.notifier.OneShotTimer(updated, False).start(2)
kaa.main()
@@ -185,9 +198,9 @@
for program in programs:
start_time = time.strftime("%a %H:%M",
time.localtime(program.start))
- print " %s (%s): %s" % (program.channel.short_name, start_time,
program.title.encode('latin-1'))
- if program.desc:
- print "\t* " + "\n\t
".join(textwrap.wrap(program.desc.encode('latin-1'), 60))
+ print " %s (%s): %s" % (program.channel.name.encode('latin-1'),
start_time, program.title.encode('latin-1'))
+ if program.description:
+ print "\t* " + "\n\t
".join(textwrap.wrap(program.description.encode('latin-1'), 60))
print "- Queried %d programs; %s results; %.04f seconds" % \
(guide.get_num_programs(), len(programs), t1-t0)
@@ -211,10 +224,10 @@
if 1:
#print dir(guide)
cs = guide.get_channels()
- cs.sort(lambda a, b: cmp(a.short_name, b.short_name))
+ cs.sort(lambda a, b: cmp(a.name, b.name))
cs.sort(lambda a, b: cmp(a.tuner_id, b.tuner_id))
for c in cs:
- log.info('tuner_id: "%s" short_name: "%s" long_name: "%s"',
c.tuner_id, c.short_name, c.long_name)
+ log.info('tuner_id: "%s" name: "%s" long_name: "%s"',
c.tuner_id, c.name, c.long_name)
if 0:
programs = guide.search(keywords = keywords)
Modified: trunk/tvserver/bin/freevo-tvserver
==============================================================================
--- trunk/tvserver/bin/freevo-tvserver (original)
+++ trunk/tvserver/bin/freevo-tvserver Mon Mar 13 19:47:47 2006
@@ -46,7 +46,6 @@
# kaa imports
import kaa
import kaa.notifier
-import kaa.epg
# FIXME: create logger objects in conf
import freevo.conf
@@ -70,14 +69,6 @@
# except Exception, e:
# log.warning('unable to set uid: %s' % e)
-# load the epg
-epg_filename = config.epg.database
-if epg_filename.find('$(DATADIR)') >= 0:
- epg_filename = epg_filename.replace('$(DATADIR)', freevo.conf.DATADIR)
-
-kaa.epg.connect('sqlite2', epg_filename)
-kaa.epg.load()
-
if len(sys.argv) > 1:
if sys.argv[1] == '-i':
# import interactive mode
Modified: trunk/tvserver/src/config.py
==============================================================================
--- trunk/tvserver/src/config.py (original)
+++ trunk/tvserver/src/config.py Mon Mar 13 19:47:47 2006
@@ -28,8 +28,6 @@
# epg group
Group(name='epg', desc=_('epg settings'), schema=[
- Var(name='database', default='$(DATADIR)/epg.db',
- desc=_('Filename for the sqlite database file')),
Dict(name='mapping', type=unicode, schema=Var(type=unicode),
desc=_('EPG channel mapping'))])
])
Modified: trunk/tvserver/src/epg.py
==============================================================================
--- trunk/tvserver/src/epg.py (original)
+++ trunk/tvserver/src/epg.py Mon Mar 13 19:47:47 2006
@@ -35,9 +35,11 @@
import logging
# kaa imports
-import kaa.epg
from kaa.notifier import OneShotTimer, Timer, Signal, execute_in_timer
+# freevo imports
+from freevo.ipc.epg import connect as guide
+
# record imports
from record_types import *
from recording import Recording
@@ -56,7 +58,7 @@
"""
Return list of channels.
"""
- return kaa.epg.channels
+ return guide().get_channels()
def check_all(self, favorites, recordings, callback, *args, **kwargs):
@@ -101,13 +103,22 @@
# same time, maybe it has moved +- 20 minutes. If the program
# moved a larger time interval, it won't be found again.
interval = (rec.start - 20 * 60, rec.start + 20 * 60)
- results = kaa.epg.search(rec.name, rec.channel, exact_match=True,
- interval = interval)
+
+ # results = kaa.epg.search(rec.name, rec.channel, exact_match=True,
+ # interval = interval)
+ # NOTE: How can we do the same as exact_match=True above? Do we need
to?
+ # So far the code below works fine.
+
+ log.debug('search: keywords="%s" channel="%s" time="%s"', rec.name,
rec.channel, interval)
+ results = guide().search(keywords = rec.name,
+ channel=guide().get_channel(rec.channel),
+ time = interval)
for epginfo in results:
# check all results
if epginfo.start == rec.start and epginfo.stop == rec.stop:
# found the recording
+ log.debug('found recording: %s', rec.name)
break
else:
# try to find it
@@ -124,11 +135,9 @@
log.info('unable to find recording in epg:\n%s' % rec)
return True
- # check if attributes changed (Note: String() should not be
- # needed here, everything has to be unicode, at least when
- # kaa.epg2 is done)
+ # check if attributes changed
for attr in ('description', 'episode', 'subtitle'):
- if String(getattr(rec, attr)) != String(getattr(epginfo, attr)):
+ if getattr(rec, attr) != getattr(epginfo, attr):
log.info('%s changed for %s', attr, rec.name)
setattr(rec, attr, getattr(epginfo, attr))
return True
@@ -161,8 +170,9 @@
fav = favorites.pop(0)
# Now search the db
- for p in kaa.epg.search(fav.name, exact_match=not fav.substring):
- if not fav.match(p.title, p.channel.id, p.start):
+ # NOTE: do we need something like "exact_match=not fav.substring" here?
+ for p in guide().search(keywords=fav.name):
+ if not fav.match(p.title, p.channel.name, p.start):
continue
rec = Recording(p.title, p.channel.id, fav.priority,
Modified: trunk/tvserver/src/recorder.py
==============================================================================
--- trunk/tvserver/src/recorder.py (original)
+++ trunk/tvserver/src/recorder.py Mon Mar 13 19:47:47 2006
@@ -4,6 +4,9 @@
# -----------------------------------------------------------------------------
# $Id$
#
+# TODO: Handle unknown channels by letting user record them even with no EPG
+# data.
+#
# -----------------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
@@ -41,10 +44,10 @@
# kaa imports
from kaa.notifier import OneShotTimer, Signal
-import kaa.epg
# freevo core imports
import freevo.ipc
+from freevo.ipc.epg import connect as guide
# record imports
from config import config
@@ -220,8 +223,8 @@
self.rpc = self.entity.rpc
self.rpc('home-theatre.device.describe', self.describe_cb).call(device)
self.rating = 0
- self.channel2epg = {}
- self.epg2channel = {}
+ self.known_channels = {}
+ self.unknown_channels = {}
def __str__(self):
@@ -243,6 +246,19 @@
def normalize_name(self, name):
return String(name.replace('.', '').replace(' ', '')).upper().strip()
+ def add_channel(self, chan_obj, chan_id):
+ if chan_obj.name in self.known_channels:
+ # duplicate, skip it
+ return
+
+ if chan_id in self.unknown_channels:
+ # found a previously unknown channel
+ del(self.unknown_channels[chan_id])
+
+ chan_obj.tuner_id = chan_id
+ self.known_channels[chan_obj.name] = chan_obj
+ self.possible_bouquets[-1].append(chan_obj.name)
+
def describe_cb(self, result):
"""
RPC return for device.describe()
@@ -258,31 +274,58 @@
for bouquet in result[2]:
self.possible_bouquets.append([])
for channel in bouquet:
+
+ # step 1, see config for override
if channel in config.epg.mapping:
- epgid = config.epg.mapping[channel] or channel
- if epgid in self.epg2channel:
- # duplicate id, skip it
+ chan = guide().get_channel(config.epg.mapping[channel])
+
+ if chan:
+ self.add_channel(chan, channel)
continue
- self.possible_bouquets[-1].append(epgid)
- self.epg2channel[epgid] = channel
- self.channel2epg[channel] = epgid
- else:
- error = True
- # ok, new channel, try to guess mapping
- for c in kaa.epg.channels:
- if Unicode(channel) == Unicode(c.access_id):
- epgid = c.id
- break
else:
- normchannel = self.normalize_name(channel)
- for c in kaa.epg.channels:
- if Unicode(normchannel) == \
- Unicode(self.normalize_name(c.name)):
- epgid = c.id
- break
- else:
- epgid = ''
- config.epg.mapping[channel] = epgid
+ # channel is there but unconfigured
+ # a match may be found later
+ self.unknown_channels[channel] =
guide().new_channel(channel)
+
+ # step 2, try tuner_id
+ chan = guide().get_channel_by_tuner_id(channel)
+
+ if not chan:
+ # step 3, try name
+ chan = guide().get_channel(channel)
+
+ if chan:
+ self.add_channel(chan, channel)
+ continue
+
+ # ok, new channel, try to guess mapping
+ normchannel = self.normalize_name(channel)
+ chan = guide().get_channel(self.normalize_name(channel))
+ if chan:
+ self.add_channel(chan, channel)
+ continue
+
+ else:
+ # if we got this far that means there is nothing to connect
+ # the channel reported by tvdev to one in the EPG
+
+ # server may have started with previously unknown channels
+ # TODO: handle these unknown_channels, which are just
+ # channels with no EPG data
+
+ if channel not in self.unknown_channels:
+ error = True
+ chan = ''
+ config.epg.mapping[channel] = chan
+
+ # TODO: remove this debugging when everything works good
+ log.debug('bouquets: %s', self.possible_bouquets)
+ n = 1
+ for b in self.possible_bouquets:
+ log.debug('bouquet %d', n)
+ for c in b:
+ log.debug('chan: %s', c)
+ n = n+1
if error:
OneShotTimer(self.sys_exit).start(1)
@@ -378,7 +421,7 @@
if remote.id == UNKNOWN_ID:
# add the recording
rec = remote.recording
- channel = self.epg2channel[rec.channel]
+ channel = self.known_channels[rec.channel].tuner_id
filename = self.get_url(rec)
rec.url = filename
log.info('%s: schedule %s' % (String(self.name),
String(rec.name)))
@@ -443,7 +486,7 @@
log.info('start live tv')
rpc = self.rpc('home-theatre.vdr.record', self.start_livetv_cb)
- rpc.call(self.device, self.epg2channel[channel], 0, 2147483647, url,
())
+ rpc.call(self.device, self.known_channels[channel].tuner_id, 0,
2147483647, url, ())
id = Recorder.next_livetv_id
Recorder.next_livetv_id = id + 1
self.livetv[id] = channel, None
Modified: trunk/tvserver/src/server.py
==============================================================================
--- trunk/tvserver/src/server.py (original)
+++ trunk/tvserver/src/server.py Mon Mar 13 19:47:47 2006
@@ -239,7 +239,7 @@
# Oops, we are in 'recording' status and this was saved.
# That means we are stopped while recording, set status to
# missed
- r.status = 'missed'
+ r.status = MISSED
if r.status == SCHEDULED:
# everything is a conflict for now
r.status = CONFLICT
@@ -434,7 +434,7 @@
parameter: channel
"""
for c in self.epg.channels():
- if c.id == channel:
+ if c.name == channel:
channel = c
break
else:
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog