-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.sh
More file actions
executable file
·78 lines (71 loc) · 2.67 KB
/
split.sh
File metadata and controls
executable file
·78 lines (71 loc) · 2.67 KB
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
#!/bin/bash -x
## Date 20171109
cdir=$(pwd)
if [[ ! -d "$1" ]];then
sdir=$cdir
echo "Selected the current directory:"
echo "---------------------------------"
echo "$cdir"
echo "---------------------------------"
else
case $1 in
-h | --help)
echo "Usage: $0 [Path]"
echo "The default Path is the current directory@@@"
exit 1
;;
*)
if [[ -d "$1" ]];then
cd "$1" && sdir=$(pwd)
echo "Selected directory:"
echo "---------------------------------"
echo "$1"
echo "---------------------------------"
else
echo "Usage: $0 [Path]"
exit 1
fi
;;
esac
fi
storagebase=$HOME/Lossless
tmpdir=$storagebase/tmp
[[ ! -d "tmpdir" ]] && mkdir -p "$tmpdir"
audiofiletxt=$cdir/audiofile.txt
[[ ! -f "$audiofiletxt" ]] && touch "$audiofiletxt"
## find all audio files
find "$sdir" -regextype posix-extended -regex ".*(flac|wav|ape)$" | sort > "$audiofiletxt"
while read audiofile;
do
audiodir=$(dirname "$audiofile") && cd "$audiodir"
audioname=$(basename "$audiofile")
#audiotype=${audioname##*.}
#trackname=${audioname%.*}
trackname=${audioname%%.*}
storagepath=$storagebase/$trackname
[[ ! -d "$storagepath" ]] && mkdir -p "$storagepath"
if [[ -f "${trackname}.cue" ]];then
## convert file encode to utf-8
codetype=$(file "${trackname}.cue" | grep ISO-8859)
[[ -n "$codetype" ]] && iconv -f ISO-8859-1 -t UTF-8 -o "${trackname}.cue" "${trackname}.cue"
shnsplit -d "$tmpdir" -f "$trackname".cue -o "flac flac --no-utf8-convert -V --best -o %f -" "$audioname" -t "%n%p-%t"
## Delete the wrong track file
find "$tmpdir" -regextype posix-extended -regex ".*/00.*" -exec rm {} \;
cuetag.sh "$trackname".cue "$tmpdir"/*.flac
elif [[ -f "${audioname}.cue" ]];then
## convert file encode to utf-8
codetype=$(file "${audioname}.cue" | grep ISO-8859)
[[ -n "$codetype" ]] && iconv -f ISO-8859-1 -t UTF-8 -o "${audioname}.cue" "${audioname}.cue"
shnsplit -d "$tmpdir" -f "$audioname".cue -o "flac flac --no-utf8-convert -V --best -o %f -" "$audioname" -t "%n%p-%t"
## Delete the wrong track file
find "$tmpdir" -regextype posix-extended -regex ".*/00.*" -exec rm {} \;
cuetag.sh "$audioname".cue "$tmpdir"/*.flac
else
echo "Wrong cue file path"
exit 1
fi
[[ -d "$tmpdir" ]] && mv "$tmpdir"/* "$storagepath"
done < "$audiofiletxt"
cd "$sdir"
[[ -f "$audiofiletxt" ]] && rm "$audiofiletxt"
[[ -d "$tmpdir" ]] && rmdir "$tmpdir"