|
|
|
@ -22,11 +22,13 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IHttpRequestBuilderFactory _requestBuilder;
|
|
|
|
|
private readonly IHttpRequestBuilderFactory _internalRequestBuilder;
|
|
|
|
|
|
|
|
|
|
public SkyHookProxy(IHttpClient httpClient, ILidarrCloudRequestBuilder requestBuilder, Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
_requestBuilder = requestBuilder.Search;
|
|
|
|
|
_internalRequestBuilder = requestBuilder.InternalSearch;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -124,14 +126,59 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public Artist 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 = _requestBuilder.Create()
|
|
|
|
|
// .SetSegment("route", "viewArtist")
|
|
|
|
|
// .AddQueryParam("id", itunesId.ToString())
|
|
|
|
|
// .Build();
|
|
|
|
|
// httpRequest.Headers.Add("X-Apple-Store-Front", "143459-2,32 t:music3");
|
|
|
|
|
|
|
|
|
|
// httpRequest.AllowAutoRedirect = true;
|
|
|
|
|
// httpRequest.SuppressHttpError = true;
|
|
|
|
|
|
|
|
|
|
// var httpResponse = _httpClient.Get<ArtistResource>(httpRequest);
|
|
|
|
|
|
|
|
|
|
// if (httpResponse.HasHttpError)
|
|
|
|
|
// {
|
|
|
|
|
// if (httpResponse.StatusCode == HttpStatusCode.NotFound)
|
|
|
|
|
// {
|
|
|
|
|
// throw new ArtistNotFoundException(itunesId);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// throw new HttpException(httpRequest, httpResponse);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Console.WriteLine("GetArtistInfo, GetArtistInfo");
|
|
|
|
|
// return MapArtists(httpResponse.Resource)[0];
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
public Tuple<Artist, List<Track>> GetArtistInfo(int itunesId)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("[GetArtistInfo] id:" + itunesId);
|
|
|
|
|
//https://itunes.apple.com/lookup?id=909253
|
|
|
|
|
var httpRequest = _requestBuilder.Create()
|
|
|
|
|
.SetSegment("route", "lookup")
|
|
|
|
|
//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()
|
|
|
|
|
.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";
|
|
|
|
|
|
|
|
|
|
httpRequest.AllowAutoRedirect = true;
|
|
|
|
|
httpRequest.SuppressHttpError = true;
|
|
|
|
@ -154,7 +201,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
//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<Artist, List<Track>>(MapArtists(httpResponse.Resource)[0], new List<Track>());
|
|
|
|
|
return new Tuple<Artist, List<Track>>(MapArtistInfo(httpResponse.Resource.StorePlatformData.Artist.Results[0]), new List<Track>());
|
|
|
|
|
//return new Tuple<Artist, List<Track>>(artist, tracks.ToList());
|
|
|
|
|
}
|
|
|
|
|
public List<Artist> SearchForNewArtist(string title)
|
|
|
|
@ -208,6 +255,20 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Artist MapArtistInfo(ArtistInfoResource resource)
|
|
|
|
|
{
|
|
|
|
|
// This expects ArtistInfoResource, thus just need to populate one artist
|
|
|
|
|
Artist artist = new Artist();
|
|
|
|
|
artist.Overview = resource.artistBio;
|
|
|
|
|
artist.ArtistName = resource.name;
|
|
|
|
|
foreach(var genre in resource.genreNames)
|
|
|
|
|
{
|
|
|
|
|
artist.Genres.Add(genre);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return artist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Artist> MapArtists(ArtistResource resource)
|
|
|
|
|
{
|
|
|
|
|
Album tempAlbum;
|
|
|
|
|