使用user.getRecentTracks,Last.fm发送2首曲目,尽管我设置的限制是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() + " — " + $(this).find("name").text() + "</a><br /><br />");
});
}
答案 0 :(得分:2)
由于正在收听的track
标有属性nowplaying="true"
,因此您可以使用not([nowplaying])
过滤这些曲目:
$(xml).find("track:not([nowplaying])").each(function()...