From c26faa8dbbfd8752fe94b39465dd3579741363f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 31 Mar 2010 12:07:56 +0200 Subject: [PATCH] Add support to extract second precise parts --- download.cgi | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/download.cgi b/download.cgi index 43d9f06..ab4b6cd 100755 --- a/download.cgi +++ b/download.cgi @@ -56,6 +56,21 @@ else: if end < start: end = end + datetime.timedelta(1) +floor_start = start +if floor_start.second: + floor_start = floor_start.replace(second=0) +floor_start = floor_start.replace(minute=floor_start.minute/15*15) + +ceil_end = end +if ceil_end.second: + ceil_end = ceil_end.replace(minute=ceil_end.minute+1, second=0) +if ceil_end.minute%15: + if ceil_end.minute / 15 == 3: + ceil_end = ceil_end.replace(minute=0) + ceil_end += datetime.timedelta(seconds=3600) + else: + ceil_end = ceil_end.replace(minute=(1+(ceil_end.minute/15))*15) + os.chdir('/home/alsa-record/') def get_filenames(): @@ -68,8 +83,8 @@ def get_filenames(): filenames.sort() filenames = [x for x in filenames if - x >= start.strftime('%Y/%m-%b/%d-%a/%Hh%M') and - x < end.strftime('%Y/%m-%b/%d-%a/%Hh%M')] + x >= floor_start.strftime('%Y/%m-%b/%d-%a/%Hh%M') and + x < ceil_end.strftime('%Y/%m-%b/%d-%a/%Hh%M')] return filenames while True: @@ -102,5 +117,22 @@ if ext == 'ogg': command = ['sox'] + filenames + ['-t', 'ogg', '-C', '6', '-'] else: command = ['sox'] + filenames + ['-t', 'wav', '-'] + +if start != floor_start or end != ceil_end: + trim_parts = ['trim'] + if start != floor_start: + trim_start = (start - floor_start).seconds + trim_parts.append(str(trim_start)) + else: + trim_start = 0 + if end != ceil_end: + if trim_start: + duration = (end - start).seconds + trim_parts.append(str(duration)) + else: + trim_end = (ceil_end-end).seconds + trim_parts.append(str(trim_end)) + command.extend(trim_parts) + os.system(' '.join(command)) -- 2.39.2