LastfmHelper.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Controller.Entities;
  7. using MediaBrowser.Model.Entities;
  8. namespace MediaBrowser.Controller.Providers.Music
  9. {
  10. public static class LastfmHelper
  11. {
  12. public static string LocalArtistMetaFileName = "MBArtist.json";
  13. public static string LocalAlbumMetaFileName = "MBAlbum.json";
  14. public static void ProcessArtistData(BaseItem artist, LastfmArtist data)
  15. {
  16. artist.Overview = data.bio != null ? data.bio.content : null;
  17. var yearFormed = 0;
  18. try
  19. {
  20. yearFormed = Convert.ToInt32(data.bio.yearformed);
  21. }
  22. catch (FormatException)
  23. {
  24. }
  25. catch (NullReferenceException)
  26. {
  27. }
  28. catch (OverflowException)
  29. {
  30. }
  31. artist.PremiereDate = new DateTime(yearFormed, 1,1);
  32. if (data.tags != null)
  33. {
  34. AddGenres(artist, data.tags);
  35. }
  36. }
  37. public static void ProcessAlbumData(BaseItem item, LastfmAlbum data)
  38. {
  39. if (!string.IsNullOrWhiteSpace(data.mbid)) item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
  40. item.Overview = data.wiki != null ? data.wiki.content : null;
  41. var release = DateTime.MinValue;
  42. DateTime.TryParse(data.releasedate, out release);
  43. item.PremiereDate = release;
  44. if (data.toptags != null)
  45. {
  46. AddGenres(item, data.toptags);
  47. }
  48. }
  49. private static void AddGenres(BaseItem item, LastfmTags tags)
  50. {
  51. foreach (var tag in tags.tag)
  52. {
  53. item.AddGenre(tag.name);
  54. }
  55. }
  56. }
  57. }