Posts Tagged TVersity

iTunes Cover Art extraction script for Windows

I’ve recently started using iTunes to organize my music library, but I use TVersity and WMP (via UPnP A/V) to play it back. I needed a way to export iTunes cover artwork to Folder.jpg so WMP & TVersity could pick it up. After digging around for a while, I couldn’t really find a solution so I broke open my text editor and put together a little something to do the job. It’s a JavaScript file that uses the iTunes COM object.

As far as I know, iTunes must be running for this to work and I think you need to have your entire music library open for it to see all files. I’m not 100% sure about that, but just do it anyway. :o

Note: Please consolidate and organize your music library first. This script puts the Folder.jpg in the same folder as the track itself, so if you’ve got tracks scattered everywhere, you’re going to have a lot of Folder.jpg files everywhere.

Download this script here

The following is the contents of the script for those who just want to see the code and derive their own works.

/*
    File: ExportItunesArtwork.js 
 
    Version: 1.0 
 
    Copyright © 2010 Edward Presutti (intellidick.com), All Rights Reserved
*/ 
 
/* iTunes delcarations */
var ITTrackKindFile		= 1;
 
var ITArtworkFormatUnknown	= 0;
var ITArtworkFormatJPEG		= 1;
var ITArtworkFormatPNG		= 2;
var ITArtworkFormatBMP		= 3;
 
var	iTunesApp = WScript.CreateObject("iTunes.Application");
var	mainLibrary = iTunesApp.LibraryPlaylist;
var	tracks = mainLibrary.Tracks;
var	numTracks = tracks.Count;
var	fso = WScript.CreateObject("Scripting.FileSystemObject");
 
while (numTracks != 0)
{
	var	currTrack = tracks.Item(numTracks);	
 
	// is this a file track?
	if (currTrack.Kind == ITTrackKindFile)
	{
		// yes, does it have an empty location?
		if (currTrack.Location != "")
		{
			// no, let's get some artwork
			var artwork = currTrack.Artwork;
			var numArt = artwork.Count;
 
			while (numArt != 0)
			{
				var art = artwork.Item(numArt);
				// WScript.Echo("Album : " + currTrack.Album + ", Artwork Description : " + art.Description);
				var f = fso.GetFile(currTrack.Location);
				// WScript.Echo("Path : " + f.ParentFolder);
				var extension;
				switch (art.Format)
				{
					case ITArtworkFormatJPEG:
						extension = ".jpg";
						break;
					case ITArtworkFormatPNG:
						extension = ".png";
						break;
					case ITArtworkFormatBMP:
						extension = ".bmp";
						break;
				}
 
				if (art.Format != ITArtworkFormatUnknown)
				{
					var fname = f.ParentFolder + "\\" + "Folder" + extension;
					if (!(fso.FileExists(fname)))
					{
						WScript.Echo("Saving artwork : " + fname);
						art.SaveArtworkToFile(fname);
					}
				}
 
				numArt--;
			}
 
		}
	}
 
	numTracks--;
}

, , , , , , , ,

11 Comments