2 # -*- coding: utf-8 -*-
11 syslog.openlog('pigebox')
21 end = '%s:%s' % (d.get('end_hour')[0], d.get('end_min')[0])
23 start = datetime.datetime.strptime('%s %s:%s' % (
24 d.get('date')[0], d.get('start_hour')[0], d.get('start_min')[0]),
26 end = datetime.datetime.strptime('%s %s:%s' % (
27 d.get('date')[0], d.get('end_hour')[0], d.get('end_min')[0]),
30 end = end + datetime.timedelta(1)
32 os.chdir('/home/alsa-record/')
35 path = start.strftime('%Y/%m-%b/%d-%a/')
36 filenames = [os.path.join(path, x) for x in os.listdir(path)]
37 if end.hour < start.hour:
38 path = end.strftime('%Y/%m-%b/%d-%a/')
39 if os.path.exists(path):
40 filenames.extend([os.path.join(path, x) for x in os.listdir(path)])
43 filenames = [x for x in filenames if
44 x >= start.strftime('%Y/%m-%b/%d-%a/%Hh%M') and
45 x < end.strftime('%Y/%m-%b/%d-%a/%Hh%M')]
49 filenames = get_filenames()
50 without_extension = [os.path.splitext(x)[0] for x in filenames]
51 for f in without_extension:
52 if without_extension.count(f) > 1:
53 # currently encoding, wait a moment and try again
54 print 'X-Currently-Encoding: please wait'
60 syslog.syslog(syslog.LOG_INFO, 'extraction (%s to %s)' % (
61 start.strftime('%Y-%m-%d %Hh%M'),
62 end.strftime('%Hh%M')))
66 print 'Content-Type: audio/x-wav'
69 print 'Content-Type: audio/ogg'
71 print 'Content-Disposition: attachment; filename=%s.%s\n' % \
72 (start.strftime('%Y-%m-%d-%Hh%M') + end.strftime('-%Hh%M'), ext)
77 command = ['sox'] + filenames + ['-t', 'ogg', '-C', '6', '-']
79 command = ['sox'] + filenames + ['-t', 'wav', '-']
80 os.system(' '.join(command))