通过 last.fm API 获取歌曲的专辑名称
Getting album name of song via last.fm API
我正在尝试使用 "Last.fm" APIs 获取一些给定歌曲名称的元数据。
这是我使用/track.search API. However, I am wondering how to get the album name of the song because to use /album.search时的示例结果 API我需要专辑名称。
感谢任何帮助或提示。谢谢。
{
"results": {
"opensearch:Query": {
"#text": "",
"role": "request",
"startPage": "1"
},
"opensearch:totalResults": "685711",
"opensearch:startIndex": "0",
"opensearch:itemsPerPage": "1",
"trackmatches": {
"track": [
{
"name": "Believer",
"artist": "Imagine Dragons",
"url": "https://www.last.fm/music/Imagine+Dragons/_/Believer",
"streamable": "FIXME",
"listeners": "359856",
"image": [
{
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "small"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "medium"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "large"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "extralarge"
}
],
"mbid": ""
}
]
},
"@attr": {}
}
}
基于 last.fm API 文档(截至 05/09/2020),/track.search response does not contain album information for each track listed in the search results response. You would need to extract name
and artist
information from your search results response and use /track.getInfo 获取相册信息的端点。响应中的相册名称是 album.title
。
例子
我正在使用 /track.search
搜索“seven nation army”
{
"results": {
"opensearch:Query": {
"#text": "",
"role": "request",
"startPage": "1"
},
"opensearch:totalResults": "30560",
"opensearch:startIndex": "0",
"opensearch:itemsPerPage": "1",
"trackmatches": {
"track": [{
"name": "Seven Nation Army",
"artist": "The White Stripes",
"url": "https://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army",
"streamable": "FIXME",
"listeners": "1583146",
"image": [{
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "small"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "medium"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "large"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "extralarge"
}
],
"mbid": "24cc8311-98fd-423a-bed1-97728f5eabc5"
}]
},
"@attr": {}
}
}
我将从这个回复中提取:
$.results.trackmatches.track[:1].name
-> “七国军”
$.results.trackmatches.track[:1].artist
-> “白色条纹”
并用作 /track.getInfo
的输入
{
"track": {
"name": "Seven Nation Army",
"mbid": "24cc8311-98fd-423a-bed1-97728f5eabc5",
"url": "https://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army",
"duration": "231000",
"streamable": {
"#text": "0",
"fulltrack": "0"
},
"listeners": "1583146",
"playcount": "12806149",
"artist": {
"name": "The White Stripes",
"mbid": "11ae9fbb-f3d7-4a47-936f-4c0a04d3b3b5",
"url": "https://www.last.fm/music/The+White+Stripes"
},
"album": {
"artist": "The White Stripes",
"title": "Elephant",
"mbid": "bb29bd28-71e7-32d3-ab5f-c2d33b25434a",
"url": "https://www.last.fm/music/The+White+Stripes/Elephant",
"image": [{
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "small"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "medium"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "large"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "extralarge"
}
],
"@attr": {
"position": "1"
}
},
"toptags": {
"tag": [{
"name": "rock",
"url": "https://www.last.fm/tag/rock"
},
{
"name": "alternative rock",
"url": "https://www.last.fm/tag/alternative+rock"
},
{
"name": "alternative",
"url": "https://www.last.fm/tag/alternative"
},
{
"name": "indie",
"url": "https://www.last.fm/tag/indie"
},
{
"name": "indie rock",
"url": "https://www.last.fm/tag/indie+rock"
}
]
},
"wiki": {
"published": "09 Aug 2008, 10:12",
"summary": "\"Seven Nation Army\" is the first track on the album Elephant by American alternative rock band The White Stripes. It was released as a single in 2003, and is one of the best-known songs from the band. Seven Nation Army reached #1 on the Modern Rock Tracks for three weeks and won 2004's Grammy Award for Best Rock Song. The song is known for its underlying riff, which plays throughout most of the song. Although it sounds like a bass guitar (an instrument the group had famously never previously used) <a href=\"http://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army\">Read more on Last.fm</a>.",
"content": "\"Seven Nation Army\" is the first track on the album Elephant by American alternative rock band The White Stripes. It was released as a single in 2003, and is one of the best-known songs from the band. Seven Nation Army reached #1 on the Modern Rock Tracks for three weeks and won 2004's Grammy Award for Best Rock Song. The song is known for its underlying riff, which plays throughout most of the song. Although it sounds like a bass guitar (an instrument the group had famously never previously used), the sound is actually created by running Jack White's semi-acoustic guitar (a 1950s style Kay Hollowbody) through a whammy pedal set down an octave. The riff was composed at a sound check before a show at the Corner Hotel in Melbourne, Australia, according to the set notes in the booklet which accompanied the Under Blackpool Lights DVD. The riff was inspired by the main theme of the Fifth Symphony composed by Anton Bruckner (https://www.youtube.com/watch?v=CgXBp-oEIR0&feature=youtu.be&t=21m29s).\n\nThe song shows a rare example of the Phrygian Half Cadence in popular music. It is also a rare example of a popular song with a wholly instrumental refrain.\n\nAccording to White, \"Seven Nation Army\" was what he used to call the Salvation Army as a child.\n\nIn March 2005, Q magazine placed \"Seven Nation Army\" at number 8 in its list of the 100 Greatest Guitar Tracks. In September 2005, NME placed \"Seven Nation Army\" at number 5 in its list of the 50 Greatest Tracks Of The Decade. In May 2008, Rolling Stone placed this song at number 21 in its list of the 100 Greatest Guitar Songs of All Time. \n\nA remix of the song was used in the trailer for Battlefield 1, which caused the song to spike up to the low 100's on Itunes charts. <a href=\"http://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army\">Read more on Last.fm</a>. User-contributed text is available under the Creative Commons By-SA License; additional terms may apply."
}
}
}
这给了我们 $.track.album.title
-> “大象”
现在将其用于 /album.search 端点以获取专辑信息。
我正在尝试使用 "Last.fm" APIs 获取一些给定歌曲名称的元数据。
这是我使用/track.search API. However, I am wondering how to get the album name of the song because to use /album.search时的示例结果 API我需要专辑名称。
感谢任何帮助或提示。谢谢。
{
"results": {
"opensearch:Query": {
"#text": "",
"role": "request",
"startPage": "1"
},
"opensearch:totalResults": "685711",
"opensearch:startIndex": "0",
"opensearch:itemsPerPage": "1",
"trackmatches": {
"track": [
{
"name": "Believer",
"artist": "Imagine Dragons",
"url": "https://www.last.fm/music/Imagine+Dragons/_/Believer",
"streamable": "FIXME",
"listeners": "359856",
"image": [
{
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "small"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "medium"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "large"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "extralarge"
}
],
"mbid": ""
}
]
},
"@attr": {}
}
}
基于 last.fm API 文档(截至 05/09/2020),/track.search response does not contain album information for each track listed in the search results response. You would need to extract name
and artist
information from your search results response and use /track.getInfo 获取相册信息的端点。响应中的相册名称是 album.title
。
例子
我正在使用 /track.search
搜索“seven nation army”{
"results": {
"opensearch:Query": {
"#text": "",
"role": "request",
"startPage": "1"
},
"opensearch:totalResults": "30560",
"opensearch:startIndex": "0",
"opensearch:itemsPerPage": "1",
"trackmatches": {
"track": [{
"name": "Seven Nation Army",
"artist": "The White Stripes",
"url": "https://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army",
"streamable": "FIXME",
"listeners": "1583146",
"image": [{
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "small"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "medium"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "large"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
"size": "extralarge"
}
],
"mbid": "24cc8311-98fd-423a-bed1-97728f5eabc5"
}]
},
"@attr": {}
}
}
我将从这个回复中提取:
$.results.trackmatches.track[:1].name
-> “七国军”
$.results.trackmatches.track[:1].artist
-> “白色条纹”
并用作 /track.getInfo
的输入{
"track": {
"name": "Seven Nation Army",
"mbid": "24cc8311-98fd-423a-bed1-97728f5eabc5",
"url": "https://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army",
"duration": "231000",
"streamable": {
"#text": "0",
"fulltrack": "0"
},
"listeners": "1583146",
"playcount": "12806149",
"artist": {
"name": "The White Stripes",
"mbid": "11ae9fbb-f3d7-4a47-936f-4c0a04d3b3b5",
"url": "https://www.last.fm/music/The+White+Stripes"
},
"album": {
"artist": "The White Stripes",
"title": "Elephant",
"mbid": "bb29bd28-71e7-32d3-ab5f-c2d33b25434a",
"url": "https://www.last.fm/music/The+White+Stripes/Elephant",
"image": [{
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "small"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "medium"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "large"
},
{
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/4834c1de5bae49f594bd2f2df1f16286.png",
"size": "extralarge"
}
],
"@attr": {
"position": "1"
}
},
"toptags": {
"tag": [{
"name": "rock",
"url": "https://www.last.fm/tag/rock"
},
{
"name": "alternative rock",
"url": "https://www.last.fm/tag/alternative+rock"
},
{
"name": "alternative",
"url": "https://www.last.fm/tag/alternative"
},
{
"name": "indie",
"url": "https://www.last.fm/tag/indie"
},
{
"name": "indie rock",
"url": "https://www.last.fm/tag/indie+rock"
}
]
},
"wiki": {
"published": "09 Aug 2008, 10:12",
"summary": "\"Seven Nation Army\" is the first track on the album Elephant by American alternative rock band The White Stripes. It was released as a single in 2003, and is one of the best-known songs from the band. Seven Nation Army reached #1 on the Modern Rock Tracks for three weeks and won 2004's Grammy Award for Best Rock Song. The song is known for its underlying riff, which plays throughout most of the song. Although it sounds like a bass guitar (an instrument the group had famously never previously used) <a href=\"http://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army\">Read more on Last.fm</a>.",
"content": "\"Seven Nation Army\" is the first track on the album Elephant by American alternative rock band The White Stripes. It was released as a single in 2003, and is one of the best-known songs from the band. Seven Nation Army reached #1 on the Modern Rock Tracks for three weeks and won 2004's Grammy Award for Best Rock Song. The song is known for its underlying riff, which plays throughout most of the song. Although it sounds like a bass guitar (an instrument the group had famously never previously used), the sound is actually created by running Jack White's semi-acoustic guitar (a 1950s style Kay Hollowbody) through a whammy pedal set down an octave. The riff was composed at a sound check before a show at the Corner Hotel in Melbourne, Australia, according to the set notes in the booklet which accompanied the Under Blackpool Lights DVD. The riff was inspired by the main theme of the Fifth Symphony composed by Anton Bruckner (https://www.youtube.com/watch?v=CgXBp-oEIR0&feature=youtu.be&t=21m29s).\n\nThe song shows a rare example of the Phrygian Half Cadence in popular music. It is also a rare example of a popular song with a wholly instrumental refrain.\n\nAccording to White, \"Seven Nation Army\" was what he used to call the Salvation Army as a child.\n\nIn March 2005, Q magazine placed \"Seven Nation Army\" at number 8 in its list of the 100 Greatest Guitar Tracks. In September 2005, NME placed \"Seven Nation Army\" at number 5 in its list of the 50 Greatest Tracks Of The Decade. In May 2008, Rolling Stone placed this song at number 21 in its list of the 100 Greatest Guitar Songs of All Time. \n\nA remix of the song was used in the trailer for Battlefield 1, which caused the song to spike up to the low 100's on Itunes charts. <a href=\"http://www.last.fm/music/The+White+Stripes/_/Seven+Nation+Army\">Read more on Last.fm</a>. User-contributed text is available under the Creative Commons By-SA License; additional terms may apply."
}
}
}
这给了我们 $.track.album.title
-> “大象”
现在将其用于 /album.search 端点以获取专辑信息。