Scripting iTunes.. A look at Apple’s iTunes SDK

:apple:

I came across the iTunes SDK while trying to find a way to automate the deletion of ghost song entries out of my iTunes library. Over time the iTunes library on my machine had become unusable, I had moved or deleted a bunch of of my music files with (not in iTunes) and thier entries remained in the iTunes library. I had always used iTunes for playing back music and had dealt with the inconvience of the ghost entries. With the arival of a iPod Nano at my doorstep, I found these entries to be truly annoying and determined that they needed to go. Sure, I could have just deleted the XML database files and gone through the process re-adding the folders to the library but that would have eliminated my play lists, play counts, last played, and ratings. So here enters the iTunes Software Development Kit (SDK) from Apple. This SDK shows you how to start using the Component Object Model (or COM) interface developed in the iTunes application. This COM interface allows you to use external tools to manipuate the actions of iTunes. Some people choose to use full blown developement environments like Visual Studio but since the Windows scripting host is installed by default on Windows XP machines we can use the notepad application. By using javascript and VBScript we create a text file that are interpreted by the Windows scripting Host (WSH) and executed with no need to compile or go through a setup program. I am not going dive into the intricacies of what a SDK is and how to use them in this article, for that I suggest you look to Google. You can download Apple’s iTunes SDK for Windows from Apples Developer’s site here. It is a small zip file, only 267KB in size. Please review the licensing agreement before you agree and download the SDK. I need to mention that while my experiences have been positive and I can’t be held responsible for negative end user experiences. The ZIP files contains the following files:

  • iTunesCOM.chm - Compressed HTML help file containing the documentation on the iTunes COM interface.
  • iTunesCOMInterface.h - COM header file used when developing in C++.

  • iTunesCOMInterface_i.c - Also a COM header file used when developing in C++.

  • samples/RemoveDeadTracks.js - Iterates over your library and removes any tracks that can no longer be found on disk.

  • samples/RemoveUserPlaylists.js - Deletes all non-smart user playlists your library.

  • samples/CreateAlbumPlaylists.js - Iterates over all tracks in your library, creates a new playlist for each album, and adds the tracks for that album to the playlist.
To execute one of the sample scripts make sure iTunes is running, browse to the directory that contails the file and double click the file. It will get processed by the WSH and execute the script. The RemoveDeadTracks script was exactly what I wanted. It did run for a long time (my library was pretty big and messed up). When it was done.. it prompted me with a message box letting me know how many songs it removed from the library. All was good in the world. The RemoveUserPlaylists is most useful if you want to clean up all the random playlists you have created. Think of it as a hatchet that gets rid of all your playlists. I used this on a test machine and it did exactly as promised. I was tempted to run this on my primary machine, but was just too lazy to do so. When it is done running a message box will prompt you with the number of playlists deleted. The CreateAlbumPlaylists is another useful script. For a long time I wanted to create playlists of all my albums, but became a tedious task. As long as all your music is tagged properly it works wonderfully. If they aren’t tagged, you will end up with one big record. When it is done running a message box will prompt you with the number of playlists created. Many software companies offer SDKs for their programs. Many of them come at a cost. It is great that Apple releases this to the public for free. This SDK definitely has peeked my interest in iTunes interface development. I think I am going to start working on a script that will remove the duplicate files out of my database while maintaining album integrity. Look for it in a future posting…… Download Apple’s iTunes SDK for Windows from Apples Developer’s site here. Technorati Tags: , , , StumbleUpon It!

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Ipod1 cheap

I am Karin, very interesting article that contained the information I was searching for in Google, thanks.

[...] I previously introduced you to the iTunes for Windows SDK in a previous article. As I mentioned in the previous article, I had just received my iPod Nano and came to the realization that my iTunes library was out of control. I discovered the iTunes SDK and the sample scripts it included. I was especially pleased with the RemoveDeadTracks script that deleted all the orphaned song entries that were left after I deleted the songs outside of the iTunes interface. I still had a problem with duplicate tracks, and decided it was the perfect oportunity to use the SDK to automate the deletion of these duplicate tracks. After spending a little time getting acquainted with the SDK I broke out my favorite script editor (windows notepad) and started to get to work. [...]

[...] <!–adsense#button–>I looked at the iTunes SDK in “Scripting iTunes.. A look at Apple’s iTunes SDK” and I have shared with you a script I have wrote to eliminate duplicate song entries in your iTunes library in “Using the iTunes SDK to Remove Duplicate Songs“.   I have used the feedback to help improve this script and am working on a way to remove the orphaned (or dead) song entries using VBScript.   [...]

[...] This is a continuing look at what we can accomplish with the  iTunes SDK.   If you have missed the previous articles in this series please take a look at  An introduction to Apple’s iTunes SDK, Removing Duplicate Songs, and Removing Orphaned Songs.  [...]

Leave a comment

(required)

(required)