fixes #231 - Fanart Thumbs are not downloaded

pull/702/head
Luke Pulverenti 12 years ago
parent eb45e67c81
commit f996336137

@ -35,6 +35,8 @@ namespace MediaBrowser.Controller.Providers.Music
/// <value>The HTTP client.</value>
protected IHttpClient HttpClient { get; private set; }
internal static FanArtAlbumProvider Current { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="FanArtAlbumProvider"/> class.
/// </summary>
@ -47,6 +49,8 @@ namespace MediaBrowser.Controller.Providers.Music
{
_providerManager = providerManager;
HttpClient = httpClient;
Current = this;
}
/// <summary>
@ -208,12 +212,12 @@ namespace MediaBrowser.Controller.Providers.Music
private DateTime _lastMusicBrainzRequest = DateTime.MinValue;
/// <summary>
/// Gets the release group id.
/// Gets the music brainz response.
/// </summary>
/// <param name="releaseEntryId">The release entry id.</param>
/// <param name="url">The URL.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.String}.</returns>
private async Task<string> GetReleaseGroupId(string releaseEntryId, CancellationToken cancellationToken)
/// <returns>Task{XmlDocument}.</returns>
internal async Task<XmlDocument> 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
/// <param name="releaseEntryId">The release entry id.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.String}.</returns>
private async Task<string> GetReleaseGroupIdInternal(string releaseEntryId, CancellationToken cancellationToken)
private async Task<string> 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#");

@ -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<string> FindId(BaseItem item, 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;
try
{
using (var json = await HttpClient.Get(url, LastfmResourcePool, cancellationToken).ConfigureAwait(false))
{
searchResult = JsonSerializer.DeserializeFromStream<LastfmArtistSearchResults>(json);
}
}
catch (HttpException e)
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
if (e.StatusCode == HttpStatusCode.NotFound)
{
return null;
}
throw;
return true;
}
if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Count > 0)
protected override async Task<string> FindId(BaseItem item, CancellationToken cancellationToken)
{
var artist = searchResult.results.artistmatches.artist.FirstOrDefault(i => string.Equals(i.name, item.Name, System.StringComparison.OrdinalIgnoreCase));
var url = string.Format("http://www.musicbrainz.org/ws/2/artist/?query=artistaccent:{0}", UrlEncode(item.Name));
return artist != null ? artist.mbid : searchResult.results.artistmatches.artist[0].mbid;
}
var doc = await FanArtAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
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)

@ -46,7 +46,7 @@ namespace MediaBrowser.Controller.Providers.Music
{
get
{
return "04-25-2013";
return "4";
}
}

Loading…
Cancel
Save