diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index e01718f45d..6848921ea5 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -77,7 +77,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
{
var handler = new WebRequestHandler
{
- AutomaticDecompression = DecompressionMethods.Deflate,
+ //AutomaticDecompression = DecompressionMethods.Deflate,
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate)
};
diff --git a/MediaBrowser.Common/Kernel/ResourcePool.cs b/MediaBrowser.Common/Kernel/ResourcePool.cs
index 8a2ab8af8e..7a74c60a78 100644
--- a/MediaBrowser.Common/Kernel/ResourcePool.cs
+++ b/MediaBrowser.Common/Kernel/ResourcePool.cs
@@ -38,6 +38,11 @@ namespace MediaBrowser.Common.Kernel
///
public readonly SemaphoreSlim Mb = new SemaphoreSlim(5, 5);
+ ///
+ /// The mb
+ ///
+ public readonly SemaphoreSlim Lastfm = new SemaphoreSlim(5, 5);
+
///
/// Apple doesn't seem to like too many simulataneous requests.
///
diff --git a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
index 0819ea6ed8..5203b6f06b 100644
--- a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
+++ b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs
@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Logging;
+using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Controller.Providers.Music
@@ -18,9 +21,64 @@ namespace MediaBrowser.Controller.Providers.Music
{
}
- protected override Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken)
+ protected override async Task FindId(Entities.BaseItem item, System.Threading.CancellationToken cancellationToken)
{
- throw new NotImplementedException();
+ //Execute the Artist search against our name and assume first one is the one we want
+ var url = RootUrl + string.Format("method=artist.search&artist={0}&api_key={1}&format=json", UrlEncode(item.Name), ApiKey);
+
+ LastfmArtistSearchResults searchResult = null;
+
+ try
+ {
+ using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false))
+ {
+ searchResult = JsonSerializer.DeserializeFromStream(json);
+ }
+ }
+ catch (HttpException e)
+ {
+ if (e.StatusCode == HttpStatusCode.NotFound)
+ {
+ return null;
+ }
+ throw;
+ }
+
+ if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Any())
+ {
+ return searchResult.results.artistmatches.artist.First().mbid;
+ }
+
+ return null;
+ }
+
+ protected override async Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken)
+ {
+ // Get artist info with provided id
+ var url = RootUrl + string.Format("method=artist.getInfo&mbid={0}&api_key={1}&format=json", UrlEncode(id), ApiKey);
+
+ LastfmGetArtistResult result = null;
+
+ try
+ {
+ using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.Lastfm, cancellationToken).ConfigureAwait(false))
+ {
+ result = JsonSerializer.DeserializeFromStream(json);
+ }
+ }
+ catch (HttpException e)
+ {
+ if (e.StatusCode == HttpStatusCode.NotFound)
+ {
+ throw new LastfmProviderException(string.Format("Unable to retrieve artist info for {0} with id {0}", item.Name, id));
+ }
+ throw;
+ }
+
+ if (result != null && result.artist != null)
+ {
+ ProcessArtistData(item as MusicArtist, result.artist);
+ }
}
}
}
diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs
index 9e1ff21884..85f141a56f 100644
--- a/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs
+++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs
@@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Providers.Music
{
public abstract class LastfmBaseArtistProvider : LastfmBaseProvider
{
- protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager)
+ protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager)
: base(jsonSerializer, httpClient, logManager)
{
LocalMetaFileName = "MBArtist.json";
@@ -25,38 +25,17 @@ namespace MediaBrowser.Controller.Providers.Music
return item is MusicArtist;
}
- protected override async Task FindId(Entities.BaseItem item, System.Threading.CancellationToken cancellationToken)
+ protected void ProcessArtistData(MusicArtist artist, LastfmArtist data)
{
- //Execute the Artist search against our name and assume first one is the one we want
- var url = RootUrl + string.Format("method=artist.search&artist={0}&api_key={1}&format=json", UrlEncode(item.Name), ApiKey);
-
- LastfmArtistSearchResults searchResult = null;
-
- try
- {
- using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false))
- {
- searchResult = JsonSerializer.DeserializeFromStream(json);
- }
- }
- catch (HttpException e)
- {
- if (e.StatusCode == HttpStatusCode.NotFound)
- {
- return null;
- }
- throw;
- }
-
- if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Any())
+ artist.Overview = data.bio.summary;
+ foreach (var tag in data.tags.tag)
{
- return searchResult.results.artistmatches.artist.First().mbid;
+ artist.AddGenre(tag.name);
}
-
- return null;
}
}
+
#region Result Objects
public class LastfmStats
@@ -71,6 +50,11 @@ namespace MediaBrowser.Controller.Providers.Music
public string url { get; set; }
}
+ public class LastfmTags
+ {
+ public List tag { get; set; }
+ }
+
public class LastfmFormationInfo
{
public string yearfrom { get; set; }
@@ -96,7 +80,7 @@ namespace MediaBrowser.Controller.Providers.Music
public string ontour { get; set; }
public LastfmStats stats { get; set; }
public List similar { get; set; }
- public List tags { get; set; }
+ public LastfmTags tags { get; set; }
public LastFmBio bio { get; set; }
}
@@ -119,6 +103,5 @@ namespace MediaBrowser.Controller.Providers.Music
{
public LastfmArtistSearchResult results { get; set; }
}
-
#endregion
}