2 # ALAC/APE to FLAC converter script
5 # Email: m0rph.mailbox@gmail.com
10 type -P "$1" &>/dev
/null
12 echo "error: unable to find $1, please install required package and try again"
20 echo "many2flac converter version 1.14, (c) m0rph, 2011"
21 echo "email: m0rph.mailbox@gmail.com"
22 echo "supported input formats: ALAC, APE"
29 echo "usage: $(basename "${0}") [options] <input file(s)>"
31 echo " -h, --help display this help and exit"
32 echo " -e, --erase erase input file(s) after success conversion"
33 echo " -f, --force force overwrite output file(s)"
34 echo " -n, --native-flac use native flac encoder instead of ffmpeg"
35 echo " -r, --replay-gain calculate ReplayGain and store in FLAC tags"
36 echo " -0, --fast use compression level 0"
37 echo " -1 use compression level 1"
38 echo " -2 use compression level 2"
39 echo " -3 use compression level 3"
40 echo " -4 use compression level 4"
41 echo " -5 use compression level 5"
42 echo " -6 use compression level 6"
43 echo " -7 use compression level 7"
44 echo " -8, --best use compression level 8"
51 format
=$
(ffmpeg
-i "$1" 2>&1 |
grep "Audio: " | cut
-d ',' -f 1 | cut
-d ' ' -f 8)
52 if [[ $format != "alac" && $format != "ape" ]]; then
60 ffmpeg
-y -i "$1" -aq $compression "$2" &> /dev
/null
62 if [ $replay_gain_flag == 1 ]; then
63 flac
--force --replay-gain "$2" &> /dev
/null
70 title
=$
(ffmpeg
-i "$1" 2>&1 |
grep -i " title :" | cut
-d ':' -f 2 |
sed 's/^ *//')
71 artist
=$
(ffmpeg
-i "$1" 2>&1 |
grep -i " artist :" | cut
-d ':' -f 2 |
sed 's/^ *//')
72 album
=$
(ffmpeg
-i "$1" 2>&1 |
grep -i " album :" | cut
-d ':' -f 2 |
sed 's/^ *//')
73 year
=$
(ffmpeg
-i "$1" 2>&1 |
grep -i " date :" | cut
-d ':' -f 2 |
sed 's/^ *//')
74 track
=$
(ffmpeg
-i "$1" 2>&1 |
grep -i " track :" | cut
-d ':' -f 2 |
sed 's/^ *//')
75 genre
=$
(ffmpeg
-i "$1" 2>&1 |
grep -i " genre :" | cut
-d ':' -f 2 |
sed 's/^ *//')
77 pipe
=`mktemp -u -t many2flac.pipe.XXXXXX`
79 mplayer
-ao pcm
-ao pcm
:file="$pipe" "$1" -noconsolecontrols &> /dev
/null
&
80 if [ $replay_gain_flag == 1 ]; then
81 flac
--force "$pipe" --replay-gain -$compression \
82 -T title
="$title" -T artist
="$artist" -T album
="$album" \
83 -T date="$year" -T tracknumber
="$track" -T genre
="$genre" \
86 flac
--force "$pipe" -$compression \
87 -T title
="$title" -T artist
="$artist" -T album
="$album" \
88 -T date="$year" -T tracknumber
="$track" -T genre
="$genre" \
103 while [[ $# > 0 ]]; do
149 if [ ! -f "$1" ]; then
150 echo "error: unable to find \"$1\" file"
154 files
=("${files[@]}" "$1")
157 echo "error: invalid option $1"
162 echo "error: invalid argument: \"$1\""
172 if [[ ${#files[@]} == 0 ]]; then
173 echo "error: no input files"
180 check_program mplayer
182 for input_file
in "${files[@]}"; do
183 check_format
"$input_file"
185 echo "$input_file: unsupported format"
189 echo -n "converting $input_file"
190 output_file
=${input_file%.*}.flac
191 if [[ -f "$output_file" && $force_flag == 0 ]]; then
192 echo " - failure (file exists)"
196 if [ $native_flag == 1 ]; then
197 process_file_native
"$input_file" "$output_file"
199 process_file
"$input_file" "$output_file"
204 if [ $erase_flag == 1 ]; then