I'm sure this utility exists somewhere in a more robust implementation, but google hasn't led me to it. So I present for posterity, a simple bash utility to copy the songs in a given playlist to a new location.
Note that I've been unable to figure out all the intricacies of unicode filenames.
Thus my first attempts with rsync met with failure as have attempts to move each individual file. So this script only moves the 'album' directory, assuming neither the artist or album have extended characters in them. Otherwise it's skipped and the activity is left as an exercise for the user.
Accordingly, the albums in a playlist are copied even if only one song from that album is in the playlist. So yes, there has been a little false advertising regarding the functionality of this script in hopes the disappointment leads to a correct solution by your hand.
Sadly, you must first install 'fileutils' from fink. Since the mac cp util doesn't support a handful of features.
sudo fink install fileutils
To get the playlist, export it from iTunes into some directory (File -> Export Song List) after selecting the playlist. Pass that filename to the below script.
#!/bin/bash
TARGET=/some/dir
DATA=`pwd`
cat $1 | tr '\r' '\n' | cut -f25 | cut -d":" -f7- | cut -d":" -f1,2 | tr ':' '/' | sort | uniq > out.txt
cd ~/Music/iTunes/iTunes\ Music
while read FILE
do
echo -n "$FILE"
if [ "$FILE" != "" ]; then
echo " copying"
cp -u -v -r --parents --target-directory $TARGET "${FILE}/"
fi
done < ${DATA}/out.txt
cd $DATA
Real bash hackers, please comment if you can lead to a way to supporting unicode filenames, and especially when using rsync. I'm mounting a smb share to get these files someplace useful, and that sucks.
Leave a comment