I just bought a 16gb iPod Touch. I was looking at the Classic for it’s decent capacity, but I decided that functionality was more important than raw space. However, my music collection is pushing 40gb, and a “16gb” iPod is really only 14.52gb. So I had to get creative with what music I can have with me. I had two goals in mind: I wanted to have the music I listen to the most and the full album of any song. To do this I had to create an iTunes script to create a playlist for me.
I wish I could just use iTunes’s smart playlists, but they really don’t offer much flexibility. Their major downside is that they don’t allow for any sort of cross-column logic, for instance I can’t match all tracks by an artist with multiple albums. To do something like that I had to use a more powerful interface. Mac users can use Applescripts, which obviously aren’t on Windows. Luckily javascript scripts can interface with iTunes and work quite well. I found this site of iTunes scripts and used their examples to make my own.
My script runs through the music library in iTunes and finds any tracks with at least minPlayCount plays (I used 5). Then it adds all the tracks from the albums that contain those tracks to a new playlist called “Full Albums”. This essentially creates an iPod version of a multi-disc CD player, which is exactly what I wanted.
FullAlbumPlaylist.js
var iTunesApp = WScript.CreateObject("iTunes.Application");
var mainLibrary = iTunesApp.LibraryPlaylist;
var mainLibrarySource = iTunesApp.LibrarySource;
var tracks = mainLibrary.Tracks;
var numTracks = tracks.Count;
var i;
//the minimum number of plays that at least one
//song on the album has to have
var minPlayCount = 5;
var albumArray = new Array();
for (i = 1; i <= numTracks; i++)
{
var currTrack = tracks.Item(i);
var album = currTrack.Album;
var artist = currTrack.Artist;
var playcount = currTrack.PlayedCount;
if (playcount >= minPlayCount && albumArray[album+artist] == undefined) {
albumArray[album+artist] = 1;
}
}
albumPlaylist = iTunesApp.CreatePlaylist("Full Albums");
for (i = 1; i <= numTracks; i++)
{
var currTrack = tracks.Item(i);
var album = currTrack.Album;
var artist = currTrack.Artist;
if (albumArray[album+artist] == 1) {
albumPlaylist.AddTrack(currTrack);
}
}
To run this script, I used the command prompt (first change to the directory where the script is, and open iTunes):
wscript FullAlbumPlaylist.js
This playlist is a great start, but it was missing some songs (particularly newer additions to my library). So, I also added a smart playlist that matches songs with at least 2 plays to my iPod. This gives me a pretty good set of music to listen to when I’m not at my computer.
