Skip to content

Instantly share code, notes, and snippets.

@devpg
Created December 22, 2012 20:18
Show Gist options
  • Save devpg/4360864 to your computer and use it in GitHub Desktop.
Save devpg/4360864 to your computer and use it in GitHub Desktop.
Exports the iTunes music library of the current user by coping *.mp3 files into folder based on the genre
#!/bin/bash
# Rewrite IFS default seperator
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
itunesFolder="/Users/$USER/Music/iTunes/iTunes Media/Music"
for file in $(find "$itunesFolder" -name '*.mp3'); do
genre=$(id3v2 -l "$file" | sed -n '/^TCON/s/^.*: //p' | sed 's/ (.*//')
if [ -n "$genre" ] && [ \! -d "$1/$genre" ]; then
mkdir "$1/$genre"
fi
# Missing "genre" will copy the file to the root output folder
cp "$file" "$1/$genre"
echo "$genre ==> $(basename $file)"
done
# Set IFS default seperator
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment