From a08ebcc0c2bc54bf33b74c77ac23d8853a1722c4 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sun, 30 Apr 2017 08:54:37 -0500 Subject: [PATCH] Now returns one artist back with albums. --- src/NzbDrone.Api/Music/AlbumResource.cs | 11 +-- src/NzbDrone.Api/Music/ArtistResource.cs | 17 +--- .../SkyHook/Resource/ArtistResource.cs | 1 + .../MetadataSource/SkyHook/SkyHookProxy.cs | 78 ++++++++++++------- src/NzbDrone.Core/Music/Album.cs | 2 +- 5 files changed, 59 insertions(+), 50 deletions(-) diff --git a/src/NzbDrone.Api/Music/AlbumResource.cs b/src/NzbDrone.Api/Music/AlbumResource.cs index c0235e48a..ee9a66564 100644 --- a/src/NzbDrone.Api/Music/AlbumResource.cs +++ b/src/NzbDrone.Api/Music/AlbumResource.cs @@ -9,10 +9,10 @@ namespace NzbDrone.Api.Music public class AlbumResource { public int AlbumId { get; set; } + public string AlbumName { get; set; } public bool Monitored { get; set; } - //public string Overview { get; set; } public int Year { get; set; } - //public SeasonStatisticsResource Statistics { get; set; } + public List Genre { get; set; } } public static class AlbumResourceMapper @@ -25,8 +25,8 @@ namespace NzbDrone.Api.Music { AlbumId = model.AlbumId, Monitored = model.Monitored, - //Overview = model.Overview; //TODO: Inspect if Album needs an overview - Year = model.Year + Year = model.Year, + AlbumName = model.Title }; } @@ -38,7 +38,8 @@ namespace NzbDrone.Api.Music { AlbumId = resource.AlbumId, Monitored = resource.Monitored, - Year = resource.Year + Year = resource.Year, + Title = resource.AlbumName }; } diff --git a/src/NzbDrone.Api/Music/ArtistResource.cs b/src/NzbDrone.Api/Music/ArtistResource.cs index 0921ea1b5..a59df1798 100644 --- a/src/NzbDrone.Api/Music/ArtistResource.cs +++ b/src/NzbDrone.Api/Music/ArtistResource.cs @@ -16,12 +16,10 @@ namespace NzbDrone.Api.Music Monitored = true; } - //Todo: Sorters should be done completely on the client - //Todo: Is there an easy way to keep IgnoreArticlesWhenSorting in sync between, Series, History, Missing? - //Todo: We should get the entire Profile instead of ID and Name separately //View Only public string ArtistName { get; set; } + public int ItunesId { get; set; } //public List AlternateTitles { get; set; } //public string SortTitle { get; set; } @@ -55,17 +53,6 @@ namespace NzbDrone.Api.Music public bool ArtistFolder { get; set; } public bool Monitored { get; set; } - //public bool UseSceneNumbering { get; set; } - //public int Runtime { get; set; } - //public int TvdbId { get; set; } - //public int TvRageId { get; set; } - //public int TvMazeId { get; set; } - //public DateTime? FirstAired { get; set; } - //public DateTime? LastInfoSync { get; set; } - //public SeriesTypes SeriesType { get; set; } - public string CleanTitle { get; set; } - public int ItunesId { get; set; } - //public string TitleSlug { get; set; } public string RootFolderPath { get; set; } public string Certification { get; set; } public List Genres { get; set; } @@ -119,7 +106,6 @@ namespace NzbDrone.Api.Music //FirstAired = resource.FirstAired, //LastInfoSync = resource.LastInfoSync, //SeriesType = resource.SeriesType, - CleanTitle = model.CleanTitle, ItunesId = model.ItunesId, ArtistSlug = model.ArtistSlug, @@ -174,7 +160,6 @@ namespace NzbDrone.Api.Music //FirstAired = resource.FirstAired, //LastInfoSync = resource.LastInfoSync, //SeriesType = resource.SeriesType, - CleanTitle = resource.CleanTitle, ItunesId = resource.ItunesId, ArtistSlug = resource.ArtistSlug, diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs index 7e6040021..b7d8eff01 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource public string ArtistName { get; set; } public int ArtistId { get; set; } public string CollectionName { get; set; } + public int CollectionId { get; set; } } public class ArtistResource diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 0b68cb78f..a912109aa 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -99,7 +99,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook Console.WriteLine("httpRequest: ", httpRequest); - var httpResponse = _httpClient.Get(httpRequest); + var httpResponse = _httpClient.Get>(httpRequest); //Console.WriteLine("Response: ", httpResponse.GetType()); //_logger.Info("Response: ", httpResponse.Resource.ResultCount); @@ -111,7 +111,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook tempList.Add(tempSeries); return tempList; - //return httpResponse.Resource.Results.SelectList(MapArtist); + return httpResponse.Resource.SelectList(MapSeries); } catch (HttpException) { @@ -131,26 +131,26 @@ namespace NzbDrone.Core.MetadataSource.SkyHook var lowerTitle = title.ToLowerInvariant(); Console.WriteLine("Searching for " + lowerTitle); - //if (lowerTitle.StartsWith("tvdb:") || lowerTitle.StartsWith("tvdbid:")) - //{ - // var slug = lowerTitle.Split(':')[1].Trim(); - - // int tvdbId; - - // if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !int.TryParse(slug, out tvdbId) || tvdbId <= 0) - // { - // return new List(); - // } - - // try - // { - // return new List { GetSeriesInfo(tvdbId).Item1 }; - // } - // catch (SeriesNotFoundException) - // { - // return new List(); - // } - //} + if (lowerTitle.StartsWith("itunes:") || lowerTitle.StartsWith("itunesid:")) + { + var slug = lowerTitle.Split(':')[1].Trim(); + + int itunesId; + + if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || !int.TryParse(slug, out itunesId) || itunesId <= 0) + { + return new List(); + } + + //try + //{ + // return new List { GetArtistInfo(itunesId).Item1 }; + //} + //catch (ArtistNotFoundException) + //{ + // return new List(); + //} + } var httpRequest = _requestBuilder.Create() .AddQueryParam("entity", "album") @@ -163,15 +163,37 @@ namespace NzbDrone.Core.MetadataSource.SkyHook var httpResponse = _httpClient.Get(httpRequest); + //Console.WriteLine("Response: ", httpResponse.GetType()); //_logger.Info("Response: ", httpResponse.Resource.ResultCount); //_logger.Info("HTTP Response: ", httpResponse.Resource.ResultCount); - var tempList = new List(); - var tempSeries = new Artist(); - tempSeries.ArtistName = "AFI"; - tempList.Add(tempSeries); - return tempList; + //var tempList = new List(); + //var tempSeries = new Artist(); + //tempSeries.ArtistName = "AFI"; + //tempList.Add(tempSeries); + //return tempList; + + + Album tempAlbum; + // TODO: This needs to handle multiple artists. + Artist artist = new Artist(); + artist.ArtistName = httpResponse.Resource.Results[0].ArtistName; + artist.ItunesId = httpResponse.Resource.Results[0].ArtistId; + foreach (var album in httpResponse.Resource.Results) + { + tempAlbum = new Album(); + tempAlbum.AlbumId = album.CollectionId; + tempAlbum.Title = album.CollectionName; + + artist.Albums.Add(tempAlbum); + } + + var temp = new List(); + temp.Add(artist); + return temp; + + // I need to return a list of mapped artists. //return httpResponse.Resource.Results.SelectList(MapArtist); } @@ -189,7 +211,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook private static Artist MapArtist(ArtistResource artistQuery) { var artist = new Artist(); - //artist.ItunesId = artistQuery.artistId; + //artist.ItunesId = artistQuery.ItunesId; ; // artist.ArtistName = artistQuery.ArtistName; diff --git a/src/NzbDrone.Core/Music/Album.cs b/src/NzbDrone.Core/Music/Album.cs index 0466e479f..aa7923aef 100644 --- a/src/NzbDrone.Core/Music/Album.cs +++ b/src/NzbDrone.Core/Music/Album.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Core.Music } public int AlbumId { get; set; } - public string Title { get; set; } + public string Title { get; set; } // NOTE: This should be CollectionName in API public int Year { get; set; } public int TrackCount { get; set; } public int DiscCount { get; set; }