Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple script to export iTunes library to mp3. (use it for my car radio usb stick) You need faad and lame Tested on mac brew install faad2 lame
#!/bin/bash
itunes_folder="/Users/MacBookPro/Music/iTunes/iTunes Media/Music"
output_folder="/Users/MacBookPro/MP3s"
if [ ! -d "$output_folder" ]; then
mkdir -p "$output_folder"
fi
find "$itunes_folder" -type f | while read FILENAME;
do
file=$(basename "$FILENAME")
extension="${file##*.}"
file_no_ext="${file%.*}"
rel_path=${FILENAME/$itunes_folder/}
rel_path=${rel_path%$file}
if [ "$extension" = "m4a" ];
then
target_folder="$output_folder$rel_path"
#create directory if not exists
if [ ! -d "$target_folder" ]; then
mkdir -p "$target_folder"
fi
faad -o - "$FILENAME" | lame -V2 - "$output_folder$rel_path$file_no_ext".mp3
elif [ "$extension" = "mp3" ];
then
#create directory if not exists
if [ ! -d "$target_folder" ]; then
mkdir -p "$target_folder"
fi
cp "$FILENAME" "$output_folder$rel_path$file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment