-
Notifications
You must be signed in to change notification settings - Fork 31
/
flac2mp3.sh
executable file
·66 lines (57 loc) · 1.12 KB
/
flac2mp3.sh
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
#!/bin/bash
# @author Fred Brooker <[email protected]>
if [ $# -eq 0 ]; then
echo -e "\nConvert FLAC files to MP3 recursively.\n\nSyntax: $(basename $0) <folder>\n"
exit 1
fi
if [ -n "$1" ]; then
if [ -d "$1" ]; then
cd "$1"
else
echo "Invalid folder: $1"
exit 1
fi
fi
which flac >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo "Installing flac"
sudo apt-get install -yqq flac
fi
which flac >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo "ERROR: flac is not installed"
exit 1
fi
which lame >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo "Installing lame"
sudo apt-get install -yqq lame
fi
which lame >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo "ERROR: lame is not installed"
exit 1
fi
for i in *
do
if [ -d "$i" ]; then
echo "Recursing into directory: $i"
$0 "$i"
fi
done
for i in *.flac
do
if [ -f "$i" ]; then
echo "Converting: $i"
j="${i%.flac}"
flac -d "$i"
lame -h --preset extreme "$j.wav" "$j.mp3"
if [ $? -eq 0 ]; then
echo "Successfully converted: $i"
rm -f "$i" "$j.wav"
else
echo "ERROR: Failed to convert: $i"
fi
fi
done
echo -e "Done.\n"