From 014a66a8bd71dd5a5c7daa39e5b75786f4923b01 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Sun, 3 Mar 2013 15:55:02 -0500 Subject: [PATCH 1/4] Fix library explorer --- MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs index 2c07effde..ef4b8f162 100644 --- a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs +++ b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs @@ -44,6 +44,7 @@ namespace MediaBrowser.ServerApplication { _logger = logger; _jsonSerializer = jsonSerializer; + _libraryManager = libraryManager; InitializeComponent(); lblVersion.Content = "Version: " + appHost.ApplicationVersion; @@ -53,7 +54,6 @@ namespace MediaBrowser.ServerApplication ddlProfile.SelectedIndex = 0; ddlIndexBy.Visibility = ddlSortBy.Visibility = lblIndexBy.Visibility = lblSortBy.Visibility = Visibility.Hidden; - _libraryManager = libraryManager; } /// From de878025e61225bc0f66c3a06728c8ae01bb912c Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Sun, 3 Mar 2013 15:55:30 -0500 Subject: [PATCH 2/4] Incremental LastfmArtistProvider --- .../MediaBrowser.Controller.csproj | 2 + .../Providers/Music/LastfmArtistProvider.cs | 26 ++++ .../Music/LastfmBaseArtistProvider.cs | 124 ++++++++++++++++++ .../Providers/Music/LastfmBaseProvider.cs | 24 +++- 4 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs create mode 100644 MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 319289f94..b0044745c 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -110,6 +110,8 @@ + + diff --git a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs new file mode 100644 index 000000000..0819ea6ed --- /dev/null +++ b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Controller.Providers.Music +{ + public class LastfmArtistProvider : LastfmBaseArtistProvider + { + public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) + : base(jsonSerializer, httpClient, logManager) + { + } + + protected override Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + } +} diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs new file mode 100644 index 000000000..9e1ff2188 --- /dev/null +++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Net; +using MediaBrowser.Model.Serialization; + +namespace MediaBrowser.Controller.Providers.Music +{ + public abstract class LastfmBaseArtistProvider : LastfmBaseProvider + { + protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) + : base(jsonSerializer, httpClient, logManager) + { + LocalMetaFileName = "MBArtist.json"; + } + + public override bool Supports(Entities.BaseItem item) + { + return item is MusicArtist; + } + + protected override async Task FindId(Entities.BaseItem item, System.Threading.CancellationToken cancellationToken) + { + //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; + } + } + + #region Result Objects + + public class LastfmStats + { + public string listeners { get; set; } + public string playcount { get; set; } + } + + public class LastfmTag + { + public string name { get; set; } + public string url { get; set; } + } + + public class LastfmFormationInfo + { + public string yearfrom { get; set; } + public string yearto { get; set; } + } + + 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 formationlist { get; set; } + } + + public class LastfmArtist + { + 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 similar { get; set; } + public List tags { get; set; } + public LastFmBio bio { get; set; } + } + + public class LastfmGetArtistResult + { + public LastfmArtist artist { get; set; } + } + + public class Artistmatches + { + public List artist { get; set; } + } + + public class LastfmArtistSearchResult + { + public Artistmatches artistmatches { get; set; } + } + + public class LastfmArtistSearchResults + { + public LastfmArtistSearchResult results { get; set; } + } + + #endregion +} diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs index 364986130..54792932e 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs @@ -94,7 +94,7 @@ namespace MediaBrowser.Controller.Providers.Music } } - protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/"; + protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/?"; protected static string ApiKey = "7b76553c3eb1d341d642755aecc40a33"; protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) @@ -186,7 +186,27 @@ namespace MediaBrowser.Controller.Providers.Music /// The item. /// /// Task. - protected abstract Task FetchData(BaseItem item, CancellationToken cancellationToken); + protected async Task FetchData(BaseItem item, CancellationToken cancellationToken) + { + var id = item.GetProviderId(MetadataProviders.Musicbrainz) ?? await FindId(item, cancellationToken).ConfigureAwait(false); + if (id != null) + { + Logger.Debug("LastfmProvider - getting info with id: " + id); + + cancellationToken.ThrowIfCancellationRequested(); + + await FetchLastfmData(item, id, cancellationToken).ConfigureAwait(false); + } + else + { + Logger.Info("LastfmProvider could not find " + item.Name + ". Check name on Last.fm."); + } + + } + + protected abstract Task FindId(BaseItem item, CancellationToken cancellationToken); + + protected abstract Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken); /// /// Encodes an URL. From d7cdf0632636e0aef3b27fa457d0d21a5d19ec37 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Sun, 3 Mar 2013 20:46:06 -0500 Subject: [PATCH 3/4] First cut at LastfmArtistProvider --- .../HttpClientManager/HttpClientManager.cs | 2 +- MediaBrowser.Common/Kernel/ResourcePool.cs | 5 ++ .../Providers/Music/LastfmArtistProvider.cs | 62 ++++++++++++++++++- .../Music/LastfmBaseArtistProvider.cs | 41 ++++-------- 4 files changed, 78 insertions(+), 32 deletions(-) diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index e01718f45..6848921ea 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 8a2ab8af8..7a74c60a7 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 0819ea6ed..5203b6f06 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 9e1ff2188..85f141a56 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 + artist.Overview = data.bio.summary; + foreach (var tag in data.tags.tag) { - using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) - { - searchResult = JsonSerializer.DeserializeFromStream(json); - } + artist.AddGenre(tag.name); } - 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; } } + #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 } From dccba7d1fdff94f14c2a09105b93d6daa602eb4d Mon Sep 17 00:00:00 2001 From: ScottRapsey Date: Mon, 4 Mar 2013 14:29:09 +1100 Subject: [PATCH 4/4] Added useLegacyV2RuntimeActivationPolicy Added useLegacyV2RuntimeActivationPolicy="true" to the Startup section of the config so that we can get .net dependencies to load if/when required. --- MediaBrowser.ServerApplication/App.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.ServerApplication/App.config b/MediaBrowser.ServerApplication/App.config index 13283e4b5..2d47c4bea 100644 --- a/MediaBrowser.ServerApplication/App.config +++ b/MediaBrowser.ServerApplication/App.config @@ -15,7 +15,7 @@ - +