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.
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--; }

#1 by lacda333 on June 7, 2010 - 9:28 pm
Yes, iTunes must be running for this to work.
I have 1200 albums in Apple Lossless format, many of them have their artworks stored in ITunes folder.
Your Javascrip works great.
Now my Squeezebox Duet sees all the artworks.
Thank you
PS: I had to press the OK button 1200 times. Is there any way to avoid that?
#2 by ekrunch on June 7, 2010 - 9:52 pm
Yes. I think you ran it using wscript, which is fine except that any message I echo out requires an OK. Try running it using cscript instead and it should just echo the messages out to the console. If you double click it from Explorer, you’re going to get wscript I think so go to the command line and just do “cscript ExportItunesArtwork.js” (Or whatever you named yours)
I’m glad this script worked out for you. I’ve got quite a few albums myself and run a TVersity server so I had to do something to get some cover art!
#3 by ekrunch on June 7, 2010 - 9:55 pm
Also, if you don’t care to see the output at all, you can just remove the line that says
WScript.Echo(“Saving artwork : ” + fname);
That will stop it from echo’ing anything but errors. Then you can continue to use wscript to run it if you’d like and not have to press OK unless there is an error of some sort.
#4 by Ray on February 27, 2011 - 1:20 am
How do i use this script? do i just run it with the latest itunes version?
#5 by ekrunch on March 21, 2011 - 3:40 pm
Using “cscript”. Fire up iTunes (it must be running), extract the script to a directory and navigate there via a command prompt, then type “cscipt ExportItunesArtwork.js” and you’re done. It should kick off and run, depending on how fast your machine is and how big your library is, you should start seeing output with 15-20 seconds.
#6 by Deen on March 25, 2011 - 10:07 am
Thanks for that script. It seems to work (at least for some albums) but I always get an error message: ,,c:\ExportItunesArtwork.js(45, 5) (null): serious error”
I tried to run it with cscript and wscript, both extracts some of the covers but it ends in the same error.
(Win7 64-bit and latest iTunes version)
#7 by ekrunch on March 25, 2011 - 5:37 pm
Interesting, I’m using W7 64-bit and the latest iTunes as well. I just deleted all of my folder.jpg files and re-ran the script across my collection (539 albums, all with cover art) and it ran successfully. If you could run the script in debug mode (use cscript /? for help) and can possibly get a more meaningful error, maybe I can help. Unfortunately, I didn’t code a lot of error handling logic into the script. It was just something I threw together and seems to work for most people so I haven’t really had to.
You might have some library corruption or something going on. Also, have you consolidated your library? It’s possible that the script could be trying to write a folder.jpg to a place that you don’t have write access to, like removable media or something. Or if you have items that you’ve deleted and haven’t cleaned them out of your library, the folder won’t exist and my script doesn’t try to make directories. Unfortunately though, iTunes still hands them to me like they exist so if my script tries to write and the directory no longer exists or you don’t have write access, it’ll bomb out.
Consolidate your library and look for missing files and see if that helps.
Good luck!
#8 by Deen on March 28, 2011 - 11:29 am
Thanks for your response. I thought my iTunes Library would be well organized, but I’ve found some removed tracks and duplicates. Tip: iTunes shows removed tracks only if you try to play them, but by clicking on ,,File –> Library –> Consolidate Files”, not just files are consolidated, iTunes even highlights all removed tracks which are still in your library. My library was already consolidated but as it turned out, these removed files were the problem.
Unfortunately the script still quits and shows the same error (debug-mode wasn’t very useful, the only additional information was the error code ,,8000FFFF” and as you probably know (45, 5) stands for line 45, character 5).
But now, after running the script several times, I have all covers in the right place.
Do you know if it’s possible the increase the resolution of the output files? I’d like to have another file named cover.jpg in original size, cause wmplayer scales down all folder.jpg files to 200×200 and shows only cover.jpg in full resolution. Changing the name was easy but I’m still looking for the line which is defining the size.
Greets
#9 by ekrunch on March 31, 2011 - 2:16 am
I actually was aware that iTunes doesn’t mark removed tracks until you consolidate or try to play them. I learned that one the hard way as well.
Unfortunately, it is not possible to change the resolution. My script tells iTunes to write the file out, it doesn’t actually do it. I just set the filename and path and iTunes does the actual work. iTunes controls the file type, resolution, etc, so there’s no line you can change to affect the output resolution. It’s whatever resolution you have stored in iTunes. That’s what gets outputted.
#10 by Ron on November 3, 2011 - 4:19 am
Thanks a lot!
I just got a new MP3 player that requires all artwork to be in separate “cover.jpg” files, and this solved my problem perfectly.