Last.fm API发送2个曲目时,我要求一个,如果我正在听一首歌

Last.fm API sends 2 tracks when I ask for one if I am listening to a song currently

本文关键字:如果 一首 一个 fm 发送 曲目 我要 Last API 2个      更新时间:2023-09-26

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

例如:http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=yeppaul&api_key=b25b959554ed76058ac220b7b2e0a26&限制=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 />");    
    });
}

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

$(xml).find("track:not([nowplaying])").each(function()...
相关文章: