From f99633613732e0d9f6a390deb434a0b536379b21 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 May 2013 01:46:17 -0400 Subject: [PATCH] fixes #231 - Fanart Thumbs are not downloaded --- .../Providers/Music/FanArtAlbumProvider.cs | 36 +++++++++------- .../Providers/Music/LastfmArtistProvider.cs | 41 ++++++------------- .../Providers/Music/LastfmBaseProvider.cs | 2 +- 3 files changed, 34 insertions(+), 45 deletions(-) diff --git a/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs b/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs index 8c92ea025f..d9ccc6fdcf 100644 --- a/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs @@ -35,6 +35,8 @@ namespace MediaBrowser.Controller.Providers.Music /// The HTTP client. protected IHttpClient HttpClient { get; private set; } + internal static FanArtAlbumProvider Current { get; private set; } + /// /// Initializes a new instance of the class. /// @@ -47,6 +49,8 @@ namespace MediaBrowser.Controller.Providers.Music { _providerManager = providerManager; HttpClient = httpClient; + + Current = this; } /// @@ -208,12 +212,12 @@ namespace MediaBrowser.Controller.Providers.Music private DateTime _lastMusicBrainzRequest = DateTime.MinValue; /// - /// Gets the release group id. + /// Gets the music brainz response. /// - /// The release entry id. + /// The URL. /// The cancellation token. - /// Task{System.String}. - private async Task GetReleaseGroupId(string releaseEntryId, CancellationToken cancellationToken) + /// Task{XmlDocument}. + internal async Task GetMusicBrainzResponse(string url, CancellationToken cancellationToken) { await _musicBrainzResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); @@ -230,7 +234,17 @@ namespace MediaBrowser.Controller.Providers.Music _lastMusicBrainzRequest = DateTime.Now; - return await GetReleaseGroupIdInternal(releaseEntryId, cancellationToken).ConfigureAwait(false); + var doc = new XmlDocument(); + + using (var xml = await HttpClient.Get(url, cancellationToken).ConfigureAwait(false)) + { + using (var oReader = new StreamReader(xml, Encoding.UTF8)) + { + doc.Load(oReader); + } + } + + return doc; } finally { @@ -244,19 +258,11 @@ namespace MediaBrowser.Controller.Providers.Music /// The release entry id. /// The cancellation token. /// Task{System.String}. - private async Task GetReleaseGroupIdInternal(string releaseEntryId, CancellationToken cancellationToken) + private async Task GetReleaseGroupId(string releaseEntryId, CancellationToken cancellationToken) { var url = string.Format("http://www.musicbrainz.org/ws/2/release-group/?query=reid:{0}", releaseEntryId); - var doc = new XmlDocument(); - - using (var xml = await HttpClient.Get(url, cancellationToken).ConfigureAwait(false)) - { - using (var oReader = new StreamReader(xml, Encoding.UTF8)) - { - doc.Load(oReader); - } - } + var doc = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false); var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("mb", "http://musicbrainz.org/ns/mmd-2.0#"); diff --git a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs index 819c05a942..dd24880f56 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs @@ -3,13 +3,11 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Net; using MediaBrowser.Model.Serialization; using System.IO; -using System.Linq; -using System.Net; using System.Threading; using System.Threading.Tasks; +using System.Xml; namespace MediaBrowser.Controller.Providers.Music { @@ -24,37 +22,22 @@ namespace MediaBrowser.Controller.Providers.Music LocalMetaFileName = LastfmHelper.LocalArtistMetaFileName; } - protected override async Task FindId(BaseItem item, CancellationToken cancellationToken) + protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) { - //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; + return true; + } - try - { - using (var json = await HttpClient.Get(url, LastfmResourcePool, cancellationToken).ConfigureAwait(false)) - { - searchResult = JsonSerializer.DeserializeFromStream(json); - } - } - catch (HttpException e) - { - if (e.StatusCode == HttpStatusCode.NotFound) - { - return null; - } - throw; - } + protected override async Task FindId(BaseItem item, CancellationToken cancellationToken) + { + var url = string.Format("http://www.musicbrainz.org/ws/2/artist/?query=artistaccent:{0}", UrlEncode(item.Name)); - if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Count > 0) - { - var artist = searchResult.results.artistmatches.artist.FirstOrDefault(i => string.Equals(i.name, item.Name, System.StringComparison.OrdinalIgnoreCase)); + var doc = await FanArtAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false); - return artist != null ? artist.mbid : searchResult.results.artistmatches.artist[0].mbid; - } + var ns = new XmlNamespaceManager(doc.NameTable); + ns.AddNamespace("mb", "http://musicbrainz.org/ns/mmd-2.0#"); + var node = doc.SelectSingleNode("//mb:artist-list/mb:artist/@id", ns); - return null; + return node != null ? node.Value : null; } protected override async Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken) diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs index 68017d5b32..f07ea0a6ae 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs @@ -46,7 +46,7 @@ namespace MediaBrowser.Controller.Providers.Music { get { - return "04-25-2013"; + return "4"; } }