Free iTunes Album Cover Artwork + Embed Artwork Image to MP3 via iTunes COM API SDK w/JavaScript

Misc Notes:

  • Given: iTunes has some pretty high quality cover art for many albums (all images are standard 600 x 600 pixels).
  • The basic trick here is that you can sign up for a free iTunes account (without providing any credit card or other personal info)…
  • And use that account to download the cover artwork for free.
  • Then run my script which will automate iTunes to extract the cover from iTunes’ special stash and save it as a real local image file
  • -AND- then embed that image back into the MP3 file so that it stays with the MP3 file no matter where it gets transferred.
  • The iTunes API is clean, the .CHM based API document that comes with the SDK is easy to navigate and is readily understandable… this really opens a lot of possibility with some quick javascript.
  • Note: if you’re experiencing the kind of trouble where the MP3 tag changes simply don’t take no matter what you do, try entirely wiping out the existing tags and start from scratch… for me, the “APE” metatag format always seemed to be a culprit (vs. “ID3” which is much more common)
  • MP3Tag is an excellent tool for bulk tag cleanup efforts like this… tons of good wizard driven actions you can perform on mp3 files names & tags… remove string, mixed case conversion, etc.
  • Standard list of iTunes genres for handy reference
  • Image size increasing MP3 size – if you’re trying to cram your music on a smart phone this could matter and I was asked about it.  Taking a quick random sampling of my covers I saw from 50k to 80k per 600 x 600 pixel JPG artwork added to each file.  Rounding up to 100k and assuming an average of 4MB’s per MP3 means for every 40 MP3’s you’re adding the size of an additional MP3 to your library.  A 16GB SSD would hold ~4 thousand MP3’s… adding images would knock that down by ~100.

Steps:

  1. Follow steps below to create free iTunes account… thus providing free artwork download capability
  2. in iTunes press CTRL-A to select all your tracks
    • now ONLY IF YOU WANT TO REPLACE all your existing artwork with iTunes covers… with your entire library selected in iTunes, right mouse and select “Get Info”, and then check the box next to the blank cover image and hit OK, this will clear the artwork from all your MP3 files!  Make sure you save any of the ones you care to keep ahead of time. It will take quite a while to complete that wipe, of course depending on the size of your library.
  3. Right-mouse and select “Get Album Artwork” – this will download covers for every MP3 file that doesn’t already have artwork embedded in the file. `
  4. Now run my script from CMD.EXE
    1. cscript EmbediTunesDLArtwork.js
    2. I’ll be honest, a handful of albums always proved stubborn, the scripted image embedding simply wouldn’t take for no apparent reasons, no errors… just had to do those few by hand.
  5. That’s basically it, go have a look!

Enjoy!

EmbediTunesDLArtwork.js
  1. var tracks = WScript.CreateObject("iTunes.Application").LibraryPlaylist.Tracks;
  2. var fso = WScript.CreateObject("Scripting.FileSystemObject");
  3. WScript.Echo("Tracks to analyze: " + tracks.Count);
  4. forEach(tracks, function (track)
  5. {
  6.   if (track.Kind == 1 && track.VideoKind == 0)
  7.   {
  8.     //"VideoKind: " + track.VideoKind + ", Kind: " + track.Kind + ", KindAsString: " + track.KindAsString +
  9.     //"Index: " + track.Index + ", PlayOrderIndex : " + track.PlayOrderIndex +
  10.     /* uncomment to collect missing artwork into a big group that’s easily grouped together in the iTunes GUI by sorting on the "Show" column header
  11.     if (track.Artwork.Count == 0)
  12.     {
  13.     track.Show = "!!missing artwork!!";
  14.     WScript.Echo("Missing artwork – Artist: " + track.Artist + ", Album: " + track.Album + ", Name: " + track.Name);
  15.     }
  16.     continue;
  17.     */
  18.     //now for all downloaded artwork, save it to an image file and then write it back into the mp3 file so that we’re free to carry music with artwork out of iTunes
  19.     var AlbumFolderName = fso.GetParentFolderName(track.Location) + "";
  20.     forEach(track.Artwork, function (art)
  21.     {
  22.       //debug:WScript.Echo("  IsDownloadedArtwork: " + art.IsDownloadedArtwork + ", Format: " + art.Format + ", Description: " + art.Description);
  23.       var AlbumArtworkFullPath = AlbumFolderName + track.Album.replace(new RegExp("[:?$/@*]", "g"), ".") + ArtworkFormatAsString(art.Format);
  24.       if (art.IsDownloadedArtwork)
  25.       {
  26.         try
  27.         {
  28.           if (!fso.FileExists(AlbumArtworkFullPath))
  29.           {
  30.             WScript.Echo("*** Saving Art to file: " + AlbumArtworkFullPath + " ***");
  31.             art.SaveArtworkToFile(AlbumArtworkFullPath);
  32.           }
  33.           WScript.Echo("    Saving art to MP3: " + track.Location);
  34.           art.SetArtworkFromFile(AlbumArtworkFullPath);
  35.         }
  36.         catch (ex)
  37.         {
  38.           WScript.Echo("        Error: " + ex.message);
  39.         }
  40.       }
  41.     });
  42.   }
  43. });
  44. function ArtworkFormatAsString(format)
  45. {
  46.   switch (format)
  47.   {
  48.     case 0: return (".unk"); break;
  49.     case 1: return (".jpg"); break;
  50.     case 2: return (".png"); break;
  51.     case 3: return (".bmp"); break;
  52.   }
  53. }
  54.  
  55. function forEach(enumerable, delegate)
  56. {
  57.   for (var enumerator = new Enumerator(enumerable); !enumerator.atEnd(); enumerator.moveNext())
  58.   {
  59.     delegate(enumerator.item());
  60.   }
  61. }
Register for free iTunes account:
Enter iTunes App Store Select “Free Apps” (currently in lower right page gutter) image
Select “Free App” image
Create New Account image
Continue image
Accept & Continue image
Enter Personal Info and Continue image
This is the big enchilada… Select “None” for payment type. Note: this option only shows up when you start by selecting a free download. image
Done image
Confirm the verification eMail via embedded link image
Pop the little iTunes download thingy and sign in <finally> image image
If all has gone according to plan… you should be greeted with this pleasantry You now have an album art download capable yet free iTunes account 🙂 image
  • Excelent script thankyou so much.