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: ,

2 comments:

  1. noted your project here and wonder whether yu can help me with one of my own.
    I'm attempting to weed down my library after converting the files to AAC (to save space on my harddisk) and, while most come out as smaller files, some are actually larger. I'm looking for a script I can use that will find files with the same name, by the same artist, that are the same time length and delete the larger of the two or more.
    The reason why time length is an issue is I have different recording of the same songs by the same artist that I would like to keep.
    The reason why it may be more than two to choose from is that some files were copied more than once by accident.
    Thanks for any help.

    ReplyDelete
  2. ech,
    If you want to find all of the tracks that have the same artist, title and duration you can use an applescript like this:
    tell application "iTunes"
    set trackList to every file track of library playlist 1 where artist = "Louis Armstrong" and name = "Christmas In New Orleans" and duration = 173
    end tell
    If you were to run some code like that for every track in your library, you can get the list of duplicates. If the list is greater than one track, then delete the one that is largest.
    One thing to be aware of is that I have noticed that when ordering tracks by track number, sometime iTunes will not interleave the tracks of different type.

    ReplyDelete

Seamless Local Control: Integrating WeatherFlow with Home Assistant Across VLANs

I've been pleased with my Home Assistant setup for some time now. One of my main focuses has been achieving local control. This ensures...