forked from mxdpeep/linux-bash-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflac2mp3.sh
More file actions
executable file
·86 lines (77 loc) · 1.63 KB
/
flac2mp3.sh
File metadata and controls
executable file
·86 lines (77 loc) · 1.63 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
79
80
81
82
83
84
85
86
#!/bin/bash
# Written by Filip Oščádal <filip@mxd.cz> <http://mxd.cz/>
# Distributed under license GPLv3+ GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY. YOU USE AT YOUR OWN RISK. THE AUTHOR
# WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY
# OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.
# See the GNU General Public License for more details.
# check syntax
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 -e "Invalid folder: $1\n"
exit 1
fi
fi
# check for installed app
which flac >/dev/null 2>&1
if [ $? -eq 1 ]
then
echo -e "Installing flac package...\n"
sudo apt-get install flac
fi
which flac >/dev/null 2>&1
if [ $? -eq 1 ]
then
echo -e "Flac is not installed!\n"
exit 1
fi
# check for installed app
which lame >/dev/null 2>&1
if [ $? -eq 1 ]
then
echo -e "Installing lame package...\n"
sudo apt-get install lame
fi
which lame >/dev/null 2>&1
if [ $? -eq 1 ]
then
echo -e "Lame is not installed!\n"
exit 1
fi
# recurse any directories first
for i in *
do
if [ -d "$i" ]
then
echo "Recursing into directory: $i"
$0 "$i"
fi
done
# convert recursively
for i in *.flac
do
if [ -d "$i" ]
then
echo "Recursing into directory: $i"
$0 "$i"
fi
if [ -f "$i" ]
then
echo "Converting: $i"
/usr/bin/flac -d "$i"
/usr/bin/lame -b 320 "${i%.flac}.wav" "${i%.flac}.mp3"
fi
done
sync
echo -e "\nDone.\n"
exit 0