Tuesday, November 20

ITunes: Deleting Dead Tracks From ITunes

I just got a new iPhone and I'm converting my music from Media Player to iTunes.

There are some key differences between these apps.

1. Media Player gets properties off of the actual file or folder. iTunes saves some information in its database and some of it is in the file.

2. Media Player puts an album art file for album art, where iTunes puts the album art in a Album Art folder, then under some convoluted database that doesn't match back to the album. Neither of the players will look for the other, so converting is not fun.

3. iTunes copies files when organizing its library, iTunes copies creating duplicate files. Media Center Moves the files underneath my consolidated library.

4. iTunes doesn't know if the file system deleted a file or a new file exists in the library. Media Player continually looks for new music, pictures and movies.

This is why I found the following code, in the Apple SDK, that will delete dead tracks from you iTunes library.

dim ITTrackKindFile

ITTrackKindFile = 1

dim iTunesApp

set iTunesApp = WScript.CreateObject("iTunes.Application")

dim deletedTracks

deletedTracks = 0

dim mainLibrary

set mainLibrary = iTunesApp.LibraryPlaylist

dim tracks

set tracks = mainLibrary.Tracks

dim numTracks

numTracks = tracks.Count

dim i

while (numTracks <> 0)

dim currTrack

set currTrack = tracks(numTracks)

if ( currTrack.Kind = ITTrackKindFile) then

' yes, does it have an empty location?

if (currTrack.Location = "") then

' yes, delete it


deletedTracks = deletedTracks + 1

end if

end if

numTracks = numTracks - 1


if (deletedTracks > 0) then

if (deletedTracks = 1) then

WScript.Echo("Removed 1 dead track.")


WScript.Echo("Removed " & deletedTracks & " dead tracks." )

end if


WScript.Echo("No dead tracks were found.")

end if


WAAW33 said...

did you find the piece of code on some other site?

I think you should quote were you found it. As there are probably many other useful scripts...

And would also be more fait to the people that write scripts, coying is easy. ;-)


Cold Chilli said...

I got the code from the Apple SDK for Windows. and adjusted the post