[vdrpylib-cvslog] vdrpylib/vdr mark.py,1.3,1.4 recording.py,1.3,1.4 timer.py,1.3,1.4 vdr.py,1.9,1.10
Status: Alpha
Brought to you by:
rshortt
From: Rob S. <rs...@us...> - 2005-01-07 12:33:13
|
Update of /cvsroot/vdrpylib/vdrpylib/vdr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21271 Modified Files: mark.py recording.py timer.py vdr.py Log Message: Change indentation to 4 spaces, no tabs. Index: recording.py =================================================================== RCS file: /cvsroot/vdrpylib/vdrpylib/vdr/recording.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** recording.py 24 Nov 2004 17:06:58 -0000 1.3 --- recording.py 7 Jan 2005 12:33:01 -0000 1.4 *************** *** 30,300 **** class Recording: ! """This class represents a VDR recording. ! ! Data about a recording can either be obtained via SVDRP or by ! disk access (which gives more accurate information). ! ! Note that when setting an SVDRP object as a recording's source, ! this SVDRP object is implicitely accessed in some of the getXXX() ! functions. Further accesses go to cache but the SVDRP connection ! may not be closed until after the first access to those getXXX() ! functions. ! """ ! def __init__(self, source = None, index = None): ! """Creates a new Recording object. ! ! The optional source argument is expected to be an SVDRP object or a ! string containing a recording description in the format as ! returned by the SVDRP LSTR command or a string containing ! the path to a recording. ! ! The index is expected to be an integer containing the index ! of this recording into the total list of recordings of a VDR ! instance (base 1). If the source argument is a recording ! description the index is derived from that description rather ! than from the index argument which may thus be ommitted. ! ! With SVDRP connections it is more efficient to run the LSTR ! command once and create a Recording object per line than ! creating multiple Recording object with an SVDRP object and ! varying indexes as this requires as many executions of the ! LSTR command. ! """ ! self.source = source ! self.index = index ! self.name = None ! self.summary = None ! self.start = None ! self.prio = None ! self.lifetime = None ! self.marks = None ! self.resume = None ! ! if source is not None: ! self.init(source, index) ! ! ! def init(self, source, index = None): ! """Initialize the data associated with this recording object ! from the given source. ! ! The source argument is expected to be an SVDRP object or a ! string containing a recording description in the format as ! returned by the SVDRP LSTR command or a string containing ! the path to a recording. ! ! The index is expected to be an integer containing the index ! of this recording into the total list of recordings of a VDR ! instance (base 1). If the source argument is a recording ! description the index is derived from that description rather ! than from the index argument which may thus be ommitted. ! ! With SVDRP connections it is more efficient to run the LSTR ! command once and create a Recording object per line than ! creating multiple Recording object with an SVDRP object and ! varying indexes as this requires as many executions of the ! LSTR command. ! """ ! if isinstance(source, svdrp.SVDRP) and index is not None: ! pat = re.compile('250[ -]' + str(index) + ' ') ! result = source.write_cmd('LSTR\n') ! if result[0:3] != '250': ! print 'lstr returned: ' + result ! for line in result.split('\n'): ! line = line.strip() ! if pat.match(line): ! self.init(line) ! ! elif isinstance(source, StringType) and len(source) > 5 and source[:3] == '250': ! tokens = source.strip()[4:].split(None, 3) ! if len(tokens) == 4: ! self.index = int(tokens[0]) ! if len(tokens[1].split('.')) == 2: ! tokens[1] = tokens[1] + '.' + time.strftime('%Y') ! self.start = int(time.mktime(time.strptime(tokens[1] + ' ' + tokens[2].replace('*', ''), '%d.%m.%Y %H:%M'))) ! self.name = tokens[3] ! if tokens[2].find('*'): ! self.resume = 0 ! else: ! self.resume = -1 ! ! elif isinstance(source, StringType) and os.path.isdir(source): ! pat = re.compile('(/video\d*/)?(.*)/(\d{4}-\d\d-\d\d\.\d\d\.\d\d)\.(\d\d)\.(\d\d)\.rec/?') ! result = pat.match(source) ! if result is None: ! raise TypeError, 'path of recording has unknown format' ! self.index = index ! self.name = result.group(2) ! self.start = int(time.mktime(time.strptime(result.group(3), '%Y-%m-%d.%H.%M'))) ! self.prio = int(result.group(4)) ! self.lifetime = int(result.group(5)) ! ! else: ! raise TypeError, 'argument source has invalid type' ! ! ! def getsource(self): ! """Returns the data source of this recording object. ! ! The return value is either a SVDRP object or a string ! containing the path to this recording. ! """ ! return self.source ! ! ! def setsource(self, source): ! """Sets a data source for this recording object. ! ! The source argument is expected to be either a SVDRP object ! or a string containing the path to a recording. ! """ ! if isinstance(source, svdrp.SVDRP) or \ ! (isinstance(source, StringType) and \ ! os.path.isdir(source)): ! self.source = source ! else: ! raise TypeError, 'argument source has invalid type' ! ! ! def getindex(self): ! """Returns the index of this recording. ! ! The return value is an integer representing the index of this ! recording into the complete list of recordings of a VDR ! instance. ! """ ! return self.index ! ! ! def getname(self): ! """Returns the name of this recording. ! ! The return value is a string containing the name of this ! recording. ! """ ! return self.name ! ! ! def getsummary(self): ! """Returns the summary of this recording. ! ! Depending on the source given at construction time, the ! summary for this recording is retrieved via SVDRP or from ! the summary.vdr file. ! ! The return value is a string containing the summary of this ! recording. ! """ ! if self.summary is None: ! if isinstance(self.source, svdrp.SVDRP): ! self.summary = self.source.lstr(self.index) ! elif isinstance(self.source, StringType) and os.path.isdir(self.source): ! fh = open(os.path.join(self.source, 'summary.vdr'), 'r') ! self.summary = fh.read() ! fh.close() ! return self.summary ! ! ! def getstart(self): ! """Returns the start time of this recording. ! ! The return value is an integer containing the time when the ! recording started as seconds since the epoch. ! """ ! return self.start ! ! ! def getprio(self): ! """Return the priority of this recording. ! ! The return value is an integer containing the priority of ! this recording (which is derived from the corresponding ! timer). ! """ ! return self.prio ! ! ! def getlifetime(self): ! """Returns the lifetime of this recording. ! ! The return value is an integer containing the number of days ! since start this recording is guaranteed to not be deleted by ! VDR. ! """ ! return self.lifetime ! ! ! def getmarks(self): ! """Returns the editing marks of this recording. ! ! The return value is a list of Mark objects representing the ! editing marks of this recording. ! """ ! if self.marks is None: ! if isinstance(self.source, StringType) and \ ! os.path.isdir(self.source) and \ ! os.path.isfile(os.path.join(self.source, 'marks.vdr')): ! ! self.marks = [] ! fh = open(os.path.join(self.source, 'marks.vdr'), 'r') ! line = fh.readline() ! while line: ! mk = mark.Mark(line.strip()) ! self.marks.append(mk) ! line = fh.readline() ! fh.close() ! ! return self.marks ! ! ! def getresume(self): ! """Returns the resume offset for this recording. ! ! The return value is an integer containing the resume offset ! of this recording. ! ! If the recording does not have a resume offset, the return ! value is -1. If the recording has an unknown resume offset ! (may occur when retrieving recording data via SVDRP), the ! return value is 0. ! """ ! if self.resume is None: ! dfn = None ! if isinstance(self.source, StringType) and \ ! os.path.isdir(self.source): ! if os.path.isfile(os.path.join(self.source, 'resume.vdr')): ! fh = open(os.path.join(self.source, 'resume.vdr'), 'r') ! nr = fh.read() ! fh.close() ! self.resume = struct.unpack('l', nr)[0] ! else: ! self.resume = -1 ! elif isinstance(self.source, StringType) and len(self.source) > 5 and self.source[:3] == '250': ! dfn = self.source ! elif isinstance(self.source, svdrp.SVDRP): ! dfn = self.source.lstr(self.index) ! ! if dfn is not None: ! tokens = dfn.strip()[4:].split(None, 3) ! if len(tokens) == 4: ! if tokens[2].find('*'): ! self.resume = 0 ! else: ! self.resume = -1 ! return self.resume ! ! ! def isnew(self): ! """Returns whether this recording is unwatched, i.e. whether ! it does not have a resume offset. ! """ ! return self.getresume() == -1 ! def __cmp__(self, other): ! """Compares two Recording objects by their start times. ! """ ! return cmp(self.start, other.start) --- 30,300 ---- class Recording: ! """This class represents a VDR recording. ! ! Data about a recording can either be obtained via SVDRP or by ! disk access (which gives more accurate information). ! ! Note that when setting an SVDRP object as a recording's source, ! this SVDRP object is implicitely accessed in some of the getXXX() ! functions. Further accesses go to cache but the SVDRP connection ! may not be closed until after the first access to those getXXX() ! functions. ! """ ! def __init__(self, source = None, index = None): ! """Creates a new Recording object. ! ! The optional source argument is expected to be an SVDRP object or a ! string containing a recording description in the format as ! returned by the SVDRP LSTR command or a string containing ! the path to a recording. ! ! The index is expected to be an integer containing the index ! of this recording into the total list of recordings of a VDR ! instance (base 1). If the source argument is a recording ! description the index is derived from that description rather ! than from the index argument which may thus be ommitted. ! ! With SVDRP connections it is more efficient to run the LSTR ! command once and create a Recording object per line than ! creating multiple Recording object with an SVDRP object and ! varying indexes as this requires as many executions of the ! LSTR command. ! """ ! self.source = source ! self.index = index ! self.name = None ! self.summary = None ! self.start = None ! self.prio = None ! self.lifetime = None ! self.marks = None ! self.resume = None ! ! if source is not None: ! self.init(source, index) ! ! ! def init(self, source, index = None): ! """Initialize the data associated with this recording object ! from the given source. ! ! The source argument is expected to be an SVDRP object or a ! string containing a recording description in the format as ! returned by the SVDRP LSTR command or a string containing ! the path to a recording. ! ! The index is expected to be an integer containing the index ! of this recording into the total list of recordings of a VDR ! instance (base 1). If the source argument is a recording ! description the index is derived from that description rather ! than from the index argument which may thus be ommitted. ! ! With SVDRP connections it is more efficient to run the LSTR ! command once and create a Recording object per line than ! creating multiple Recording object with an SVDRP object and ! varying indexes as this requires as many executions of the ! LSTR command. ! """ ! if isinstance(source, svdrp.SVDRP) and index is not None: ! pat = re.compile('250[ -]' + str(index) + ' ') ! result = source.write_cmd('LSTR\n') ! if result[0:3] != '250': ! print 'lstr returned: ' + result ! for line in result.split('\n'): ! line = line.strip() ! if pat.match(line): ! self.init(line) ! ! elif isinstance(source, StringType) and len(source) > 5 and source[:3] == '250': ! tokens = source.strip()[4:].split(None, 3) ! if len(tokens) == 4: ! self.index = int(tokens[0]) ! if len(tokens[1].split('.')) == 2: ! tokens[1] = tokens[1] + '.' + time.strftime('%Y') ! self.start = int(time.mktime(time.strptime(tokens[1] + ' ' + tokens[2].replace('*', ''), '%d.%m.%Y %H:%M'))) ! self.name = tokens[3] ! if tokens[2].find('*'): ! self.resume = 0 ! else: ! self.resume = -1 ! ! elif isinstance(source, StringType) and os.path.isdir(source): ! pat = re.compile('(/video\d*/)?(.*)/(\d{4}-\d\d-\d\d\.\d\d\.\d\d)\.(\d\d)\.(\d\d)\.rec/?') ! result = pat.match(source) ! if result is None: ! raise TypeError, 'path of recording has unknown format' ! self.index = index ! self.name = result.group(2) ! self.start = int(time.mktime(time.strptime(result.group(3), '%Y-%m-%d.%H.%M'))) ! self.prio = int(result.group(4)) ! self.lifetime = int(result.group(5)) ! ! else: ! raise TypeError, 'argument source has invalid type' ! ! ! def getsource(self): ! """Returns the data source of this recording object. ! ! The return value is either a SVDRP object or a string ! containing the path to this recording. ! """ ! return self.source ! ! ! def setsource(self, source): ! """Sets a data source for this recording object. ! ! The source argument is expected to be either a SVDRP object ! or a string containing the path to a recording. ! """ ! if isinstance(source, svdrp.SVDRP) or \ ! (isinstance(source, StringType) and \ ! os.path.isdir(source)): ! self.source = source ! else: ! raise TypeError, 'argument source has invalid type' ! ! ! def getindex(self): ! """Returns the index of this recording. ! ! The return value is an integer representing the index of this ! recording into the complete list of recordings of a VDR ! instance. ! """ ! return self.index ! ! ! def getname(self): ! """Returns the name of this recording. ! ! The return value is a string containing the name of this ! recording. ! """ ! return self.name ! ! ! def getsummary(self): ! """Returns the summary of this recording. ! ! Depending on the source given at construction time, the ! summary for this recording is retrieved via SVDRP or from ! the summary.vdr file. ! ! The return value is a string containing the summary of this ! recording. ! """ ! if self.summary is None: ! if isinstance(self.source, svdrp.SVDRP): ! self.summary = self.source.lstr(self.index) ! elif isinstance(self.source, StringType) and os.path.isdir(self.source): ! fh = open(os.path.join(self.source, 'summary.vdr'), 'r') ! self.summary = fh.read() ! fh.close() ! return self.summary ! ! ! def getstart(self): ! """Returns the start time of this recording. ! ! The return value is an integer containing the time when the ! recording started as seconds since the epoch. ! """ ! return self.start ! ! ! def getprio(self): ! """Return the priority of this recording. ! ! The return value is an integer containing the priority of ! this recording (which is derived from the corresponding ! timer). ! """ ! return self.prio ! ! ! def getlifetime(self): ! """Returns the lifetime of this recording. ! ! The return value is an integer containing the number of days ! since start this recording is guaranteed to not be deleted by ! VDR. ! """ ! return self.lifetime ! ! ! def getmarks(self): ! """Returns the editing marks of this recording. ! ! The return value is a list of Mark objects representing the ! editing marks of this recording. ! """ ! if self.marks is None: ! if isinstance(self.source, StringType) and \ ! os.path.isdir(self.source) and \ ! os.path.isfile(os.path.join(self.source, 'marks.vdr')): ! ! self.marks = [] ! fh = open(os.path.join(self.source, 'marks.vdr'), 'r') ! line = fh.readline() ! while line: ! mk = mark.Mark(line.strip()) ! self.marks.append(mk) ! line = fh.readline() ! fh.close() ! ! return self.marks ! ! ! def getresume(self): ! """Returns the resume offset for this recording. ! ! The return value is an integer containing the resume offset ! of this recording. ! ! If the recording does not have a resume offset, the return ! value is -1. If the recording has an unknown resume offset ! (may occur when retrieving recording data via SVDRP), the ! return value is 0. ! """ ! if self.resume is None: ! dfn = None ! if isinstance(self.source, StringType) and \ ! os.path.isdir(self.source): ! if os.path.isfile(os.path.join(self.source, 'resume.vdr')): ! fh = open(os.path.join(self.source, 'resume.vdr'), 'r') ! nr = fh.read() ! fh.close() ! self.resume = struct.unpack('l', nr)[0] ! else: ! self.resume = -1 ! elif isinstance(self.source, StringType) and len(self.source) > 5 and self.source[:3] == '250': ! dfn = self.source ! elif isinstance(self.source, svdrp.SVDRP): ! dfn = self.source.lstr(self.index) ! ! if dfn is not None: ! tokens = dfn.strip()[4:].split(None, 3) ! if len(tokens) == 4: ! if tokens[2].find('*'): ! self.resume = 0 ! else: ! self.resume = -1 ! return self.resume ! ! ! def isnew(self): ! """Returns whether this recording is unwatched, i.e. whether ! it does not have a resume offset. ! """ ! return self.getresume() == -1 ! def __cmp__(self, other): ! """Compares two Recording objects by their start times. ! """ ! return cmp(self.start, other.start) Index: vdr.py =================================================================== RCS file: /cvsroot/vdrpylib/vdrpylib/vdr/vdr.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** vdr.py 2 Dec 2004 02:13:47 -0000 1.9 --- vdr.py 7 Jan 2005 12:33:01 -0000 1.10 *************** *** 31,544 **** class VDR: ! """This class represents a VDR instance and all its associated ! data. ! ! It is a container for channel objects and runtime-related data. ! It offers functions to retrieve channel and EPG data from the ! VDR files or via SVDRP. ! ! The channels variable is a dictionary containing integer objects [...999 lines suppressed...] ! self.timers = [] ! ! try: ! index = 1 ! fh = open(self.timerfile, 'r') ! line = fh.readline() ! while line: ! t = timer.Timer(line.strip(), index) ! if t.name is None: ! print 'Could not parse line ' + str(index) + ' in file ' + self.timerfile + ': ' + line.strip() ! self.timers.append(t) ! line = fh.readline() ! index = index + 1 ! fh.close() ! except IOError: ! return None ! ! return self.timers Index: timer.py =================================================================== RCS file: /cvsroot/vdrpylib/vdrpylib/vdr/timer.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** timer.py 24 Nov 2004 17:07:46 -0000 1.3 --- timer.py 7 Jan 2005 12:33:01 -0000 1.4 *************** *** 44,83 **** ##################################################################### def parsetime(t): ! """Converts a string containing a start or stop time in VDR's ! standard format ('hhmm') to the number of seconds since ! midnight. ! """ ! return int(t[0:2]) * 3600 + int(t[2:4]) * 60 def strtime(t): ! """Converts the numeric start and stop time into a string ! with VDR's standard format ('hhmm'). ! """ ! return string.zfill(str(int(t / 3600)), 2) + string.zfill(str(int(t / 60) % 60), 2) def parserecurrence(s): ! """Converts the given string from VDR's representation of ! recurring timers to a list with 7 elements evaluating to true ! or false. ! """ ! recurrence = [ 0 ] * 7 ! for counter in range(0, 7): ! recurrence[counter] = (not (s[counter] == '-')) ! return recurrence def strrecurrence(r): ! """Converts the internal recurrence representation into a string ! with VDR's format. ! """ ! s = '' ! for x in r: ! if x: ! s = s + 'X' ! else: ! s = s + '-' ! return s --- 44,83 ---- ##################################################################### def parsetime(t): ! """Converts a string containing a start or stop time in VDR's ! standard format ('hhmm') to the number of seconds since ! midnight. ! """ ! return int(t[0:2]) * 3600 + int(t[2:4]) * 60 def strtime(t): ! """Converts the numeric start and stop time into a string ! with VDR's standard format ('hhmm'). ! """ ! return string.zfill(str(int(t / 3600)), 2) + string.zfill(str(int(t / 60) % 60), 2) def parserecurrence(s): ! """Converts the given string from VDR's representation of ! recurring timers to a list with 7 elements evaluating to true ! or false. ! """ ! recurrence = [ 0 ] * 7 ! for counter in range(0, 7): ! recurrence[counter] = (not (s[counter] == '-')) ! return recurrence def strrecurrence(r): ! """Converts the internal recurrence representation into a string ! with VDR's format. ! """ ! s = '' ! for x in r: ! if x: ! s = s + 'X' ! else: ! s = s + '-' ! return s *************** *** 86,246 **** ##################################################################### class Timer: ! """This class represents a VDR timer. ! ! The index variable is an integer containing the index of this ! timer into the total list of timers of a VDR instance. ! ! The name variable is a string containing the name of this timer ! also serving as the name for the corresponding recording. ! ! The summary variable is a string containing the name of this ! timer also serving as the name for the corresponding recording. ! ! The channel variable is an instance of class Channel containing ! the channel this timer should record on. ! ! The start variable is an integer containing the number of seconds ! after midnight specifying the start time of the timer. ! ! The stop variable is an integer containing the number of seconds ! after midnight specifying the stop time of the timer. ! ! The day variable is an integer. If the recurrence variable is ! None, it contains the day of month on which the recording is to ! take place. If the recurrence variable is not None, day specifies ! the day of month on which the recurring recording is to take ! place the first time. ! ! The recurrence variable is a 7-element list containing values ! evaluating either to true or false. Each element represents a ! week day, element 0 being Monday through element 6 being Sunday. ! Their values indicate whether the recording shall take place at ! the corresponding week day. If the recurrence variable is not ! None, day specifies the day of month on which the recurring ! recording is to take place the first time. ! If the recurrence variable is None, this is a one-shot timer. ! ! The prio variable is an integer containing the priority of this ! timer. Values may range between 1 and 99. ! The lifetime variable is an integer containing the lifetime of ! this timer in days. Values may range between 1 and 99. ! ! The active variable is an integer evaluating to true if this ! timer is active and evaluating to false otherwise. ! """ ! def __init__(self, s = None, index = None, vdr = None): ! """Creates a new Timer object. ! ! The optional s argument is expected to be a string containing ! a timer specification as can be found in VDR's timers.conf ! file or as returned by the LSTT SVDRP command. ! ! The optional index argument is expected to be an integer ! containing the index of this timer into the global list of ! timers of a VDR instance. The index of a timer can only be ! derived from its specification string (i.e. the s argument) ! when it it's in the SVDRP format. When reading VDR's ! timers.conf file the timer indexes are encoded implicitely in ! the line number and have thus to be passed explicitely to ! this constructor. ! ! The optional vdr argument is expected to an instance of class ! VDR. When specified, this class can offer more advanced ! abstractions than without it in which case it merely serves ! as a data container. ! """ ! self.index = index ! self.name = None ! self.summary = None ! self.channel = None ! self.start = None ! self.stop = None ! self.day = None ! self.recurrence = None ! self.prio = None ! self.lifetime = None ! self.active = None ! self.vdr = vdr ! ! if s is not None: ! self.parse(s) ! ! ! def parse(self, s): ! """Parses a timer definition and updates the data of this ! object accordingly. ! ! The s argument is expected to be a string containing ! a timer specification as can be found in VDR's timers.conf ! file or as returned by the LSTT SVDRP command. Note that only ! the SVDRP version allows to derive the index of a timer from ! the specification string. ! ! The return value evaluates to true if the string s could be ! parsed successfully. ! """ ! if s is not None and isinstance(s, StringType) and len(s) > 5: ! s = s.strip() ! if s[0:3] == '250': ! s = s[4:] ! res = _pat.match(s) ! if res is not None: ! if res.group('index') is not None: ! self.index = int(res.group('index')) ! self.active = int(res.group('id')) ! self.channel = int(res.group('channel')) ! d = res.group('day') ! if len(d) == 7: ! self.day = None ! self.recurrence = parserecurrence(d) ! else: ! self.day = int(d) ! self.recurrence = None ! self.start = parsetime(res.group('start')) ! self.stop = parsetime(res.group('stop')) ! self.prio = int(res.group('prio')) ! self.lifetime = int(res.group('lifetime')) ! self.name = res.group('name') ! if self.name is None: ! self.name = '' ! self.summary = res.group('summary') ! if self.summary is None: ! self.summary = '' ! return 1 ! return 0 ! ! ! def __cmp__(self, other): ! """Compares two Timer objects by their indexes. ! """ ! return cmp(self.index, other.index) ! def __str__(self): ! """Returns a string representation of this object in the ! format of VDR's timers.conf file. ! """ ! day = '' ! if self.recurrence is not None: ! day = strrecurrence(self.recurrence) ! else: ! day = str(self.day) ! return string.join(map(str, [self.active, self.channel, day, strtime(self.start), strtime(self.stop), self.prio, self.lifetime, self.name, self.summary]), ':') ! def getchannel(self): ! """Returns the channel this timer refers to. ! ! In contrast to the numeric channel variable, this function ! returns a channel object if the vdr variable is not None. ! ! The return value is a instance of class Channel or None if ! this timer refers to no or an invalid channel or the vdr ! variable is None. ! """ ! if self.vdr and self.vdr.channels and self.channel: ! return self.vdr.getchannel(self.channel) ! return None ! --- 86,246 ---- ##################################################################### class Timer: ! """This class represents a VDR timer. ! ! The index variable is an integer containing the index of this ! timer into the total list of timers of a VDR instance. ! ! The name variable is a string containing the name of this timer ! also serving as the name for the corresponding recording. ! ! The summary variable is a string containing the name of this ! timer also serving as the name for the corresponding recording. ! ! The channel variable is an instance of class Channel containing ! the channel this timer should record on. ! ! The start variable is an integer containing the number of seconds ! after midnight specifying the start time of the timer. ! ! The stop variable is an integer containing the number of seconds ! after midnight specifying the stop time of the timer. ! ! The day variable is an integer. If the recurrence variable is ! None, it contains the day of month on which the recording is to ! take place. If the recurrence variable is not None, day specifies ! the day of month on which the recurring recording is to take ! place the first time. ! ! The recurrence variable is a 7-element list containing values ! evaluating either to true or false. Each element represents a ! week day, element 0 being Monday through element 6 being Sunday. ! Their values indicate whether the recording shall take place at ! the corresponding week day. If the recurrence variable is not ! None, day specifies the day of month on which the recurring ! recording is to take place the first time. ! If the recurrence variable is None, this is a one-shot timer. ! ! The prio variable is an integer containing the priority of this ! timer. Values may range between 1 and 99. ! The lifetime variable is an integer containing the lifetime of ! this timer in days. Values may range between 1 and 99. ! ! The active variable is an integer evaluating to true if this ! timer is active and evaluating to false otherwise. ! """ ! def __init__(self, s = None, index = None, vdr = None): ! """Creates a new Timer object. ! ! The optional s argument is expected to be a string containing ! a timer specification as can be found in VDR's timers.conf ! file or as returned by the LSTT SVDRP command. ! ! The optional index argument is expected to be an integer ! containing the index of this timer into the global list of ! timers of a VDR instance. The index of a timer can only be ! derived from its specification string (i.e. the s argument) ! when it it's in the SVDRP format. When reading VDR's ! timers.conf file the timer indexes are encoded implicitely in ! the line number and have thus to be passed explicitely to ! this constructor. ! ! The optional vdr argument is expected to an instance of class ! VDR. When specified, this class can offer more advanced ! abstractions than without it in which case it merely serves ! as a data container. ! """ ! self.index = index ! self.name = None ! self.summary = None ! self.channel = None ! self.start = None ! self.stop = None ! self.day = None ! self.recurrence = None ! self.prio = None ! self.lifetime = None ! self.active = None ! self.vdr = vdr ! ! if s is not None: ! self.parse(s) ! ! ! def parse(self, s): ! """Parses a timer definition and updates the data of this ! object accordingly. ! ! The s argument is expected to be a string containing ! a timer specification as can be found in VDR's timers.conf ! file or as returned by the LSTT SVDRP command. Note that only ! the SVDRP version allows to derive the index of a timer from ! the specification string. ! ! The return value evaluates to true if the string s could be ! parsed successfully. ! """ ! if s is not None and isinstance(s, StringType) and len(s) > 5: ! s = s.strip() ! if s[0:3] == '250': ! s = s[4:] ! res = _pat.match(s) ! if res is not None: ! if res.group('index') is not None: ! self.index = int(res.group('index')) ! self.active = int(res.group('id')) ! self.channel = int(res.group('channel')) ! d = res.group('day') ! if len(d) == 7: ! self.day = None ! self.recurrence = parserecurrence(d) ! else: ! self.day = int(d) ! self.recurrence = None ! self.start = parsetime(res.group('start')) ! self.stop = parsetime(res.group('stop')) ! self.prio = int(res.group('prio')) ! self.lifetime = int(res.group('lifetime')) ! self.name = res.group('name') ! if self.name is None: ! self.name = '' ! self.summary = res.group('summary') ! if self.summary is None: ! self.summary = '' ! return 1 ! return 0 ! ! ! def __cmp__(self, other): ! """Compares two Timer objects by their indexes. ! """ ! return cmp(self.index, other.index) ! def __str__(self): ! """Returns a string representation of this object in the ! format of VDR's timers.conf file. ! """ ! day = '' ! if self.recurrence is not None: ! day = strrecurrence(self.recurrence) ! else: ! day = str(self.day) ! return string.join(map(str, [self.active, self.channel, day, strtime(self.start), strtime(self.stop), self.prio, self.lifetime, self.name, self.summary]), ':') ! def getchannel(self): ! """Returns the channel this timer refers to. ! ! In contrast to the numeric channel variable, this function ! returns a channel object if the vdr variable is not None. ! ! The return value is a instance of class Channel or None if ! this timer refers to no or an invalid channel or the vdr ! variable is None. ! """ ! if self.vdr and self.vdr.channels and self.channel: ! return self.vdr.getchannel(self.channel) ! return None ! Index: mark.py =================================================================== RCS file: /cvsroot/vdrpylib/vdrpylib/vdr/mark.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mark.py 25 Nov 2002 22:05:35 -0000 1.3 --- mark.py 7 Jan 2005 12:33:01 -0000 1.4 *************** *** 22,85 **** class Mark: ! """This class represents an editing mark of a VDR recording. ! The seconds variable is an integer representing the offset of ! this mark into the recording in seconds. ! ! The frames variable is an integer representing the offset of ! this mark into the recording relative to the position ! indicated by the seconds variable. With 25 fps recordings the ! value of this variable ranges between 0 and 24. ! ! The comment variable is a string containing the comment of this ! mark. If there is no comment associated with this mark, this ! variable is None. ! """ ! _pat = re.compile('(\d\d):(\d\d):(\d\d)(\.(\d+))?( (.*))?') ! def __init__(self, str = None): ! """Construct a new Mark object. ! ! The optional str argument is a string containing the ! specification of an editing mark in the format of VDR's ! marks.vdr file. ! """ ! self.seconds = 0 ! self.frames = 0 ! self.comment = None ! ! if str is not None: ! self.parse(str) ! def parse(self, str): ! """Parse a string for editing mark data and update this ! object's data accordingly. ! ! The str argument is a string containing the ! specification of an editing mark in the format of VDR's ! marks.vdr file. ! """ ! res = _pat.match(str) ! self.seconds = int(res.group(1)) * 3600 + int(res.group(2)) * 60 + int(res.group(3)) ! if result.group(4) is None: ! self.frames = 0 ! else: ! self.frames = int(result.group(5)) ! self.comment = result.group(7) ! ! ! def __str__(self): ! """Returns a string representation of this mark in the format ! of VDR's marks.vdr file. ! """ ! s = str(self.seconds / 3600) + ':' + str((self.seconds / 60) % 60) + ':' + str(self.seconds % 60) ! if self.frames != 0: ! s = s + '.' + str(self.frames) ! if self.comment is not None: ! s = s + ' ' + self.comment ! return s ! --- 22,85 ---- class Mark: ! """This class represents an editing mark of a VDR recording. ! The seconds variable is an integer representing the offset of ! this mark into the recording in seconds. ! ! The frames variable is an integer representing the offset of ! this mark into the recording relative to the position ! indicated by the seconds variable. With 25 fps recordings the ! value of this variable ranges between 0 and 24. ! ! The comment variable is a string containing the comment of this ! mark. If there is no comment associated with this mark, this ! variable is None. ! """ ! _pat = re.compile('(\d\d):(\d\d):(\d\d)(\.(\d+))?( (.*))?') ! def __init__(self, str = None): ! """Construct a new Mark object. ! ! The optional str argument is a string containing the ! specification of an editing mark in the format of VDR's ! marks.vdr file. ! """ ! self.seconds = 0 ! self.frames = 0 ! self.comment = None ! ! if str is not None: ! self.parse(str) ! def parse(self, str): ! """Parse a string for editing mark data and update this ! object's data accordingly. ! ! The str argument is a string containing the ! specification of an editing mark in the format of VDR's ! marks.vdr file. ! """ ! res = _pat.match(str) ! self.seconds = int(res.group(1)) * 3600 + int(res.group(2)) * 60 + int(res.group(3)) ! if result.group(4) is None: ! self.frames = 0 ! else: ! self.frames = int(result.group(5)) ! self.comment = result.group(7) ! ! ! def __str__(self): ! """Returns a string representation of this mark in the format ! of VDR's marks.vdr file. ! """ ! s = str(self.seconds / 3600) + ':' + str((self.seconds / 60) % 60) + ':' + str(self.seconds % 60) ! if self.frames != 0: ! s = s + '.' + str(self.frames) ! if self.comment is not None: ! s = s + ' ' + self.comment ! return s ! |