Skip to content

Instantly share code, notes, and snippets.

@pascalopitz
Created August 6, 2011 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pascalopitz/1129468 to your computer and use it in GitHub Desktop.
Save pascalopitz/1129468 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ "$1" ]
then
find "$1" -name '*.flac' | while read fn;
do
basename=$(basename "$fn" .flac).mp3
dirname=$(dirname "$fn")
outfile="$dirname/$basename"
if [ -e "$fn" ] && [ ! -e "$outfile" ];
then
id3title=$(metaflac --show-tag=TITLE "$fn" | perl -pe "s/^TITLE=(.*)/\$1/i")
id3artist=$(metaflac --show-tag=ARTIST "$fn" | perl -pe "s/^ARTIST=(.*)/\$1/i")
id3album=$(metaflac --show-tag=ALBUM "$fn" | perl -pe "s/^ALBUM=(.*)/\$1/i")
id3date=$(metaflac --show-tag=DATE "$fn" | perl -pe "s/^DATE=(.*)/\$1/i")
id3tracknumber=$(metaflac --show-tag=TRACKNUMBER "$fn" | perl -pe "s/^TRACKNUMBER=(.*)/\$1/i")
id3genre=$(metaflac --show-tag=GENRE "$fn" | perl -pe "s/^GENRE=(.*)/\$1/i")
flac -c -d "$fn" | \
lame -h -m s -b 360 \
--tt "$id3title" \
--ta "$id3artist" \
--tl "$id3album" \
--ty "$id3date" \
--tn "$id3tracknumber" \
--tg "$id3genre" \
- "$outfile"
else
echo >&2 ""$fn" -- skipping."
fi
done
else
echo >&2 "Usage: "$(basename "$0")" DIRNAME"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment