FanartBaseProvider.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System.Threading;
  2. using MediaBrowser.Controller.Configuration;
  3. using System.Collections.Generic;
  4. using MediaBrowser.Controller.Entities;
  5. using System;
  6. using MediaBrowser.Model.Logging;
  7. namespace MediaBrowser.Controller.Providers
  8. {
  9. class FanArtProviderException : ApplicationException
  10. {
  11. public FanArtProviderException(string msg)
  12. : base(msg)
  13. {
  14. }
  15. }
  16. /// <summary>
  17. /// Class FanartBaseProvider
  18. /// </summary>
  19. public abstract class FanartBaseProvider : BaseMetadataProvider
  20. {
  21. protected static readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(5,5);
  22. /// <summary>
  23. /// The LOG o_ FILE
  24. /// </summary>
  25. protected const string LOGO_FILE = "logo.png";
  26. /// <summary>
  27. /// The AR t_ FILE
  28. /// </summary>
  29. protected const string ART_FILE = "clearart.png";
  30. /// <summary>
  31. /// The THUM b_ FILE
  32. /// </summary>
  33. protected const string THUMB_FILE = "thumb.jpg";
  34. /// <summary>
  35. /// The DIS c_ FILE
  36. /// </summary>
  37. protected const string DISC_FILE = "disc.png";
  38. /// <summary>
  39. /// The BANNE r_ FILE
  40. /// </summary>
  41. protected const string BANNER_FILE = "banner.png";
  42. /// <summary>
  43. /// The Backdrop
  44. /// </summary>
  45. protected const string BACKDROP_FILE = "backdrop.jpg";
  46. /// <summary>
  47. /// The Primary image
  48. /// </summary>
  49. protected const string PRIMARY_FILE = "folder.jpg";
  50. /// <summary>
  51. /// The API key
  52. /// </summary>
  53. protected const string APIKey = "5c6b04c68e904cfed1e6cbc9a9e683d4";
  54. protected FanartBaseProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager)
  55. {
  56. }
  57. /// <summary>
  58. /// Needses the refresh internal.
  59. /// </summary>
  60. /// <param name="item">The item.</param>
  61. /// <param name="providerInfo">The provider info.</param>
  62. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  63. protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
  64. {
  65. if (item.DontFetchMeta) return false;
  66. return DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays))
  67. && ShouldFetch(item, providerInfo);
  68. }
  69. /// <summary>
  70. /// Gets a value indicating whether [requires internet].
  71. /// </summary>
  72. /// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
  73. public override bool RequiresInternet
  74. {
  75. get { return true; }
  76. }
  77. /// <summary>
  78. /// Gets the priority.
  79. /// </summary>
  80. /// <value>The priority.</value>
  81. public override MetadataProviderPriority Priority
  82. {
  83. get { return MetadataProviderPriority.Third; }
  84. }
  85. /// <summary>
  86. /// Shoulds the fetch.
  87. /// </summary>
  88. /// <param name="item">The item.</param>
  89. /// <param name="providerInfo">The provider info.</param>
  90. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  91. protected virtual bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
  92. {
  93. return false;
  94. }
  95. #region Result Objects
  96. protected class FanArtImageInfo
  97. {
  98. public string id { get; set; }
  99. public string url { get; set; }
  100. public string likes { get; set; }
  101. }
  102. protected class FanArtMusicInfo
  103. {
  104. public string mbid_id { get; set; }
  105. public List<FanArtImageInfo> musiclogo { get; set; }
  106. public List<FanArtImageInfo> artistbackground { get; set; }
  107. public List<FanArtImageInfo> artistthumb { get; set; }
  108. public List<FanArtImageInfo> hdmusiclogo { get; set; }
  109. public List<FanArtImageInfo> musicbanner { get; set; }
  110. }
  111. protected class FanArtMusicResult
  112. {
  113. public FanArtMusicInfo result { get; set; }
  114. }
  115. #endregion
  116. }
  117. }