-
Notifications
You must be signed in to change notification settings - Fork 6
/
combine.py
executable file
·44 lines (33 loc) · 1.5 KB
/
combine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import argparse
import csv
import subprocess
import os
err = subprocess.Popen(['pip', 'install', 'ffmpeg'],
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE).communicate()[1]
if len(err) != 0:
print(err)
exit(1)
parser = argparse.ArgumentParser()
parser.add_argument('-shoutouts', type=str, default=os.path.join(os.path.curdir, 'prepared_shoutouts'),
help='Input shoutouts folder')
parser.add_argument('-tracks', type=str, default=os.path.join(os.path.curdir, 'prepared_tracks'),
help='Input tracks folder')
parser.add_argument('-output', type=str, default=os.path.join(os.path.curdir, 'klub.mp3'),
help='Output file')
args = parser.parse_args()
if not os.path.exists(args.shoutouts) or not os.path.exists(args.tracks):
exit(1)
inputs = []
with open('klub.csv', 'rt') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for i, row in enumerate(reader, 1):
inputs.append('-i')
inputs.append(os.path.join(args.shoutouts, str(i) + '.wav'))
inputs.append('-i')
inputs.append(os.path.join(args.tracks, str(i) + '.wav'))
filter_ = ''.join(('[' + str(a) + ':0]' for a in range(0, 2 * i))) + 'concat=n=' + str(2 * i) + ':v=0:a=1[out]'
process = subprocess.Popen(['ffmpeg', *inputs, '-filter_complex', filter_, '-map', '[out]', args.output],
stdout=subprocess.PIPE)
process.communicate()