fixes #157 - a handful of persistent artist have failure to download BIOs

This commit is contained in:
Luke Pulverenti 2013-05-10 13:12:50 -04:00
parent 2ea9b7e4eb
commit 2bb518027f

View File

@ -93,8 +93,6 @@ namespace MediaBrowser.Controller.Providers.Music
//Execute the Artist search against our name and assume first one is the one we want //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); var url = RootUrl + string.Format("method=artist.search&artist={0}&api_key={1}&format=json", UrlEncode(item.Name), ApiKey);
LastfmArtistSearchResults searchResult;
try try
{ {
using (var json = await HttpClient.Get(new HttpRequestOptions using (var json = await HttpClient.Get(new HttpRequestOptions
@ -106,14 +104,18 @@ namespace MediaBrowser.Controller.Providers.Music
}).ConfigureAwait(false)) }).ConfigureAwait(false))
{ {
searchResult = JsonSerializer.DeserializeFromStream<LastfmArtistSearchResults>(json); using (var reader = new StreamReader(json, true))
} {
} var jsonString = await reader.ReadToEndAsync().ConfigureAwait(false);
catch (HttpException e)
// Sometimes they send back an empty response or just the text "null"
if (!jsonString.StartsWith("{", StringComparison.OrdinalIgnoreCase))
{ {
return null; return null;
} }
var searchResult = JsonSerializer.DeserializeFromString<LastfmArtistSearchResults>(jsonString);
if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Count > 0) if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Count > 0)
{ {
var artist = searchResult.results.artistmatches.artist.FirstOrDefault(i => i.name != null && string.Compare(i.name, item.Name, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0) ?? var artist = searchResult.results.artistmatches.artist.FirstOrDefault(i => i.name != null && string.Compare(i.name, item.Name, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0) ??
@ -121,6 +123,13 @@ namespace MediaBrowser.Controller.Providers.Music
return artist.mbid; return artist.mbid;
} }
}
}
}
catch (HttpException)
{
return null;
}
return null; return null;
} }