Skip to content

Instantly share code, notes, and snippets.

@mvanduijker
Created January 12, 2013 12:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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