Update of /cvsroot/freevo/freevo/src/record
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3734/record

Modified Files:
        server.py 
Added Files:
        favorite.py recording.py 
Log Message:
Current status of the recordserver:
o add/delete/modify/list recordings
o add/list favorites
o tv_grab will force an internal favorite update
o create recordings based on favorites
o basic conflict detection
o store everything in a fxd file
Recording itself (a.k.a. record/plugins) is not working yet


--- NEW FILE: recording.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# recording.py -
# -----------------------------------------------------------------------------
# $Id: recording.py,v 1.1 2004/11/06 17:56:21 dischi Exp $
#
#
# -----------------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002-2004 Krister Lagerstrom, Dirk Meyer, et al.
#
# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
#
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------

import time

import util.fxdparser as fxdparser

_time_format = '%Y%m%d.%H:%M'

def _int2time(i):
    return time.strftime(_time_format, time.localtime(i))

def _time2int(s):
    return int(time.mktime(time.strptime(s, _time_format)))


class Recording:
    def __init__(self, id = -1, name = 'unknown', channel = 'unknown',
                 priority = 0, start = 0, stop = 0, filename = '/dev/null',
                 info = {}, status = 'scheduled' ):
        self.id       = id
        self.name     = name
        self.channel  = channel
        self.priority = priority
        self.start    = start
        self.stop     = stop
        self.filename = filename
        self.info     = info
        self.status   = status

    def short_list(self):
        return self.id, self.channel, self.priority, self.start, \
               self.stop, self.status


    def long_list(self):
        return self.id, self.name, self.channel, self.priority, self.start, \
               self.stop, self.filename, self.status, self.info


    def parse_fxd(self, parser, node):
        self.id = int(parser.getattr(node, 'id'))
        for child in node.children:
            for var in ('name', 'channel', 'status'):
                if child.name == var:
                    setattr(self, var, parser.gettext(child))
            if child.name == 'priority':
                self.priority = int(parser.gettext(child))
            if child.name == 'timer':
                self.start = _time2int(parser.getattr(child, 'start'))
                self.stop  = _time2int(parser.getattr(child, 'stop'))
        parser.parse_info(node, self)


    def __str__(self):
        return String(self.short_list())


    def __fxd__(self, fxd):
        node = fxdparser.XMLnode('recording', [ ('id', self.id ) ] )
        for var in ('name', 'channel', 'priority', 'filename', 'status'):
            subnode = fxdparser.XMLnode(var, [], getattr(self, var) )
            fxd.add(subnode, node)
        timer = fxdparser.XMLnode('timer', [ ('start', _int2time(self.start)),
                                             ('stop', _int2time(self.stop)) ])
        fxd.add(timer, node)
        info = fxdparser.XMLnode('info')
        for i in self.info:
            subnode = fxdparser.XMLnode(i, [], self.info[i] )
            fxd.add(subnode, info)
        fxd.add(info, node)
        return node

    def __cmp__(self, obj):
        if not isinstance(obj, Recording):
            return True
        return self.name != obj.name or self.channel != obj.channel or \
               self.start != obj.start or self.stop != obj.stop


--- NEW FILE: favorite.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# favorite.py -
# -----------------------------------------------------------------------------
# $Id: favorite.py,v 1.1 2004/11/06 17:56:21 dischi Exp $
#
#
# -----------------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002-2004 Krister Lagerstrom, Dirk Meyer, et al.
#
# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
#
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------

import re
import time

import config
import util.fxdparser as fxdparser

_time_re = re.compile('([0-9]*):([0-9]*)-([0-9]*):([0-9]*)')

class Favorite:
    def __init__(self, id = -1, name = 'unknown', channels = [],
                 priority = 0, days = [], times = []):
        self.id = id
        self.name = name
        self.channels = channels
        self.priority = priority
        self.days = days
        self.times = []
        for t in times:
            m = _time_re.match(t).groups()
            start = int(m[0])*100 + int(m[1])
            stop  = int(m[2])*100 + int(m[3])
            self.times.append((start, stop))

    def short_list(self):
        return self.id, self.name, self.priority

    def long_list(self):
        return self.id, self.name, self.channels, self.priority, self.days, \
               self.times

    def parse_fxd(self, parser, node):
        self.id = int(parser.getattr(node, 'id'))
        for child in node.children:
            for var in ('name', 'channel'):
                if child.name == var:
                    setattr(self, var, parser.gettext(child))
            if child.name == 'channels':
                self.channels = []
                for v in parser.gettext(child).split(' '):
                    self.channels.append(v)
            if child.name == 'days':
                self.days = []
                for v in parser.gettext(child).split(' '):
                    self.days.append(int(v))
            if child.name == 'times':
                self.times = []
                for v in parser.gettext(child).split(' '):
                    m = _time_re.match(v).groups()
                    start = int(m[0])*100 + int(m[1])
                    stop  = int(m[2])*100 + int(m[3])
                    self.times.append((start, stop))
            if child.name == 'priority':
                setattr(self, 'priority', int(parser.gettext(child)))

    def match(self, name, channel, start):
        if name != self.name:
            return False
        # FIXME: correct channel in db
        for c in config.TV_CHANNELS:
            if c[0] == channel:
                channel = c[1]
                break
        if not channel in self.channels:
            return False
        timestruct = time.localtime(start)
        if not int(time.strftime('%w', timestruct)) in self.days:
            return False
        stime = int(timestruct[3]) * 100 + int(timestruct[4])
        for t1, t2 in self.times:
            if stime >= t1 and stime <= t2:
                return True
        return False


    def __str__(self):
        return String(self.short_list())


    def __fxd__(self, fxd):
        node = fxdparser.XMLnode('favorite', [ ('id', self.id ) ] )
        for var in ('name', 'priority'):
            subnode = fxdparser.XMLnode(var, [], getattr(self, var) )
            fxd.add(subnode, node)
        for var in ('channels', 'days'):
            s = ''
            for v in getattr(self, var):
                s += '%s ' % v
            subnode = fxdparser.XMLnode(var, [], s[:-1])
            fxd.add(subnode, node)
        s = ''
        for v in self.times:
            s += '%02d:%02d-%02d:%02d ' % (v[0] / 100, v[0] % 100,
                                           v[1] / 100, v[1] % 100)
            subnode = fxdparser.XMLnode('times', [], s[:-1])
            fxd.add(subnode, node)
        return node

    def __cmp__(self, obj):
        if not isinstance(obj, Favorite):
            return True
        return self.name != obj.name or self.channels != obj.channels or \
               self.days != obj.days or self.times != obj.times


Index: server.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/record/server.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** server.py   4 Nov 2004 19:55:49 -0000       1.11
--- server.py   6 Nov 2004 17:56:21 -0000       1.12
***************
*** 1,27 ****
- #!/usr/bin/env python
  # -*- coding: iso-8859-1 -*-
! # -----------------------------------------------------------------------
! # record_server.py - A network aware TV recording server.
! # -----------------------------------------------------------------------
  # $Id$
  #
- # -----------------------------------------------------------------------
- # $Log$
- # Revision 1.11  2004/11/04 19:55:49  dischi
[...1035 lines suppressed...]
  
!     #
!     # home.theatre.favorite rpc commands
!     #
  
!     def __rpc_favorite_update__(self, addr=None, val=[]):
!         self.check_favorites()
!         return RPCReturn()
  
  
+     def __rpc_favorite_add__(self, addr, val):
+         name, channel, priority, day, time = \
+               self.parse_parameter(val, ( unicode, list, int, list, list ))
+         print 'favorite.add: %s' % String(name)
+         f = Favorite(self.fav_id, name, channel, priority, day, time)
+         if f in self.favorites:
+             return RPCError('Already scheduled')
+         self.favorites.append(f)
+         self.fav_id += 1
+         return self.__rpc_favorite_update__()



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to