Querying Amazon Product API to get ASIN of MP3 download using artist and title
Asked Answered
M

2

5

I am new using Amazon's Product Advertising API, and for my first project with it, I am trying to get the ASIN of the MP3 download product of a particular song, based on the artist and title. I will eventually be using these ASINs to populate an Amazon MP3 Clips Widget.

I am using the PHP class from CodeDiesel.com to get started. It works just fine, and I have added the following function:

    public function searchMusic($artist, $title) {
        $parameters = array("Operation"     => "ItemSearch",
                            "Artist"        => $artist,
                            "Title"         => $title,
                            "SearchIndex"   => "Music",
                            "ResponseGroup" => "Medium");
        $xml_response=$this->queryAmazon($parameters);
        return $xml_response;
    }

Now, the trouble is, I can only seem to get albums this way. For instance, if I put in "Robert Randolph" for the artist, and "Colorblind" for the title, I get Robert Randolph and the Family Band's Colorblind album. If I search for a particular track, such as "Thrill Of It", Amazon can't find anything.

So what I need to do is first figure out how to make a query for track title. Then I need to figure out how to limit my results to just MP3 downloads. How can I do this?

If there is documentation on the topic, can you point me in the right direction? I have been reading through it, but don't see any parameters for what I want.

Thank you for your time.

Marentic answered 16/2, 2011 at 18:25 Comment(0)
W
9

The documentation is oddly organized, and I have a hard time finding relevant information myself.

To look up mp3s, you have to change your SearchIndex parameter to 'MP3Downloads'. Then, instead of using "Artist" and "Track", you have to use "Keywords". Combine the artist and track values into one string for the "Keywords" property value. Also, try "MusicTracks" for SearchIndex, as you might get different results there as well.

This is a snippet from a working system I have that does a similar type of lookup.

    $params = Array(
        "Operation"=>'ItemSearch',
        "SearchIndex"=>'MP3Downloads',
        "ResponseGroup"=>'ItemAttributes,Tracks,Images',
        "Keywords"=>$track['title'].' '.$artist['name']
    );
Whelk answered 16/2, 2011 at 18:31 Comment(0)
A
2

This was a problem I had as well. I worked from the same example which I heavily modified and incorporated into a whole collection of classes which I made mashups out of. What I really want is the previews from Amazon given an artist and album title. I'm going to keep working on it, now that I still have too much time on my hands. My mashup codebase is here:

My Mashup's and codebase

I keep getting referrals from this question, my solution is basically the same as Chris's, I have two methods/functions that do this in my code:

        /**
     * Return the tracks found on an album, have to page to get them all which this method does not do.
     * 
     * @param string $albumTitle 
     * @param string $artist
     * @return mixed simpleXML object
     */
    public function getMP3sForAlbumByArtist($albumTitle, $artist)
    {
        $searchTerm = $albumTitle . ' ' . $artist;
        $parameters = array("Operation"   => "ItemSearch",
                            "Keywords"    => $searchTerm,
                            "SearchIndex" => AmazonProductAPI::CATEGORY_MP3_DOWNLOADS,
                            "ResponseGroup" => AmazonProductAPI::RESPONSE_GROUP_TRACKS);

        $xml_response = $this->queryAmazon($parameters);

        return $xml_response;
    }



    /**
     * Return the tracks found on a song title and artist
     * 
     * @param string $songTitle 
     * @param string $artist
     * @return mixed simpleXML object
     */
    public function getMP3ForSongByArtist($songTitle, $artist)
    {
        $searchTerm = $songTitle . ' ' . $artist;
        $parameters = array("Operation"   => "ItemSearch",
                            "Keywords"    => $searchTerm,
                            "SearchIndex" => AmazonProductAPI::CATEGORY_MP3_DOWNLOADS,
                            "ResponseGroup" => AmazonProductAPI::RESPONSE_GROUP_TRACKS);

        $xml_response = $this->queryAmazon($parameters);

        return $xml_response;
    }

My code is downloadable from the above link or is in GitHub, it is based on older code examples I've updated. It is running OK on my host, but iTunes is better for previews of songs.

Autopsy answered 4/10, 2011 at 22:25 Comment(6)
HI. How to search only on original tracks ?Melanimelania
I haven't worked with that API in years. Amazon, Google, and others change the API and what is permissible. I'm not even sure what you mean by original tracks, the entire song? Amazon isn't going to let you access the entire song, they make it almost impossible to access the preview.Autopsy
Thks for your answer. I have improved your post, ans changed the version to 2013... And it works perfectly ;). By original, I would like to say "official release", like it is named in musicbraiz or discogs php api.Melanimelania
Hooray for me, now I need to update my GData code and I don't want to use Zend, I have just one method, why do I need to add so much more code to my project...Autopsy
Don't undestand what you want ?Melanimelania
Nothing I am on to the next problem. :-)Autopsy

© 2022 - 2024 — McMap. All rights reserved.