first time i run it master
authorMauro Scomparin <scompo@gmail.com>
Mon, 31 Aug 2020 16:55:58 +0000 (18:55 +0200)
committerMauro Scomparin <scompo@gmail.com>
Mon, 31 Aug 2020 16:55:58 +0000 (18:55 +0200)
splitter.py [new file with mode: 0644]
test/in.txt [new file with mode: 0644]

diff --git a/splitter.py b/splitter.py
new file mode 100644 (file)
index 0000000..e635793
--- /dev/null
@@ -0,0 +1,34 @@
+import subprocess
+import shlex
+import re
+import sys
+
+command_template = "ffmpeg -i \"{}\" -ss \"{}\" -to \"{}\" -c copy \"{}\""
+
+def main() :
+    print("Audio splitter")
+    audio_file=sys.argv[2]
+    start="00:00:00"
+    track_file=sys.argv[1]
+    count = 0
+    with open(track_file) as f:
+        for line in f:
+            line_clean = line.rsplit("\n")[0]
+            if line_clean != "":
+                count = count + 1
+                pieces = line_clean.split("\t")
+                start= pieces[0]
+                stop=pieces[1]
+                output_file=str(count).zfill(2) + "-" + pieces[2] + ".ogg"
+                command = command_template.format(audio_file, start, stop, output_file)
+                # command="echo hello"
+                print("Running command: {}".format(command))
+                split_command = shlex.split(command)
+                process=subprocess.Popen(split_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+                stdout, stderr = process.communicate()
+                print(stdout.decode())
+                print(stderr.decode())
+
+if __name__ == "__main__":
+    main()
+
diff --git a/test/in.txt b/test/in.txt
new file mode 100644 (file)
index 0000000..4f7645c
--- /dev/null
@@ -0,0 +1,4 @@
+00:00  01:00   out 1
+01:00  02:00   out 2
+02:00  03:00   out 3
+