1

I am having trouble retrieving artist's album data from last.fm api. I am using lastfm-sharp library.

I want to show artist's all albums with their release date, genre and album art. But when I try to get release date I get exception thrown. textbox1.text is artist name.

here is my code :

Session session = new Session("API_KEY", "SECRET");
session.Authenticate("USERNAME", Lastfm.Utilities.md5("PASSWORD"));

Artist artist = new Artist(textBox1.Text, session);
Lastfm.Services.Album artalbum = new Lastfm.Services.Album(textBox1.Text, "", session);

dataGridView1.Columns.Add("artistname", "artistname");
dataGridView1.Columns.Add("albumname", "albumname");
dataGridView1.Columns.Add("releasedate", "releasedate");

foreach (var s in artist.GetTopAlbums())
  dataGridView1.Rows.Add(s.Item.Artist,s.Item.Name,s.Item.GetReleaseDate());

ERROR :String was not recognized as a valid DateTime. I couldn't find any detail tutorial about using Last.fm api with c#.

Malav Shah
  • 143
  • 2
  • 16
  • 1
    Are you sure the error is thrown on the artist name? Sounds more like you expected releasedate to be a DateTime; it probably is a string.. – TaW Aug 14 '14 at 04:04
  • error is thrown at releasedate. but I am not sure how to resolve the issue. I tried releasedate().ToString() – Malav Shah Aug 14 '14 at 04:13
  • @MalavShah Use : Releasedate().ToString("dd-MM-yyyy"); – Thirisangu Ramanathan Aug 14 '14 at 04:17
  • @Thirisangu I tried using date format but didn't work. I also tried `s.Item.GetReleaseDate().ToShortDateString()` – Malav Shah Aug 14 '14 at 04:23
  • @MalavShah Try this : DateTime.ParseExact(s.Item.GetReleaseDate.ToString(),"dd-MM-yyyy",CultureInfo.InvariantCulture); – Thirisangu Ramanathan Aug 14 '14 at 04:28
  • Actually it should be `DateTime` - according to the sources in _lastfm-sharp-0.1.10.tar.gz_. Could it be null for your test case? Or maybe it is an issue with the lib not being uptodate?? – TaW Aug 14 '14 at 04:29
  • [This](http://www.lastfm.ru/api/show/artist.getTopAlbums) is an API reference for artist.getTopAlbums. And it based on sample response it doesn't return ReleaseDate. So there is another service call. And I see an [open issue](https://code.google.com/p/lastfm-sharp/issues/detail?id=7) on lastfm-sharp bug tracker. So probably it's a source of the exception. – Ivan Zub Aug 14 '14 at 04:32
  • @Thirisangu no luck with DateTime.ParseExact too. – Malav Shah Aug 14 '14 at 04:38
  • @TaW the lib I am using is up to date. I tried using DateTime too but didn't work and its not null for my test case as I tried many test cases. – Malav Shah Aug 14 '14 at 04:41
  • @MalavShah It may be NULL for that case., Try with some other Arist and Check whether ReleasedDate is NULL or not before convertion., – Thirisangu Ramanathan Aug 14 '14 at 04:42
  • @TaW Sorry for my incorrect comment. you may be right as commented by Ivan Zub even though thier is a function for getreleasedate it returns null. – Malav Shah Aug 14 '14 at 04:45
  • @IvanZub can you please guide me to right direction on how I can retrieve each album's releasedate and display it in my datagrid? – Malav Shah Aug 14 '14 at 04:47
  • @MalavShah it looks like that the library that you are using is no longer supported from 2010. But if you have to use it you can just put the call to GetReleaseDate into try/catch block. But I think you shouldn't use that library and check for another .NET project at http://www.lastfm.ru/api/downloads – Ivan Zub Aug 14 '14 at 05:15
  • @IvanZub thank you for your suggestion. I am not bound to use this library nor I am bound to use lastfm. I am open to use any api which can help me retrieve artist's all albums, release date and coverart. If you have any information regarding any other api which can help me get the information please share. I have tried to use gracenote api but couldn't find tutorials on it. – Malav Shah Aug 15 '14 at 00:47

0 Answers0