« Core Jelly - structuring scripts using import | Main | db2 8.1 madness »

Scripting iTunes on Windows

At the Apple developer site I found a COM SDK for iTunes.
This allows anyone with a little JavaScript knowledge to script the iTunes app from the command line.
Its a reasonably easy object model to understand and makes batch processing of the iTunes library very easy.
Here's a simple script to list albums in your library (ListAlbums.js).
To run it, use the the cscript command. var iTunesApp = WScript.CreateObject("iTunes.Application"); var mainLibrary = iTunesApp.LibraryPlaylist; var tracks = mainLibrary.Tracks; var numTracks = tracks.Count; // array of albums, keyed by name, value of array element is the artist var albumArray = new Array(); for (i = 1; i <= numTracks; i++) { var currTrack = tracks.Item(i); var album = currTrack.Album; WScript.Echo("Processing track, Name: '" + currTrack.Name + "', by Artist: '" + currTrack.Artist); if ((album != undefined) && (album != "")) { if (albumArray[album] == undefined) { WScript.Echo("Adding album " + album); albumArray[album] = currTrack.Artist; } } } // dump out albums var count = 0; for (var name in albumArray) { count++; WScript.Echo("Album[" + count + "] = " + name + ", by " + albumArray[name]); }

TrackBack

TrackBack URL for this entry:
http://www.multitask.com.au/mt/mt-tb.cgi/82

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)