Last.fm Recent Tracks

Tapping in to the Lat.fm API to get a user's recent tracks via jQuery and JSON.

by Wederson

HTML

<div id="top_artist"></div>


 
 <Promotion id="da70e592" queries="liu castelly,liu,lidiane" title="Liu Castelly - Ouvir Músicas de Liu Castelly" url="http://xmusica.com.br/p/?name=p.php?a=Liu Castelly%26" image_url="" start_date="" end_date="" is_regex="false" enabled="true" description="Ouças as músicas da Liu Castelly aqui no Xmúsica .com.br, lançamentos músicas novas e antigas."/>

CSS

.nope
{
opacity:0.9;
filter:alpha(opacity=25);
}

JavaScript

$.getJSON('http://ws.audioscrobbler.com/2.0/?method=user.getTopArtists&user=xinita&limit=1000&api_key=ea9fa4f5486cf49531e6f1261c7bf217&format=json&callback=?', function(data) {
    var items = [];
    var now_playing = "";
    var artist = data.topartists.artist;

    $.each(artist, function(i) {

        var found = 'nope';

        switch (true) {
        case artist[i].name === 'Animal Collective':
            found = 'yeah';
            break;
        case artist[i].name === 'Foster The People':
            found = 'yeah';
            break;
        }



        items.push('<Promotion id="da70e592" queries="' + artist[i].name + '" title="' + artist[i].name + ' - Ouvir Músicas de ' + artist[i].name + '" url="http://xmusica.com.br/p/?name=p.php?a=' + artist[i].name + '%26" image_url="' + artist[i].image[1]["#text"] + '" start_date="" end_date="" is_regex="false" enabled="true" description="Ouças as músicas da' + artist[i].name + ' aqui no Xmúsica .com.br, lançamentos músicas novas e antigas."/>');
    });

    $('#top_artist').append(items.join(''));

});