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():
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:
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))