-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsplit-cue-flac
executable file
·82 lines (64 loc) · 1.65 KB
/
split-cue-flac
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/zsh
CUETAG_CMD=`dirname $0`/cuetag
ICONV_CUE_F=
ICONV_CUE_T=UTF8
while getopts 'hc:' OPTION
do
case $OPTION in
c)
ICONV_CUE_F=$OPTARG
;;
h)
printf "Usage: %s: [-c cue_encoding]\n" $(basename $0) >&2
exit 2
;;
esac
done
DISKNUM=
test_disk_image() {
DISKNUM=`echo "$1" | perl -pe 's/.*(?:cd|disk)\s*(\d+).*/$1/i'`
if [ "x$DISKNUM" = "x$1" ]; then
DISKNUM=""
fi
}
SAVEIFS=$IFS
IFS='\n'
WORKDIR=.tmp-split-cue-flac
find ./ -name '*.flac' -size +80M | while read image
do
echo "$image"
DIR=`dirname "$image"`
BASE=`basename "$image"`
BASE=`echo "$BASE" | sed -e 's/.flac//'`
CUE=$BASE.cue
IMAGE=$BASE.flac
cd "$DIR"
echo "Splitting with shnsplit"
rm -rf $WORKDIR
mkdir $WORKDIR
if [ "x$ICONV_CUE_F" != "x" ]; then
echo "Converting cue $CUE"
iconv -f $ICONV_CUE_F -t $ICONV_CUE_T "$CUE" -o "$WORKDIR/$CUE"
else
cp "$CUE" "$WORKDIR/$CUE"
fi && \
shnsplit -d $WORKDIR -o flac -f "$WORKDIR/$CUE" -t "%n – %t" "$IMAGE" && \
echo "Moving $IMAGE -> ${IMAGE}.image" && \
mv "$IMAGE" "${IMAGE}.image" && \
echo "Fixing tags with cuetag" && \
$CUETAG_CMD "$WORKDIR/$CUE" ./$WORKDIR/*.flac && \
test_disk_image "$IMAGE" && \
DSK= && \
if [ "x$DISKNUM" != "x" ]; then
DSK="CD$DISKNUM"
echo "Creating $DSK dir"
rm -rf $DSK
mkdir $DSK
fi && \
mv $WORKDIR/*.flac ./$DSK && \
rm -r $WORKDIR
if [ "x$DIR" != "x." ]; then
cd ../
fi
done
IFS=$SAVEIFS