0

尽管我设置的限制是 1,但使用 user.getRecentTracks,Last.fm 发送 2 首曲目。由于某个聪明人,如果我当前没有收听曲目,它只会发送一首曲目。

例如:http ://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=yeppaul&api_key=b25b959554ed76058ac220b7b2e0a026&limit=1

<lfm status="ok">
<recenttracks user="yeppaul" page="1" perPage="1" totalPages="1474" total="1474">
<track nowplaying="true">
<artist>
<name>The Offspring</name>
<mbid>23a03e33-a603-404e-bcbf-2c00159d7067</mbid>
<url>The Offspring</url>
<image size="small">http://userserve-ak.last.fm/serve/34/319822.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/319822.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/319822.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/319822.jpg</image>
</artist>
<loved>0</loved>
<name>Original Prankster</name>
<streamable>1</streamable>
<mbid>07933833-f6df-45eb-80ab-870e1d19b151</mbid>
<album mbid="05a93768-e317-338a-882e-fbe83790d8cd">Conspiracy of One</album>
<url>
http://www.last.fm/music/The+Offspring/_/Original+Prankster
</url>
<image size="small">http://userserve-ak.last.fm/serve/34s/47828469.png</image>
<image size="medium">http://userserve-ak.last.fm/serve/64s/47828469.png</image>
<image size="large">http://userserve-ak.last.fm/serve/126/47828469.png</image>
<image size="extralarge">
http://userserve-ak.last.fm/serve/300x300/47828469.png
</image>
</track>
<track>
<artist>
<name>The Offspring</name>
<mbid>23a03e33-a603-404e-bcbf-2c00159d7067</mbid>
<url>The Offspring</url>
<image size="small">http://userserve-ak.last.fm/serve/34/319822.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/319822.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/319822.jpg</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/319822.jpg</image>
</artist>
<loved>0</loved>
<name>Smash</name>
<streamable>0</streamable>
<mbid>1c6f6ba6-ea2e-4dcf-bef5-20f29d70611d</mbid>
<album mbid="021b8436-4c5f-3aa0-ac08-3ebf6470ada3">Smash</album>
<url>http://www.last.fm/music/The+Offspring/_/Smash</url>
<image size="small">http://userserve-ak.last.fm/serve/34s/60481175.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64s/60481175.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/60481175.jpg</image>
<image size="extralarge">
http://userserve-ak.last.fm/serve/300x300/60481175.jpg
</image>
<date uts="1347066244">8 Sep 2012, 01:04</date>
</track>
</recenttracks>
</lfm>

这是我的 jQuery:

$(document).ready(function(){ 
    $.ajax({
        type: "GET",
        url: "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=yeppaul&api_key=61d9a12fccfc085e5ddc70beccdbeaae&limit=5",
        dataType: "xml",
        success: showListens
    });
});

function showListens(xml) {
    $(xml).find("track").each(function()
    {
        $(".listen").append("<a href=" + $(this).find("url").text() + ">" + $(this).find("artist").text() + " &mdash; " + $(this).find("name").text() + "</a><br /><br />");    
    });
}
4

1 回答 1

2

由于track正在收听的曲目标有属性nowplaying="true",因此您可以使用以下方法过滤这些曲目not([nowplaying])

$(xml).find("track:not([nowplaying])").each(function()...
于 2012-09-08T01:12:17.263 回答