From 3662bb933bf94926e199529363c2091103a26905 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Fri, 5 May 2017 13:35:28 -0500 Subject: [PATCH] Fixed up API to instead call multiple APIs and mash results together --- .../MetadataSource/SkyHook/SkyHookProxy.cs | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 16f3b3a50..735ee3716 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -165,25 +165,24 @@ namespace NzbDrone.Core.MetadataSource.SkyHook public Tuple> GetArtistInfo(int itunesId) { - Console.WriteLine("[GetArtistInfo] id:" + itunesId); - //https://itunes.apple.com/lookup?id=909253 - //var httpRequest = _requestBuilder.Create() - // .SetSegment("route", "lookup") - // .AddQueryParam("id", itunesId.ToString()) - // .Build(); - - // TODO: Add special header, add Overview to Artist model - var httpRequest = _internalRequestBuilder.Create() + _logger.Debug("Getting Artist with iTunesID of {0}", itunesId); + var httpRequest1 = _requestBuilder.Create() + .SetSegment("route", "lookup") + .AddQueryParam("id", itunesId.ToString()) + .Build(); + + var httpRequest2 = _internalRequestBuilder.Create() .SetSegment("route", "viewArtist") .AddQueryParam("id", itunesId.ToString()) .Build(); - httpRequest.Headers.Add("X-Apple-Store-Front", "143459-2,32 t:music3"); - httpRequest.Headers.ContentType = "application/json"; + httpRequest2.Headers.Add("X-Apple-Store-Front", "143459-2,32 t:music3"); + httpRequest2.Headers.ContentType = "application/json"; - httpRequest.AllowAutoRedirect = true; - httpRequest.SuppressHttpError = true; + httpRequest1.AllowAutoRedirect = true; + httpRequest1.SuppressHttpError = true; - var httpResponse = _httpClient.Get(httpRequest); + var httpResponse = _httpClient.Get(httpRequest1); + var httpResponse2 = _httpClient.Get(httpRequest2); if (httpResponse.HasHttpError) { @@ -193,16 +192,22 @@ namespace NzbDrone.Core.MetadataSource.SkyHook } else { - throw new HttpException(httpRequest, httpResponse); + throw new HttpException(httpRequest1, httpResponse); + } + } + + List artists = MapArtists(httpResponse.Resource); + + if (httpResponse2.HasHttpError) + { + if (artists.Count == 1) + { + artists[0].Overview = httpResponse2.Resource.StorePlatformData.Artist.Results[itunesId].artistBio; } } - Console.WriteLine("GetArtistInfo, GetArtistInfo"); - //var tracks = httpResponse.Resource.Episodes.Select(MapEpisode); - //var artist = MapArtist(httpResponse.Resource); // I don't know how we are getting tracks from iTunes yet. - return new Tuple>(MapArtistInfo(httpResponse.Resource.StorePlatformData.Artist.Results[0]), new List()); - //return new Tuple>(artist, tracks.ToList()); + return new Tuple>(artists[0], new List()); } public List SearchForNewArtist(string title) {