It is currently April 27th, 2024, 6:29 am

Using Last.FM API to get information for NowPlaying plugin

Report bugs with the Rainmeter application and suggest features.
red_sky
Posts: 1
Joined: June 15th, 2012, 12:28 pm

Using Last.FM API to get information for NowPlaying plugin

Post by red_sky »

Hello there, devs.

I briefly spoke to Poiru about a method of getting Album artwork for Spotify without being able to get it directly from the application itself.

I was tinkering with some Snarl (Growl for Windows) integration into Spotify, I realized that the Last.FM API provides a number of details about a song and requires only the artist and track title to get additional information about the song.

Of course, you would need an API key, but they are freely available.

The information you could easily get from this includes album artwork, song duration, genres, as well as how many people have listened to it on Last.FM and how many total listens it has on Last.FM.

While my specialties lie mostly with C# and not C++, it's extremely easy to parse what data you want (I'm aware that C++ would take more work, but I'm not sure how much).

For example, here's a C# snippet that will get the URL of album artwork:

Code: Select all

string path = "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=[api key]&artist=[artist]&track=[track]";

XPathDocument doc = new XPathDocument(path);
XPathNavigator navigator = doc.CreateNavigator();
XPathNodeIterator nodeIterator = navigator.Select("/lfm/track/album/image");
XPathNavigator node = nodeIterator.Current;
string imgUrl = node.InnerXml;
I've removed error handling for the sake of example, but it's not too difficult.

I'm just trying to think of ways to help you guys improve your already awesome software! Thanks for all the hard work.