PureScrobbler track search problem


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. if (trackName != null && artistName != null)
  2. {
  3. //Get track info
  4.  
  5. LastFmLib.API20.Types.Track suspect = new LastFmLib.API20.Types.Track();
  6. //LastFmLib.API20.Types.ArtistInfo suspectArtist = new LastFmLib.API20.Types.ArtistInfo();
  7. //suspectArtist.Name = "something";
  8. suspect.Artist = new LastFmLib.API20.Types.ArtistInfo(suspect.Artist.Name = artistName);
  9. suspect.Title = trackName;
  10. try
  11. {
  12.  
  13. LastFmLib.API20.Tracks.TrackSearch detective = new LastFmLib.API20.Tracks.TrackSearch(suspect);
  14. //detective.Limit = 1;
  15.  
  16. detective.Start();
  17. if (detective.succeeded)
  18. {
  19. //for now just list the results
  20. foreach (LastFmLib.API20.Types.Track sparkle in detective.Result.Tracks)
  21. {
  22. Console.WriteLine();
  23. Console.WriteLine("And the result is: A: " + sparkle.ArtistName + " T: " + sparkle.Title + " L: " + sparkle.NumListeners);
  24. Console.WriteLine();
  25. }
  26. }
  27. }
  28. catch (Exception e)
  29. {
  30. Console.ForegroundColor = ConsoleColor.Red;
  31. Console.WriteLine();
  32. Console.WriteLine("Error: {0}", e.ToString());
  33. Console.WriteLine();
  34. Console.ForegroundColor = ConsoleColor.White;
  35. }
  36.  
  37. Console.WriteLine("Something good should happen here");
  38. Console.WriteLine("Artist: " + artistName + " Track: " + trackName);
  39. }
  40. else
  41. {
  42. //Give error
  43. Console.ForegroundColor = ConsoleColor.Red;
  44. Console.WriteLine(">< Error: Not enough track data was provided ><");
  45. Console.ForegroundColor = ConsoleColor.White;
  46. if (debug)
  47. {
  48. Console.ForegroundColor = ConsoleColor.Yellow;
  49. Console.WriteLine("The track name or artist name were missing.");
  50. Console.WriteLine("Please check the output of the XML.");
  51. Console.ForegroundColor = ConsoleColor.White;
  52. }
  53. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.