Merge pull request #2 from lidarr/feature/LidarrAPI

Reimplemented the Metadata Search/Add Artist Flow with LidarrAPI.Metadata
pull/4/head
Joseph Milazzo 7 years ago committed by GitHub
commit 490e9feb93

@ -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

@ -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<ArtistInfoResource> 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<ImageResource> 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<string> Genres { get; set; }
public string Label { get; set; }
}

@ -11,10 +11,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
public List<string> Genres { get; set; }
public string AristUrl { get; set; }
public string Overview { get; set; }
public string Id { get; set; }
public List<ImageResource> Images { get; set; }
public string Name { get; set; }
// We may need external_urls.spotify to external linking...
public string ArtistName { get; set; }
}
}

@ -14,6 +14,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
}
public List<ArtistInfoResource> Items { get; set; }
public int Count { get; set; }
}
public class AlbumResultResource
@ -24,6 +25,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
}
public List<AlbumInfoResource> Items { get; set; }
public int Count { get; set; }
}
public class TrackResultResource
@ -34,6 +36,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
}
public List<TrackInfoResource> Items { get; set; }
public int Count { get; set; }
}
public class ArtistResource
{

@ -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<ArtistInfoResource> Artists { get; set; }

@ -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<ArtistInfoResource>(httpRequest);
var httpResponse = _httpClient.Get<ArtistResource>(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<Artist> 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);
}

@ -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);

@ -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<ApplicationStartedEvent>
{
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);
}

Loading…
Cancel
Save