AudioImageProvider.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using MediaBrowser.Controller.Configuration;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Entities.Audio;
  4. using MediaBrowser.Model.Entities;
  5. using MediaBrowser.Model.Logging;
  6. using System;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace MediaBrowser.Controller.Providers.MediaInfo
  10. {
  11. /// <summary>
  12. /// Uses ffmpeg to create video images
  13. /// </summary>
  14. public class AudioImageProvider : BaseMetadataProvider
  15. {
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="BaseMetadataProvider" /> class.
  18. /// </summary>
  19. /// <param name="logManager">The log manager.</param>
  20. /// <param name="configurationManager">The configuration manager.</param>
  21. public AudioImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
  22. : base(logManager, configurationManager)
  23. {
  24. }
  25. /// <summary>
  26. /// Supportses the specified item.
  27. /// </summary>
  28. /// <param name="item">The item.</param>
  29. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  30. public override bool Supports(BaseItem item)
  31. {
  32. return item.LocationType == LocationType.FileSystem && item is Audio;
  33. }
  34. /// <summary>
  35. /// Override this to return the date that should be compared to the last refresh date
  36. /// to determine if this provider should be re-fetched.
  37. /// </summary>
  38. /// <param name="item">The item.</param>
  39. /// <returns>DateTime.</returns>
  40. protected override DateTime CompareDate(BaseItem item)
  41. {
  42. return item.DateModified;
  43. }
  44. /// <summary>
  45. /// Gets the priority.
  46. /// </summary>
  47. /// <value>The priority.</value>
  48. public override MetadataProviderPriority Priority
  49. {
  50. get { return MetadataProviderPriority.Last; }
  51. }
  52. /// <summary>
  53. /// Needses the refresh internal.
  54. /// </summary>
  55. /// <param name="item">The item.</param>
  56. /// <param name="providerInfo">The provider info.</param>
  57. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  58. protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
  59. {
  60. if (!string.IsNullOrEmpty(item.PrimaryImagePath))
  61. {
  62. return false;
  63. }
  64. return base.NeedsRefreshInternal(item, providerInfo);
  65. }
  66. /// <summary>
  67. /// Fetches metadata and returns true or false indicating if any work that requires persistence was done
  68. /// </summary>
  69. /// <param name="item">The item.</param>
  70. /// <param name="force">if set to <c>true</c> [force].</param>
  71. /// <param name="cancellationToken">The cancellation token.</param>
  72. /// <returns>Task{System.Boolean}.</returns>
  73. public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
  74. {
  75. if (force || string.IsNullOrEmpty(item.PrimaryImagePath))
  76. {
  77. var album = item.ResolveArgs.Parent as MusicAlbum;
  78. if (album != null)
  79. {
  80. // First try to use the parent's image
  81. item.PrimaryImagePath = item.ResolveArgs.Parent.PrimaryImagePath;
  82. }
  83. }
  84. SetLastRefreshed(item, DateTime.UtcNow);
  85. return TrueTaskResult;
  86. }
  87. }
  88. }