Closed veso266 closed 6 years ago
Content can be multiple LastTracks, therefore you have to iterate it to get single LastTracks
Hi @veso266
What you want to do is call the track.getInfo
API, like so
LastfmClient client = new LastfmClient("MY_API_KEY", "MY_API_SECRET");
LastResponse<LastTrack> track = await client.Track.GetInfoAsync("Believe", "Cher");
What your code is actually doing is calling the track.search
API (I've added the types to make things clear)
LastfmClient client = new LastfmClient("MY_API_KEY", "MY_API_SECRET");
PageResponse<LastTrack> track = await client.Track.SearchAsync("Believe", page: 5, itemsPerPage: 100);
IReadOnlyList<LastTrack> searchResults = response.Content;
Let me know if that helps. Cheers
Thanks for anwsering almost there
using IF.Lastfm;
using IF.Lastfm.Core;
using IF.Lastfm.Core.Api;
using IF.Lastfm.Core.Json;
using IF.Lastfm.Core.Helpers;
using IF.Lastfm.Core.Objects;
using IF.Lastfm.Core.Scrobblers;
public static async void lastFM (string title)
{
var client = new LastfmClient("MY_API_KEY", "MY_API_SECRET");
LastResponse<LastTrack> track = await client.Track.GetInfoAsync("Believe", "Cher");
IReadOnlyList<LastTrack> searchResults = track.Content;
}
CS0246 The type or namespace name 'LastResponse<LastTrack>' could not be found (are you missing a using directive or an assembly reference?)
not sure why LastResponse doesn't exist
You also need
using IF.Lastfm.Core.Api.Helpers;
Your code won't compile btw - track.Content
won't be IReadOnlyList<LastTrack>
, because you're calling the GetInfoAsync
which returns a LastResponsetrack.Content
will be a LastTrack
.
oops forget that I also needed that one (didn't knew existed :smiley: )
var client = new LastfmClient("apikey" "secret");
PageResponse<LastTrack> track = await client.Track.SearchAsync("Skyfall", page: 1, itemsPerPage: 10);
IReadOnlyList<LastTrack> searchResults = track.Content;
var ArtistName = searchResults[0].ArtistName;
works like it should now, but it is a bit slow (do you know if its possible to make it faster?) Thanks
Hi @veso266 from the code you've given me I can't immediately see any performance problems. I'd use a tool like Fiddler to check exactly how much time is spent waiting for the Last.fm API vs how long is spent in your code.
PS - you posted your api key and api secret in your comment - you should avoid posting these online.
Ta
Hi I was trying your wrapper and it works realy well but now I am trying to get an info about a track name in the lastFM api you would use track.getinfo https://www.last.fm/api/show/track.getInfo
but not sure how would I do that in your wrapper I tried to get an Artist name for title Believe
but it complains
Hopefully you can help me a bit with this
Thanks for Anwsering and Best Regards