-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplit-record
executable file
·63 lines (55 loc) · 1.57 KB
/
split-record
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
'''
Given a recording and a tracklist in any ffmpeg-supported audio format,
split the single record into multiple MP3 tracks.
Suggested usage: cat tracklist.txt | ./split.py > run.sh
Then inspect and execute run.sh
Tracklist is read from stdin and is expected to begin with the name of a
side (which is used as the input filename) followed by one line for each
track, consisting of track number, name, and duration.
Sides are separated by a newline.
For example:
SIDE1
1 Track Name One 1:23
2 Track Name Two 3:11
SIDE1
3 Track Name Three 0:34
4 Track Name Four 4:23
'''
import datetime
import os
import time
import subprocess
import sys
if os.isatty(0):
print 'tracklist on stdin required!'
print __doc__
sys.exit(1)
sides = {}
tracks = []
firstline = True
for line in sys.stdin:
if line == '\n':
sides[sidename] = tracks
tracks = []
firstline = True
continue
if firstline:
sidename = line.strip()
firstline = False
else:
line = line.strip()
num = line.split()[0]
name = ' '.join(line.split()[:-1])
time = line.split()[-1]
tracks.append((num, name, time))
sides[sidename] = tracks
for side in sides:
seek = datetime.timedelta()
for track in sides[side]:
(num, name, time) = track
t = datetime.datetime.strptime(time, '%M:%S')
time = t.strftime('%H:%M:%S')
print 'ffmpeg -i "%s" -ss %s -t %s "%s.mp3"' % (side, seek, time, name)
delta = datetime.timedelta(minutes=t.minute, seconds=t.second)
seek += delta