From 704983f652354adf40a16d5a6cbb29812b68dc66 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Fri, 2 Jun 2017 20:25:34 -0500 Subject: [PATCH] Fixed small issue in ProfileService. Reimplemented the metadata with LidarrAPI.Metadata --- .../Cloud/SonarrCloudRequestBuilder.cs | 6 ++- .../SkyHook/Resource/AlbumInfoResource.cs | 8 +++- .../SkyHook/Resource/ArtistInfoResource.cs | 5 +-- .../SkyHook/Resource/ArtistResource.cs | 3 ++ .../SkyHook/Resource/TrackInfoResource.cs | 2 +- .../MetadataSource/SkyHook/SkyHookProxy.cs | 40 ++++++------------- src/NzbDrone.Core/Music/AddArtistService.cs | 2 +- src/NzbDrone.Core/Profiles/ProfileService.cs | 9 +++-- 8 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/NzbDrone.Common/Cloud/SonarrCloudRequestBuilder.cs b/src/NzbDrone.Common/Cloud/SonarrCloudRequestBuilder.cs index 9efdda47c..ca8385242 100644 --- a/src/NzbDrone.Common/Cloud/SonarrCloudRequestBuilder.cs +++ b/src/NzbDrone.Common/Cloud/SonarrCloudRequestBuilder.cs @@ -17,8 +17,10 @@ namespace NzbDrone.Common.Cloud Services = new HttpRequestBuilder("http://services.lidarr.tv/v1/") .CreateFactory(); - Search = new HttpRequestBuilder("https://api.spotify.com/{version}/{route}/") // TODO: maybe use {version} - .SetSegment("version", "v1") + //Search = new HttpRequestBuilder("https://api.spotify.com/{version}/{route}/") // TODO: maybe use {version} + // .SetSegment("version", "v1") + // .CreateFactory(); + Search = new HttpRequestBuilder("http://localhost:5000/{route}/") // TODO: maybe use {version} .CreateFactory(); InternalSearch = new HttpRequestBuilder("https://itunes.apple.com/WebObjects/MZStore.woa/wa/{route}") //viewArtist or search diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/AlbumInfoResource.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/AlbumInfoResource.cs index d442be7ec..7f478ea3c 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/AlbumInfoResource.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/AlbumInfoResource.cs @@ -11,12 +11,16 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource { } - public string AlbumType { get; set; } // Might need to make this a separate class + //public string AlbumType { get; set; } // Might need to make this a separate class public List Artists { get; set; } // Will always be length of 1 unless a compilation public string Url { get; set; } // Link to the endpoint api to give full info for this object public string Id { get; set; } // This is a unique Album ID. Needed for all future API calls + public int Year { get; set; } public List Images { get; set; } - public string Name { get; set; } // In case of a takedown, this may be empty + public string AlbumName { get; set; } // In case of a takedown, this may be empty + public string Overview { get; set; } + public List Genres { get; set; } + public string Label { get; set; } } diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistInfoResource.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistInfoResource.cs index 35f969001..8a81d873f 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistInfoResource.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistInfoResource.cs @@ -11,10 +11,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource public List Genres { get; set; } public string AristUrl { get; set; } + public string Overview { get; set; } public string Id { get; set; } public List Images { get; set; } - public string Name { get; set; } - - // We may need external_urls.spotify to external linking... + public string ArtistName { get; set; } } } diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs index 8d98d6890..d85d675a4 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource } public List Items { get; set; } + public int Count { get; set; } } public class AlbumResultResource @@ -24,6 +25,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource } public List Items { get; set; } + public int Count { get; set; } } public class TrackResultResource @@ -34,6 +36,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource } public List Items { get; set; } + public int Count { get; set; } } public class ArtistResource { diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/TrackInfoResource.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/TrackInfoResource.cs index 2f905637d..3bdf71977 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/TrackInfoResource.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/TrackInfoResource.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource public int DurationMs { get; set; } public string Href { get; set; } public string Id { get; set; } - public string Name { get; set; } + public string TrackName { get; set; } public int TrackNumber { get; set; } public bool Explicit { get; set; } public List Artists { get; set; } diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 5a76a4c8e..093fb88e5 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -79,9 +79,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook _logger.Debug("Getting Artist with SpotifyId of {0}", spotifyId); - ///v1/albums/{id} - // - // We need to perform a direct lookup of the artist var httpRequest = _requestBuilder.Create() .SetSegment("route", "artists/" + spotifyId) @@ -95,7 +92,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook httpRequest.AllowAutoRedirect = true; httpRequest.SuppressHttpError = true; - var httpResponse = _httpClient.Get(httpRequest); + var httpResponse = _httpClient.Get(httpRequest); if (httpResponse.HasHttpError) @@ -110,10 +107,11 @@ namespace NzbDrone.Core.MetadataSource.SkyHook } } + // It is safe to assume an id will only return one Artist back Artist artist = new Artist(); - artist.ArtistName = httpResponse.Resource.Name; - artist.SpotifyId = httpResponse.Resource.Id; - artist.Genres = httpResponse.Resource.Genres; + artist.ArtistName = httpResponse.Resource.Artists.Items[0].ArtistName; + artist.SpotifyId = httpResponse.Resource.Artists.Items[0].Id; + artist.Genres = httpResponse.Resource.Artists.Items[0].Genres; var albumRet = MapAlbums(artist); artist = albumRet.Item1; @@ -147,7 +145,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook { Album album = new Album(); album.AlbumId = albumResource.Id; - album.Title = albumResource.Name; + album.Title = albumResource.AlbumName; album.ArtworkUrl = albumResource.Images.Count > 0 ? albumResource.Images[0].Url : ""; album.Tracks = MapTracksToAlbum(album); masterTracks.InsertRange(masterTracks.Count, album.Tracks); @@ -190,7 +188,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook track.Explict = trackResource.Explicit; track.Compilation = trackResource.Artists.Count > 1; track.TrackNumber = trackResource.TrackNumber; - track.Title = trackResource.Name; + track.Title = trackResource.TrackName; tracks.Add(track); } @@ -226,8 +224,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook var httpRequest = _requestBuilder.Create() .SetSegment("route", "search") - .AddQueryParam("type", "artist,album") - .AddQueryParam("q", title.ToLower().Trim()) + .AddQueryParam("type", "artist") // TODO: LidarrAPI.Metadata is getting , encoded. Needs to be raw , + .AddQueryParam("query", title.ToLower().Trim()) .Build(); @@ -250,20 +248,6 @@ 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 MapArtists(ArtistResource resource) { @@ -272,10 +256,12 @@ namespace NzbDrone.Core.MetadataSource.SkyHook foreach(var artistResource in resource.Artists.Items) { Artist artist = new Artist(); - artist.ArtistName = artistResource.Name; - artist.SpotifyId = artistResource.Id; + artist.ArtistName = artistResource.ArtistName; + artist.SpotifyId = artistResource.Id; // TODO: Rename spotifyId to LidarrId artist.Genres = artistResource.Genres; artist.ArtistSlug = Parser.Parser.CleanArtistTitle(artist.ArtistName); + //artist.Images = artistResource.Images; + artists.Add(artist); } diff --git a/src/NzbDrone.Core/Music/AddArtistService.cs b/src/NzbDrone.Core/Music/AddArtistService.cs index 07f995f69..2a1358b5b 100644 --- a/src/NzbDrone.Core/Music/AddArtistService.cs +++ b/src/NzbDrone.Core/Music/AddArtistService.cs @@ -77,7 +77,7 @@ namespace NzbDrone.Core.Music { tuple = _artistInfo.GetArtistInfo(newArtist.SpotifyId); } - catch (SeriesNotFoundException) + catch (ArtistNotFoundException) { _logger.Error("SpotifyId {1} was not found, it may have been removed from Spotify.", newArtist.SpotifyId); diff --git a/src/NzbDrone.Core/Profiles/ProfileService.cs b/src/NzbDrone.Core/Profiles/ProfileService.cs index 37014191c..1317b10b9 100644 --- a/src/NzbDrone.Core/Profiles/ProfileService.cs +++ b/src/NzbDrone.Core/Profiles/ProfileService.cs @@ -6,6 +6,7 @@ using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; +using NzbDrone.Core.Music; namespace NzbDrone.Core.Profiles { @@ -22,13 +23,13 @@ namespace NzbDrone.Core.Profiles public class ProfileService : IProfileService, IHandle { private readonly IProfileRepository _profileRepository; - private readonly ISeriesService _seriesService; + private readonly IArtistService _artistService; private readonly Logger _logger; - public ProfileService(IProfileRepository profileRepository, ISeriesService seriesService, Logger logger) + public ProfileService(IProfileRepository profileRepository, IArtistService artistService, Logger logger) { _profileRepository = profileRepository; - _seriesService = seriesService; + _artistService = artistService; _logger = logger; } @@ -44,7 +45,7 @@ namespace NzbDrone.Core.Profiles public void Delete(int id) { - if (_seriesService.GetAllSeries().Any(c => c.ProfileId == id)) + if (_artistService.GetAllArtists().Any(c => c.ProfileId == id)) { throw new ProfileInUseException(id); }