Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create playlists in iTunes for all complete albums Apps
User Aphex5 posted an interesting question on Stack Exchange, asking if there was a way to create playlists for all complete albums in his iTunes library. He then followed up with an answer, the following AppleScript:
-- Creates a playlist for each full album you have in iTunes
-- Set the playlistPrefix and playlistSuffix as desired before running

-- Based on code by Brad Campbell
-- http://www.bradcampbell.com/2009/05/26/make-a-whole-album-playlist-in-itunes/

tell application "iTunes"
    set playlistPrefix to "FA: "
    set playlistSuffix to ""
    -- The "FA: " prefix will help cluster full albums in iTunes' playlists,
    -- and is narrow enough to not get in your way when viewing on an iPhone

    set albumBuckets to {} as list
    set allSongs to (every track of library playlist 1 whose enabled is true and podcast is false and kind contains "audio") as list

    -- Find all partial albums in iTunes
    repeat with currentTrack in allSongs
        set albumName to album of currentTrack as text
        set artistName to artist of currentTrack as text

        -- First check for missing values, then perform integer comparison
        -- Zero is on the left to force interger type coercion, just in case
        if album of currentTrack is not missing value and 0 is less than length of albumName then
            if artist of currentTrack is not missing value and 0 is less than length of artistName then
                if track number of currentTrack is not missing value and 0 is less than track number of currentTrack then
                    if track count of currentTrack is not missing value and 0 is less than track count of currentTrack then
                        if albumBuckets does not contain album of currentTrack then
                            copy album of currentTrack to the end of albumBuckets
                        end if
                    end if
                end if
            end if
        end if

    end repeat

    repeat with currentAlbum in albumBuckets
        set albumSongs to (every track of library playlist 1 whose album is currentAlbum)
        set firstTrack to first item of albumSongs

        -- Filter album list to act only on full albums
        if (count of albumSongs) is equal to track count of first item of albumSongs and 1 is less than (count of albumSongs) then
            -- This is a full album, construct the playlist

            -- Sort tracks by track number
            set albumSongsSorted to {} as list
            repeat with i from 1 to (count of albumSongs)
                repeat with trk in albumSongs
                    if track number of trk is i then
                        set nextSong to trk
                        copy nextSong to the end of albumSongsSorted
                    end if
                end repeat
            end repeat

            -- Don't show artist name for compilations
            if firstTrack is not compilation then
                set playlistNameArtist to artist of firstTrack & " - "
            else
                set playlistNameArtist to ""
            end if

            set albumPlaylistName to playlistPrefix & playlistNameArtist & currentAlbum & playlistSuffix

            -- Create playlist
            if user playlist albumPlaylistName exists then
                try
                    delete tracks of user playlist albumPlaylistName
                end try
            else
                make new user playlist with properties {name:albumPlaylistName}
            end if

            try
                repeat with trk in albumSongsSorted
                    duplicate trk to user playlist albumPlaylistName
                end repeat
            end try
        end if
    end repeat

    display dialog "Playlists created! Check iTunes for playlists beginning with '" & playlistPrefix & "'"
end tell
This will traverse the iTunes library and make playlists for every album where the number of tracks matches the total number of tracks for the album; in other words, if you only have one or six songs from a ten-song album, it won't make a playlist. Naturally, this assumes that you have the correct metadata for your tracks to enable this. If you don't, you can go through your albums - one by one, alas - using Doug Adams' Albumize Selection AppleScript; this script sets both track number and track count tags to the appropriate numbers.
    •    
  • Currently 3.13 / 5
  You rated: 4 / 5 (8 votes cast)
 
[5,845 views]  

Create playlists in iTunes for all complete albums | 5 comments | Create New Account
Click here to return to the 'Create playlists in iTunes for all complete albums ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create playlists in iTunes for all complete albums
Authored by: shled on Feb 11, '13 08:43:32AM

Haven't tried the script yet but feel obligated to bring two of the best programs out there for Mac using music lovers with large libraries. I have been using MPFreaker/ [http://www.lairware.com/mpfreaker/] for many years and started using Song Sergeant [http://www.lairware.com/songsergeant/] about two years ago. Both let you really get control of your music. I have no connection with LairWare except as a satisfied customer.



[ Reply to This | # ]
Create playlists in iTunes for all complete albums
Authored by: david-bo on Feb 12, '13 03:03:17PM

What's the purpose with this hint? I just don't understand, hence my question.

---
link



[ Reply to This | # ]
Create playlists in iTunes for all complete albums
Authored by: Unsoluble on Feb 13, '13 10:19:44AM

Maybe there's some other esoteric purpose, but I can think of one (sort of) -- many iOS apps, like the one I use for tracking my runs, allow you to choose music to listen to, but *only* from a list of playlists. That is, I can't just choose an album, I have to have pre-create an actual playlist with the contents of that album in it. So maybe for that sort of thing?

Edited on Feb 13, '13 10:20:11AM by Unsoluble



[ Reply to This | # ]
Create playlists in iTunes for all complete albums
Authored by: morespace54 on Mar 08, '13 10:12:07AM

Can't tell but my guess is that it can be useful to temporarily "manage" you music collection from within iTunes. I've ripped (and re-ripped) my CDs quite a few time over the years (mp3 192, mp3 256, alac, etc.) only to find out some album are still missing a few songs (either because I mistakenly erased them or because iTunes cleverly put those tracks on a different album - the band was singing with a guess artist and/or the "album by artist" field wasn't properly filed). I guess I could use this AS to do a check on which album is complete and to found out most of them are not...

Edited on Mar 08, '13 10:13:18AM by morespace54



[ Reply to This | # ]
Create playlists in iTunes for all complete albums
Authored by: msadesign on Feb 13, '13 05:07:47AM

I don't see the purpose either, since iTunes already does pretty much the same thing. And I can say from personal experience that once you get a few hundred album playlists iTunes will slow to a crawl.



[ Reply to This | # ]