I am trying to use "Last.fm" APIs to get some metadata given song name.
This is a sample result when I use /track.search API. However, I am wondering how to get the album name of the song because to use /album.search API I need album name.
I appreciate any help or hint. Thanks.
{
"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": {}
}
}
Based on last.fm API documentation (as of 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 endpoint to get album information. Album name is album.title
in the response.
I am searching for "seven nation army" using /track.search
{
"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": {}
}
}
From this response I will extract:
$.results.trackmatches.track[:1].name
-> "Seven Nation Army"
$.results.trackmatches.track[:1].artist
-> "The White Stripes"
and use as input for /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."
}
}
}
This gives us $.track.album.title
-> "Elephant"
Now use that for /album.search endpoint to get album information.