2013-04-22 04:38:03 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-06-09 16:47:28 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-03-03 17:07:13 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-04-22 04:38:03 +00:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-03-03 17:07:13 +00:00
|
|
|
|
using System;
|
2013-04-22 04:38:03 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net;
|
2013-03-03 17:07:13 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
2013-06-09 16:47:28 +00:00
|
|
|
|
namespace MediaBrowser.Providers.Music
|
2013-03-03 17:07:13 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MovieDbProvider
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class LastfmBaseProvider : BaseMetadataProvider
|
|
|
|
|
{
|
2013-09-06 15:23:20 +00:00
|
|
|
|
internal static readonly SemaphoreSlim LastfmResourcePool = new SemaphoreSlim(4, 4);
|
2013-03-04 15:33:54 +00:00
|
|
|
|
|
2013-03-03 17:07:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="LastfmBaseProvider" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="jsonSerializer">The json serializer.</param>
|
|
|
|
|
/// <param name="httpClient">The HTTP client.</param>
|
2013-03-04 05:43:06 +00:00
|
|
|
|
/// <param name="logManager">The log manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
2013-03-03 17:07:13 +00:00
|
|
|
|
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
|
2013-03-04 05:43:06 +00:00
|
|
|
|
protected LastfmBaseProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
|
|
|
|
|
: base(logManager, configurationManager)
|
2013-03-03 17:07:13 +00:00
|
|
|
|
{
|
|
|
|
|
if (jsonSerializer == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("jsonSerializer");
|
|
|
|
|
}
|
|
|
|
|
if (httpClient == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("httpClient");
|
|
|
|
|
}
|
|
|
|
|
JsonSerializer = jsonSerializer;
|
|
|
|
|
HttpClient = httpClient;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 14:09:29 +00:00
|
|
|
|
protected override string ProviderVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-09-06 17:26:56 +00:00
|
|
|
|
return "8";
|
2013-03-12 14:09:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool RefreshOnVersionChange
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the json serializer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The json serializer.</value>
|
|
|
|
|
protected IJsonSerializer JsonSerializer { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the HTTP client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The HTTP client.</value>
|
|
|
|
|
protected IHttpClient HttpClient { get; private set; }
|
|
|
|
|
|
2013-04-22 04:38:03 +00:00
|
|
|
|
protected virtual bool SaveLocalMeta
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ConfigurationManager.Configuration.SaveLocalMeta;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-03 17:07:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [requires internet].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public override bool RequiresInternet
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/?";
|
|
|
|
|
protected static string ApiKey = "7b76553c3eb1d341d642755aecc40a33";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Encodes an URL.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
protected static string UrlEncode(string name)
|
|
|
|
|
{
|
|
|
|
|
return WebUtility.UrlEncode(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-03 17:07:13 +00:00
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
#region Result Objects
|
2013-03-03 17:07:13 +00:00
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
public class LastfmStats
|
|
|
|
|
{
|
|
|
|
|
public string listeners { get; set; }
|
|
|
|
|
public string playcount { get; set; }
|
|
|
|
|
}
|
2013-03-03 20:55:30 +00:00
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
public class LastfmTag
|
|
|
|
|
{
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
public string url { get; set; }
|
|
|
|
|
}
|
2013-03-03 20:55:30 +00:00
|
|
|
|
|
2013-03-04 14:34:00 +00:00
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
public class LastfmTags
|
|
|
|
|
{
|
|
|
|
|
public List<LastfmTag> tag { get; set; }
|
|
|
|
|
}
|
2013-03-03 20:55:30 +00:00
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
public class LastfmFormationInfo
|
|
|
|
|
{
|
|
|
|
|
public string yearfrom { get; set; }
|
|
|
|
|
public string yearto { get; set; }
|
|
|
|
|
}
|
2013-03-03 20:55:30 +00:00
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
public class LastFmBio
|
|
|
|
|
{
|
|
|
|
|
public string published { get; set; }
|
|
|
|
|
public string summary { get; set; }
|
|
|
|
|
public string content { get; set; }
|
|
|
|
|
public string placeformed { get; set; }
|
|
|
|
|
public string yearformed { get; set; }
|
|
|
|
|
public List<LastfmFormationInfo> formationlist { get; set; }
|
|
|
|
|
}
|
2013-03-03 17:07:13 +00:00
|
|
|
|
|
2013-09-06 15:23:20 +00:00
|
|
|
|
public class LastFmImage
|
|
|
|
|
{
|
|
|
|
|
public string url { get; set; }
|
|
|
|
|
public string size { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 15:38:22 +00:00
|
|
|
|
public class LastfmArtist : IHasLastFmImages
|
2013-03-04 20:03:36 +00:00
|
|
|
|
{
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
public string mbid { get; set; }
|
|
|
|
|
public string url { get; set; }
|
|
|
|
|
public string streamable { get; set; }
|
|
|
|
|
public string ontour { get; set; }
|
|
|
|
|
public LastfmStats stats { get; set; }
|
|
|
|
|
public List<LastfmArtist> similar { get; set; }
|
|
|
|
|
public LastfmTags tags { get; set; }
|
|
|
|
|
public LastFmBio bio { get; set; }
|
2013-09-06 15:23:20 +00:00
|
|
|
|
public List<LastFmImage> image { get; set; }
|
2013-03-04 20:03:36 +00:00
|
|
|
|
}
|
2013-03-03 17:07:13 +00:00
|
|
|
|
|
2013-03-05 16:48:17 +00:00
|
|
|
|
|
2013-09-06 15:38:22 +00:00
|
|
|
|
public class LastfmAlbum : IHasLastFmImages
|
2013-03-05 16:48:17 +00:00
|
|
|
|
{
|
|
|
|
|
public string name { get; set; }
|
|
|
|
|
public string artist { get; set; }
|
|
|
|
|
public string id { get; set; }
|
|
|
|
|
public string mbid { get; set; }
|
|
|
|
|
public string releasedate { get; set; }
|
|
|
|
|
public int listeners { get; set; }
|
|
|
|
|
public int playcount { get; set; }
|
|
|
|
|
public LastfmTags toptags { get; set; }
|
|
|
|
|
public LastFmBio wiki { get; set; }
|
2013-09-06 15:38:22 +00:00
|
|
|
|
public List<LastFmImage> image { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IHasLastFmImages
|
|
|
|
|
{
|
|
|
|
|
List<LastFmImage> image { get; set; }
|
2013-03-05 16:48:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LastfmGetAlbumResult
|
|
|
|
|
{
|
|
|
|
|
public LastfmAlbum album { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 20:03:36 +00:00
|
|
|
|
public class LastfmGetArtistResult
|
|
|
|
|
{
|
|
|
|
|
public LastfmArtist artist { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Artistmatches
|
|
|
|
|
{
|
|
|
|
|
public List<LastfmArtist> artist { get; set; }
|
2013-03-03 17:07:13 +00:00
|
|
|
|
}
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
|
|
|
|
public class LastfmArtistSearchResult
|
|
|
|
|
{
|
|
|
|
|
public Artistmatches artistmatches { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LastfmArtistSearchResults
|
|
|
|
|
{
|
|
|
|
|
public LastfmArtistSearchResult results { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-03-03 17:07:13 +00:00
|
|
|
|
}
|