LastfmBaseProvider.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using MediaBrowser.Common.Net;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Providers;
  4. using MediaBrowser.Model.Logging;
  5. using MediaBrowser.Model.Serialization;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Net;
  9. using System.Threading;
  10. namespace MediaBrowser.Providers.Music
  11. {
  12. /// <summary>
  13. /// Class MovieDbProvider
  14. /// </summary>
  15. public abstract class LastfmBaseProvider : BaseMetadataProvider
  16. {
  17. internal static readonly SemaphoreSlim LastfmResourcePool = new SemaphoreSlim(4, 4);
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="LastfmBaseProvider" /> class.
  20. /// </summary>
  21. /// <param name="jsonSerializer">The json serializer.</param>
  22. /// <param name="httpClient">The HTTP client.</param>
  23. /// <param name="logManager">The log manager.</param>
  24. /// <param name="configurationManager">The configuration manager.</param>
  25. /// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
  26. protected LastfmBaseProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
  27. : base(logManager, configurationManager)
  28. {
  29. if (jsonSerializer == null)
  30. {
  31. throw new ArgumentNullException("jsonSerializer");
  32. }
  33. if (httpClient == null)
  34. {
  35. throw new ArgumentNullException("httpClient");
  36. }
  37. JsonSerializer = jsonSerializer;
  38. HttpClient = httpClient;
  39. }
  40. protected override string ProviderVersion
  41. {
  42. get
  43. {
  44. return "8";
  45. }
  46. }
  47. protected override bool RefreshOnVersionChange
  48. {
  49. get
  50. {
  51. return true;
  52. }
  53. }
  54. /// <summary>
  55. /// Gets the json serializer.
  56. /// </summary>
  57. /// <value>The json serializer.</value>
  58. protected IJsonSerializer JsonSerializer { get; private set; }
  59. /// <summary>
  60. /// Gets the HTTP client.
  61. /// </summary>
  62. /// <value>The HTTP client.</value>
  63. protected IHttpClient HttpClient { get; private set; }
  64. protected virtual bool SaveLocalMeta
  65. {
  66. get
  67. {
  68. return ConfigurationManager.Configuration.SaveLocalMeta;
  69. }
  70. }
  71. /// <summary>
  72. /// Gets a value indicating whether [requires internet].
  73. /// </summary>
  74. /// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
  75. public override bool RequiresInternet
  76. {
  77. get
  78. {
  79. return true;
  80. }
  81. }
  82. protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/?";
  83. protected static string ApiKey = "7b76553c3eb1d341d642755aecc40a33";
  84. /// <summary>
  85. /// Encodes an URL.
  86. /// </summary>
  87. /// <param name="name">The name.</param>
  88. /// <returns>System.String.</returns>
  89. protected static string UrlEncode(string name)
  90. {
  91. return WebUtility.UrlEncode(name);
  92. }
  93. }
  94. #region Result Objects
  95. public class LastfmStats
  96. {
  97. public string listeners { get; set; }
  98. public string playcount { get; set; }
  99. }
  100. public class LastfmTag
  101. {
  102. public string name { get; set; }
  103. public string url { get; set; }
  104. }
  105. public class LastfmTags
  106. {
  107. public List<LastfmTag> tag { get; set; }
  108. }
  109. public class LastfmFormationInfo
  110. {
  111. public string yearfrom { get; set; }
  112. public string yearto { get; set; }
  113. }
  114. public class LastFmBio
  115. {
  116. public string published { get; set; }
  117. public string summary { get; set; }
  118. public string content { get; set; }
  119. public string placeformed { get; set; }
  120. public string yearformed { get; set; }
  121. public List<LastfmFormationInfo> formationlist { get; set; }
  122. }
  123. public class LastFmImage
  124. {
  125. public string url { get; set; }
  126. public string size { get; set; }
  127. }
  128. public class LastfmArtist : IHasLastFmImages
  129. {
  130. public string name { get; set; }
  131. public string mbid { get; set; }
  132. public string url { get; set; }
  133. public string streamable { get; set; }
  134. public string ontour { get; set; }
  135. public LastfmStats stats { get; set; }
  136. public List<LastfmArtist> similar { get; set; }
  137. public LastfmTags tags { get; set; }
  138. public LastFmBio bio { get; set; }
  139. public List<LastFmImage> image { get; set; }
  140. }
  141. public class LastfmAlbum : IHasLastFmImages
  142. {
  143. public string name { get; set; }
  144. public string artist { get; set; }
  145. public string id { get; set; }
  146. public string mbid { get; set; }
  147. public string releasedate { get; set; }
  148. public int listeners { get; set; }
  149. public int playcount { get; set; }
  150. public LastfmTags toptags { get; set; }
  151. public LastFmBio wiki { get; set; }
  152. public List<LastFmImage> image { get; set; }
  153. }
  154. public interface IHasLastFmImages
  155. {
  156. List<LastFmImage> image { get; set; }
  157. }
  158. public class LastfmGetAlbumResult
  159. {
  160. public LastfmAlbum album { get; set; }
  161. }
  162. public class LastfmGetArtistResult
  163. {
  164. public LastfmArtist artist { get; set; }
  165. }
  166. public class Artistmatches
  167. {
  168. public List<LastfmArtist> artist { get; set; }
  169. }
  170. public class LastfmArtistSearchResult
  171. {
  172. public Artistmatches artistmatches { get; set; }
  173. }
  174. public class LastfmArtistSearchResults
  175. {
  176. public LastfmArtistSearchResult results { get; set; }
  177. }
  178. #endregion
  179. }