LastfmArtistByNameProvider.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using MediaBrowser.Common.Net;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Entities;
  4. using MediaBrowser.Controller.Entities.Audio;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Model.Logging;
  7. using MediaBrowser.Model.Serialization;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace MediaBrowser.Providers.Music
  11. {
  12. /// <summary>
  13. /// Class LastfmArtistByNameProvider
  14. /// </summary>
  15. public class LastfmArtistByNameProvider : LastfmArtistProvider
  16. {
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="LastfmArtistByNameProvider" /> class.
  19. /// </summary>
  20. /// <param name="jsonSerializer">The json serializer.</param>
  21. /// <param name="httpClient">The HTTP client.</param>
  22. /// <param name="logManager">The log manager.</param>
  23. /// <param name="configurationManager">The configuration manager.</param>
  24. /// <param name="libraryManager">The library manager.</param>
  25. public LastfmArtistByNameProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, ILibraryManager libraryManager)
  26. : base(jsonSerializer, httpClient, logManager, configurationManager, libraryManager)
  27. {
  28. }
  29. /// <summary>
  30. /// Gets a value indicating whether [save local meta].
  31. /// </summary>
  32. /// <value><c>true</c> if [save local meta]; otherwise, <c>false</c>.</value>
  33. protected override bool SaveLocalMeta
  34. {
  35. get
  36. {
  37. return true;
  38. }
  39. }
  40. /// <summary>
  41. /// Supportses the specified item.
  42. /// </summary>
  43. /// <param name="item">The item.</param>
  44. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  45. public override bool Supports(BaseItem item)
  46. {
  47. return item is Artist;
  48. }
  49. /// <summary>
  50. /// Gets the provider version.
  51. /// </summary>
  52. /// <value>The provider version.</value>
  53. protected override string ProviderVersion
  54. {
  55. get
  56. {
  57. return "7";
  58. }
  59. }
  60. /// <summary>
  61. /// Fetches the lastfm data.
  62. /// </summary>
  63. /// <param name="item">The item.</param>
  64. /// <param name="musicBrainzId">The music brainz id.</param>
  65. /// <param name="cancellationToken">The cancellation token.</param>
  66. /// <returns>Task.</returns>
  67. protected override async Task FetchLastfmData(BaseItem item, string musicBrainzId, bool force, CancellationToken cancellationToken)
  68. {
  69. var artist = (Artist)item;
  70. // See if we can avoid an http request by finding the matching MusicArtist entity
  71. var musicArtist = Artist.FindMusicArtist(artist, LibraryManager);
  72. if (musicArtist != null && !force)
  73. {
  74. LastfmHelper.ProcessArtistData(musicArtist, artist);
  75. }
  76. else
  77. {
  78. await base.FetchLastfmData(item, musicBrainzId, force, cancellationToken).ConfigureAwait(false);
  79. }
  80. }
  81. }
  82. }