1
1
import os
2
2
import sys
3
-
4
- # call 'cuebreakpoints | shnsplit'
5
- # check for errors
3
+ import shlex
4
+ from subprocess import call
6
5
7
6
# call cuetag
8
7
# check for errors
9
8
10
9
# programmatically rename by metadata (if possible)
11
10
12
11
def find_command (name ):
12
+ print ('checking for %s' % name )
13
13
for dir in os .environ ['PATH' ].split (':' ):
14
14
command = os .path .join (dir , name )
15
15
if os .path .exists (command ): return command
@@ -18,13 +18,25 @@ def print_usage():
18
18
print ('usage: wavCue2Flac albumPath' )
19
19
20
20
def find_cue_wav (path ):
21
+ print ('checking for cue/wav in %s' % path )
21
22
for root , dirs , files in os .walk (path ):
22
23
for file in files :
23
24
cue = os .path .abspath (os .path .join (root , file ))
24
25
if cue .endswith ('.cue' ):
25
- wav = cue .replace ('.cue' , '.wav' )
26
- if os .path .exists (wav ):
27
- return cue , wav
26
+ for ext in ['.wav' , '.wv' ]:
27
+ wav = cue .replace ('.cue' , ext )
28
+ if os .path .exists (wav ):
29
+ return cue , wav
30
+
31
+ def split_album (cue , wav ):
32
+ print ('splitting album with cuebreakpoints | shnsplit' )
33
+ os .chdir (os .path .dirname (cue ))
34
+ ret = call (
35
+ 'cuebreakpoints %s | shnsplit -q -o "flac flac -s --best -o %%f -" %s' % (shlex .quote (cue ), shlex .quote (wav )),
36
+ shell = True )
37
+ if ret != 0 :
38
+ print ('error calling cuebreakpoints/shnsplit' , file = sys .stderr )
39
+ sys .exit (1 )
28
40
29
41
if len (sys .argv ) != 2 :
30
42
print_usage ()
@@ -60,5 +72,4 @@ def find_cue_wav(path):
60
72
cue = paths [0 ]
61
73
wav = paths [1 ]
62
74
63
- print (cue )
64
- print (wav )
75
+ split_album (cue , wav )
0 commit comments