Created
November 14, 2016 20:06
-
-
Save jvhaarst/e5177dca032123d956dcbb7525b515dd to your computer and use it in GitHub Desktop.
BASH 4 script to convert m4a files into mp3 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/bash | |
# Error handling | |
set -o nounset | |
set -o errexit | |
set -o pipefail | |
# BASH 4 script to convert m4a files into mp3 files | |
# Needed programs : faad and lame | |
OIFS="$IFS" | |
IFS=$'\n' | |
for FILE in $(find . -maxdepth 1 -type f -name '*.m4a') | |
do | |
# Fill array with all the values of this file | |
# This took me some time to discover | |
# http://stackoverflow.com/questions/7612320/bash-weird-variable-scope-when-populating-array-with-results | |
# Create associative array | |
declare -A MYMAP | |
while IFS=$OIFS read KEY VALUE; do | |
# remove colon from key | |
KEY=$(echo "$KEY"|sed 's/://') | |
# Add key and value to associative array | |
MYMAP[$KEY]=$VALUE | |
done < <(faad -i "${FILE}" 2>&1 | grep ': ' | grep -v '^ ') | |
# Use info to tag new file | |
NEWNAME=$(basename "$FILE" .m4a)'.mp3' | |
echo "converting $FILE to $NEWNAME" | |
faad -q -w "$FILE" | \ | |
lame --silent --preset standard \ | |
--tt ${MYMAP[title]} \ | |
--ta ${MYMAP[artist]} \ | |
--tl ${MYMAP[album]} \ | |
--ty ${MYMAP[date]} \ | |
--tn ${MYMAP[track]}"/"${MYMAP[totaltracks]}] \ | |
--tg ${MYMAP[genre]} \ | |
- "${NEWNAME}" | |
done | |
IFS="$OIFS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment