logo

Make a “Whole Album” Playlist in iTunes

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.

Download

FullAlbumPlaylist.js

  1. Benn
    Awesome post. Being able to make your own *actually* smart playlists would be really helpful. I had a similar problem with my laptop/desktop combo. Tremendously cool post.
  2. moole
    -- AppleScript version: tell application "iTunes" -- the minimum number of plays that at least one song on the album has to have set minPlayCount to 3 set albumList to {} as list set allSongs to (every track of library playlist 1 whose enabled is true and podcast is false and kind contains "audio" and genre does not contain "Books & Spoken") as list repeat with i from 1 to count of allSongs set currentTrack to item i of allSongs set albumId to artist of currentTrack & album of currentTrack if ((played count of currentTrack is greater than (minPlayCount - 1)) and (albumId is not in albumList)) then set albumList to albumList & albumId end if end repeat set albumsPlaylistName to "Albums with Played Count > " & minPlayCount if user playlist albumsPlaylistName exists then try delete tracks of user playlist albumsPlaylistName end try else make new user playlist with properties {name:albumsPlaylistName, shuffle:false, song repeat:«constant eSpKkSpN»} end if repeat with i from 1 to count of allSongs set currentTrack to item i of allSongs set albumId to artist of currentTrack & album of currentTrack if albumId is in albumList then duplicate currentTrack to user playlist albumsPlaylistName end if end repeat display dialog "Done! Check " & albumsPlaylistName & " playlist." end tell

Leave a Reply

*

captcha *