Skip to content

Instantly share code, notes, and snippets.

@deadbok
Created February 19, 2015 21:45
Show Gist options
  • Save deadbok/0a18f923a25b6cd6205c to your computer and use it in GitHub Desktop.
Save deadbok/0a18f923a25b6cd6205c to your computer and use it in GitHub Desktop.
Covert FLAC files to MP3
#!/bin/bash
#Based on: https://wiki.archlinux.org/index.php/Convert_Flac_to_Mp3#Without_FFmpeg
for a in *.flac; do
# give output correct extension
OUTF="${a[@]/%flac/mp3}"
# get the tags
ARTIST=$(metaflac "$a" --show-tag=ARTIST | sed s/.*=//g)
TITLE=$(metaflac "$a" --show-tag=TITLE | sed s/.*=//g)
ALBUM=$(metaflac "$a" --show-tag=ALBUM | sed s/.*=//g)
GENRE=$(metaflac "$a" --show-tag=GENRE | sed s/.*=//g)
TRACKNUMBER=$(metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g)
DATE=$(metaflac "$a" --show-tag=DATE | sed s/.*=//g)
# stream flac into the lame encoder
flac -F -c -d "$a" | lame -b 192 -V0 --add-id3v2 --pad-id3v2 --ignore-tag-errors \
--ta "$ARTIST" --tt "$TITLE" --tl "$ALBUM" --tg "${GENRE:-12}" \
--tn "${TRACKNUMBER:-0}" --ty "$DATE" - "$OUTF"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment