It’s actually pretty easy once you find out how to do it. By having the artist and album name you can fetch the album artwork from Amazon in three different sizes.
With php5 it’s very easy since it has an integrated xml parser. All we have to do is this:
$url = simplexml_load_file('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=12DR2PGAQT303YTEWP02&Operation=ItemSearch&SearchIndex=Music&Artist=ARTIST&ResponseGroup=Images&Keywords=ALBUMNAME');
Please note that in the url I’ve put ARTIST and ALBUMNAME, which you should replace with what you’re searching for. Doing so, we get an xml file from which we can display the image like this:
echo '<img src="' . $url->Items->Item[0]->LargeImage->URL . '" />';
If we want the large one, that is. If we would like the medium one we would use MediumImage and SmallImage for the small one.
That’s it, it’s very useful if you are organizing your mp3 files or maybe building an online community or something.
Hope it helps somebody! If you find it useful, digg it!
ps: I forgot to mention that if you are using php4 this wont work, you will have to use another xml parser to fetch the image location from the xml provided by Amazon.
Have swing!
[...] Read more from the original source: Use PHP to Fetch an Album Artwork From Amazon [...]
[...] Originally posted here: Use PHP to Fetch an Album Artwork From Amazon | iBlog random [...]
nice clear tutorial, thanks for sharing, only thing worth noting – to my knowledge simplexml_load_file() is a PHP 5 function.
No worky.
http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=12DR2PGAQT303YTEWP02&Operation=ItemSearch&SearchIndex=Music&Artist=ARTIST&ResponseGroup=Images&Keywords=ALBUMNAME results in ”
MissingParameterThe request must contain the parameter Signature.27ecb0a2-4953-4733-990d-05628706d4d1″That’s with me replacing your AWSAccessKeyId with ours.
Ideas, please! Thanks.
Uhm, actually I don’t know what’s wrong, I should check.. lately I’ve been using LastFM’s API and it works similarly, like this:
$url = simplexml_load_file(‘http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=YOUR_API_KEY&artist=ARTIST&track=TRACK_NAME’);
and then the image is:
$url->track->album->image[1]
You can apply for an api account here: http://www.last.fm/api/account