iTunes favorites mix tape generator: Now with more Entropy

Last summer I devised an AppleScript to generate a fixed-length, one track per-artist iTunes playlist. This worked pretty well, but I’ve been using this script long enough and frequently enough that I started to notice that my supposedly random playlists contained clumps of tracks that had all been played on the same date a few months ago, as though my previous random playlists were just getting recycled into new ones.

So I added some additional logic to enforce a one track per artist, one track per-date rule - no more clustered tracks.

The updated script also contains a couple of other niceties:

  • It tells iTunes to focus (in case you’re running the script via some sort of launcher like Quicksilver)
  • It presents you with a choice of durations.

The next logical iteration would be additional interface allowing you to select source and destination playlists, but I haven’t gotten irked enough by that problem to solve it yet.

-- Mix Tape iTunes playlist generator
-- by Andy Chase | http://andychase.net
-- January 11, 2010

tell application "iTunes" to activate tell application "iTunes" set theSmartPL to playlist "Unrecent Alt/Rock Faves" set theDumbPL to playlist "Unrecent Faves Cassette"

set cassetteLengths to {30, 45, 60, 74, 90, 120}

set theDuration to 60 * {choose from list cassetteLengths with title "Cassette Length" default items {45} without multiple selections allowed}

set allArtists to {}
set allDates to {}

delete every track of theDumbPL

set selectedTracks to every track of theSmartPL

repeat with aTrack in selectedTracks

    if (the duration of theDumbPL ? theDuration) then

        set theArtist to the artist of aTrack
        set theDate to the played date of aTrack
        set theDateString to the date string of theDate
        if (theArtist is not in allArtists and ((duration of aTrack) + (duration of theDumbPL)) ? theDuration and theDateString is not in allDates) then
            duplicate aTrack to theDumbPL
            set end of allArtists to theArtist
            set end of allDates to theDateString
        end if

    end if
end repeat

set the shuffle of theDumbPL to true
reveal theDumbPL
play theDumbPL

end tell

AttachmentSize
Flip Unrecent Faves Cassette.scpt7.03 KB
Syndicate content

Twitter

Older

Contact

Andy Chase
(978) 297-6402
andychase [at] gmail.com
GPG/PGP Public Key