Download album art for free through a web service

by Mads Kristensen 13. October 2006 01:53

I recently played with building a C# media player with built-in music library and wanted it to show album covers like Windows Media Player 11 does. It proved quite difficult because there is no free service for downloads of album covers as far as I know. Then I stumbled upon a Coding4Fun article that used the Amazon web service for retrieval of book covers and thought it might also work for album covers. Sure enough, it did.

You can start to download album covers in three simple steps that only take 5 minutes.

  • Register for free at Amazon to get your devtag (or use mine, see the code below)
  • Add a web reference to your Visual Studio project
  • Use a simple method to download the album art

After you’ve registered to get your devtag, you can add the web service to your Visual Studio project. The address of the Amazon web service is http://soap.amazon.com/schemas3/AmazonWebServices.wsdl. Be sure to rename the Web reference name to "Amazon" in the dialog below.

 

That’s all the groundwork; now just use this simple method to start downloading album covers.

using System;

using System.Web;

using System.Web.Services.Protocols;

using System.Net;

using System.IO;

using Amazon;

 

public bool DownloadAlbumArt(string albumArtist, string albumTitle, string dirName)

{

  using (WebClient webClient = new WebClient())

  {

    KeywordRequest req = new KeywordRequest();

    req.keyword = albumArtist + " " + albumTitle;

    // Remember to register to get your own devtag.

    req.devtag = "D1QFTS4VAA6C72";

    req.mode = "music";

    req.type = "lite";

    req.page = "1";

 

    using (AmazonSearchService search = new AmazonSearchService())

    {

      try

      {

        ProductInfo productInfo = search.KeywordSearchRequest(req);

 

        if (productInfo.Details.Length > 0)

        {

          string url = productInfo.Details[0].ImageUrlLarge;

          webClient.DownloadFile(url, dirName + "/" + albumTitle + ".jpg");

        }

 

        return productInfo.Details.Length > 0;

      }

      catch (SoapException)

      {

        return false;

      }

    }

  }
}

Then call the method with this line of code:

DownloadAlbumArt("metallica", "load", @"c:\");

That will download this album cover to C:\load.jpg.

This is another example of something that seems difficult at first, but actually is pretty easy.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Tags:

Server-side

Comments

10/13/2006 8:47:36 PM #

 Rhonda Tipton

This is really cool.  I plan on trying it when I get home tonight.  You have one of the most informatative blogs.  I am a beginner and I get a lot of great information from this blog.  Keep up the good work.

Rhonda Tipton |

10/17/2006 2:05:42 AM #

 DamageINC

I downloaded the Yamo demo and used their SharpFactory.Yamo.Core.AmazonMediaInformationProvider class.
Here's the code:

Engine engine = new Engine(); // Also in SharpFactory.Yamo.Core
AmazonMediaInformationProvider amip = new AmazonMediaInformationProvider(engine);
amip.DownloadAlbumArt(currentArtist, currentAlbum, destDir);

The only problem I found with it is the image file name is always "Folder.jpg.

DamageINC |

10/17/2006 5:40:07 AM #

Mads Kristensen

I've been looking at the Yamo as well, but didn't care for at whole assembly for such a simple task as downloading album art. I'm very much against the whole nine yards if it is not needed. Simplicity is key. Besides that, the yamo is a great piece of code.

Mads Kristensen |

10/24/2006 12:19:00 AM #

 Troy Morvant

Take this to the next level and imbed the album art inside the ID3 tag.  I built a multi-threaded media library tool as well (used SQL express for very large collections) and needed to be able to work through 20K+ albums quickly and imbed the album art and found the ID3Lib library extremely helpful (http://id3lib.sourceforge.net/ ).  

Troy Morvant |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008