Saying stuff about stuff.

Bash script to convert media to MP3 and add it to iTunes

Despite this task sounding difficult it’s actually very simple, FFmpeg does all the hard work (I suggest using Homebrew to install brew install ffmpeg) and not only converts other audio formats to MP3 but can also extract audio from video files.

Adding to iTunes is also ridiculously easy nowadays. There’s no mucking about with AppleScript, you simply have to move the file to a special iTunes folder (~/Music/iTunes/iTunes Music/Automatically Add to iTunes/) and iTunes will assimilate the file into its directory structure.

#!/usr/bin/env sh
if [ $# -eq 0 ]; then
cat <<USAGE
Convert multiple media files to MP3 and add them to iTunes in one line.
Usage:
$ 2mp3 list of files to convert
USAGE
else
for path in "$@"; do
name=$(basename $path)
name=${name%.*}
mp3="$name.mp3"
ffmpeg -i "$path" -f mp3 "$mp3"
mv "$path" ~/.Trash
mv "$mp3" ~/Music/iTunes/iTunes\ Music/Automatically\ Add\ to\ iTunes/
done
fi
view raw 2mp3 hosted with ❤ by GitHub

Here’s the Gist.