Monday, February 13, 2006

script to filter tracks by location


When I added all of the tracks from our server to my iTunes library, I had a lot of duplicate tracks.  On my laptop, I had the protected AAC files, and the server has the mp3 format versions.


First I used iTunes "Show Duplicate Tracks" menu item to display all of the duplicate tracks.  Then I selected all of the tracks and created a playlist with those.  Then I ran this script which puts all of the duplicate tracks that are located on the server into a new playlist.







set pathToServer to "Music:"

tell application "iTunes"
    if not (exists (some playlist whose name is "toBeDeleted")) then
        set new_playlist to (make new playlist with properties {name:"toBeDeleted"})
    else
        set mySource to container of view of front window
        set new_playlist to playlist "toBeDeleted"
    end if
    repeat with t from 1 to count of every file track of playlist "Duplicate tracks"
        with timeout of 300000 seconds
            try
                set aTr to (file track t of library playlist 1)
                set trackLoc to location of aTr as string
                if ((offset of (pathToServer as string) in trackLoc) is 1) then
                    -- This track came from Shrook
                    -- the track has not been added to playlist
                    duplicate aTr to new_playlist
                end if
            end try
        end timeout
    end repeat
end tell



Then all I had to do was delete the tracks in the "toBeDeleted" playlist.


Technorati Tags: ,