]> git.0d.be Git - pige-extractor.git/commitdiff
Add support to extract second precise parts
authorFrédéric Péters <fpeters@0d.be>
Wed, 31 Mar 2010 10:07:56 +0000 (12:07 +0200)
committerFrédéric Péters <fpeters@0d.be>
Wed, 31 Mar 2010 10:07:56 +0000 (12:07 +0200)
download.cgi

index 43d9f0654b6fb773d6aedae609bb83b0b1f88989..ab4b6cd7edf76060461ee4fe1c96d8b9803bb52e 100755 (executable)
@@ -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))