-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmp42mp3.sh
More file actions
executable file
·41 lines (35 loc) · 879 Bytes
/
mp42mp3.sh
File metadata and controls
executable file
·41 lines (35 loc) · 879 Bytes
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
#!/bin/bash
# @author Fred Brooker <git@gscloud.cz>
if [ $# -eq 0 ]; then
echo -e "\nConvert M4A files to MP3 recursively.\n\nSyntax: $(basename $0) <folder>\n"
exit 1
fi
which ffmpeg >/dev/null 2>&1 || (echo "Installing ffmpeg" && sudo apt-get install -yqq ffmpeg)
which ffmpeg >/dev/null 2>&1 || (echo "ERROR: ffmpeg is not installed" && exit 1)
if [ -n "$1" ]; then
if [ -d "$1" ]; then
cd "$1"
else
echo "Invalid folder: $1"
exit 1
fi
fi
for i in *; do
if [ -d "$i" ]; then
echo "Recursing into directory: $i"
$0 "$i"
fi
done
for i in *.m4a; do
if [ -f "$i" ]; then
echo "Converting: $i"
ffmpeg -i "$i" -codec:v copy -codec:a libmp3lame -b:a 320k "${i%.m4a}.mp3"
if [ $? -eq 0 ]; then
echo "Successfully converted: $i"
rm -f "$i"
else
echo "Failed to convert: $i"
fi
fi
done
echo -e "Done.\n"