Friday, June 23, 2006

Add missing tracks to local iTunes


I have been getting bored with the music selection that I have on my iPod.  Since my laptop only has a subset of our total music collection, the iPod only has music from this set.


I wanted to make sure that the iTunes Library on my laptop had access to all of the music on the Mac mini, so I wrote the following script.  What it does is:


  • Iterates through the iTunes library on the Mac mini

  • For each track that is a MP3 of unprotected AAC file, checks with the local iTunes to see if a track with the same title, artist, and album exists

  • If no track exists, it adds a link to the remote file mounted via afp.


This script is not is not optimized, but it works.  And I am only planning on letting it run once.






using terms from application "iTunes"
    
    tell (choose remote application)
        repeat with t from 1 to count of (every file track of library playlist 1)
            set aTr to (file track t of library playlist 1)
            if kind of aTr = "MPEG audio file" or kind of aTr = "AAC audio file" then
                tell application "iTunes"
                    set trackList to (every file track of library playlist 1 where artist = (artist of aTr) and name = (name of aTr) and album = (album of aTr))
                    if (count of trackList) = 0 then
                        -- this track is not in the itunes
                        set filelocation to (location of aTr as string)
                        set filelocation to (characters 7 thru (length of filelocation) of filelocation as string)
                        set filelocation to "/Volumes" & filelocation
                        open (POSIX file filelocation as alias)
                    end if
                    
                end tell
            end if
            set foo to name of aTr
        end repeat
    end tell
end using terms from


Technorati Tags: ,

No comments:

Post a Comment

Mastering Matter: Seamless Smart Home Integration with Network Segmentation

I’ve been intrigued by the idea of integrating devices with Matter for some time. My smart home setup includes a pair of SwitchBot Hubs, som...