mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Merge pull request #2 from lidarr/feature/LidarrAPI
Reimplemented the Metadata Search/Add Artist Flow with LidarrAPI.Metadata
This commit is contained in:
commit
490e9feb93
8 changed files with 35 additions and 40 deletions
|
@ -17,8 +17,10 @@ namespace NzbDrone.Common.Cloud
|
||||||
Services = new HttpRequestBuilder("http://services.lidarr.tv/v1/")
|
Services = new HttpRequestBuilder("http://services.lidarr.tv/v1/")
|
||||||
.CreateFactory();
|
.CreateFactory();
|
||||||
|
|
||||||
Search = new HttpRequestBuilder("https://api.spotify.com/{version}/{route}/") // TODO: maybe use {version}
|
//Search = new HttpRequestBuilder("https://api.spotify.com/{version}/{route}/") // TODO: maybe use {version}
|
||||||
.SetSegment("version", "v1")
|
// .SetSegment("version", "v1")
|
||||||
|
// .CreateFactory();
|
||||||
|
Search = new HttpRequestBuilder("http://localhost:5000/{route}/") // TODO: maybe use {version}
|
||||||
.CreateFactory();
|
.CreateFactory();
|
||||||
|
|
||||||
InternalSearch = new HttpRequestBuilder("https://itunes.apple.com/WebObjects/MZStore.woa/wa/{route}") //viewArtist or search
|
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 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 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 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 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 List<string> Genres { get; set; }
|
||||||
public string AristUrl { get; set; }
|
public string AristUrl { get; set; }
|
||||||
|
public string Overview { get; set; }
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public List<ImageResource> Images { get; set; }
|
public List<ImageResource> Images { get; set; }
|
||||||
public string Name { get; set; }
|
public string ArtistName { get; set; }
|
||||||
|
|
||||||
// We may need external_urls.spotify to external linking...
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ArtistInfoResource> Items { get; set; }
|
public List<ArtistInfoResource> Items { get; set; }
|
||||||
|
public int Count { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AlbumResultResource
|
public class AlbumResultResource
|
||||||
|
@ -24,6 +25,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AlbumInfoResource> Items { get; set; }
|
public List<AlbumInfoResource> Items { get; set; }
|
||||||
|
public int Count { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TrackResultResource
|
public class TrackResultResource
|
||||||
|
@ -34,6 +36,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TrackInfoResource> Items { get; set; }
|
public List<TrackInfoResource> Items { get; set; }
|
||||||
|
public int Count { get; set; }
|
||||||
}
|
}
|
||||||
public class ArtistResource
|
public class ArtistResource
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||||
public int DurationMs { get; set; }
|
public int DurationMs { get; set; }
|
||||||
public string Href { get; set; }
|
public string Href { get; set; }
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string TrackName { get; set; }
|
||||||
public int TrackNumber { get; set; }
|
public int TrackNumber { get; set; }
|
||||||
public bool Explicit { get; set; }
|
public bool Explicit { get; set; }
|
||||||
public List<ArtistInfoResource> Artists { 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);
|
_logger.Debug("Getting Artist with SpotifyId of {0}", spotifyId);
|
||||||
|
|
||||||
///v1/albums/{id}
|
|
||||||
//
|
|
||||||
|
|
||||||
// We need to perform a direct lookup of the artist
|
// We need to perform a direct lookup of the artist
|
||||||
var httpRequest = _requestBuilder.Create()
|
var httpRequest = _requestBuilder.Create()
|
||||||
.SetSegment("route", "artists/" + spotifyId)
|
.SetSegment("route", "artists/" + spotifyId)
|
||||||
|
@ -95,7 +92,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||||
httpRequest.AllowAutoRedirect = true;
|
httpRequest.AllowAutoRedirect = true;
|
||||||
httpRequest.SuppressHttpError = true;
|
httpRequest.SuppressHttpError = true;
|
||||||
|
|
||||||
var httpResponse = _httpClient.Get<ArtistInfoResource>(httpRequest);
|
var httpResponse = _httpClient.Get<ArtistResource>(httpRequest);
|
||||||
|
|
||||||
|
|
||||||
if (httpResponse.HasHttpError)
|
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 artist = new Artist();
|
||||||
artist.ArtistName = httpResponse.Resource.Name;
|
artist.ArtistName = httpResponse.Resource.Artists.Items[0].ArtistName;
|
||||||
artist.SpotifyId = httpResponse.Resource.Id;
|
artist.SpotifyId = httpResponse.Resource.Artists.Items[0].Id;
|
||||||
artist.Genres = httpResponse.Resource.Genres;
|
artist.Genres = httpResponse.Resource.Artists.Items[0].Genres;
|
||||||
|
|
||||||
var albumRet = MapAlbums(artist);
|
var albumRet = MapAlbums(artist);
|
||||||
artist = albumRet.Item1;
|
artist = albumRet.Item1;
|
||||||
|
@ -147,7 +145,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||||
{
|
{
|
||||||
Album album = new Album();
|
Album album = new Album();
|
||||||
album.AlbumId = albumResource.Id;
|
album.AlbumId = albumResource.Id;
|
||||||
album.Title = albumResource.Name;
|
album.Title = albumResource.AlbumName;
|
||||||
album.ArtworkUrl = albumResource.Images.Count > 0 ? albumResource.Images[0].Url : "";
|
album.ArtworkUrl = albumResource.Images.Count > 0 ? albumResource.Images[0].Url : "";
|
||||||
album.Tracks = MapTracksToAlbum(album);
|
album.Tracks = MapTracksToAlbum(album);
|
||||||
masterTracks.InsertRange(masterTracks.Count, album.Tracks);
|
masterTracks.InsertRange(masterTracks.Count, album.Tracks);
|
||||||
|
@ -190,7 +188,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||||
track.Explict = trackResource.Explicit;
|
track.Explict = trackResource.Explicit;
|
||||||
track.Compilation = trackResource.Artists.Count > 1;
|
track.Compilation = trackResource.Artists.Count > 1;
|
||||||
track.TrackNumber = trackResource.TrackNumber;
|
track.TrackNumber = trackResource.TrackNumber;
|
||||||
track.Title = trackResource.Name;
|
track.Title = trackResource.TrackName;
|
||||||
tracks.Add(track);
|
tracks.Add(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,8 +224,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||||
|
|
||||||
var httpRequest = _requestBuilder.Create()
|
var httpRequest = _requestBuilder.Create()
|
||||||
.SetSegment("route", "search")
|
.SetSegment("route", "search")
|
||||||
.AddQueryParam("type", "artist,album")
|
.AddQueryParam("type", "artist") // TODO: LidarrAPI.Metadata is getting , encoded. Needs to be raw ,
|
||||||
.AddQueryParam("q", title.ToLower().Trim())
|
.AddQueryParam("query", title.ToLower().Trim())
|
||||||
.Build();
|
.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)
|
private List<Artist> MapArtists(ArtistResource resource)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -272,10 +256,12 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||||
foreach(var artistResource in resource.Artists.Items)
|
foreach(var artistResource in resource.Artists.Items)
|
||||||
{
|
{
|
||||||
Artist artist = new Artist();
|
Artist artist = new Artist();
|
||||||
artist.ArtistName = artistResource.Name;
|
artist.ArtistName = artistResource.ArtistName;
|
||||||
artist.SpotifyId = artistResource.Id;
|
artist.SpotifyId = artistResource.Id; // TODO: Rename spotifyId to LidarrId
|
||||||
artist.Genres = artistResource.Genres;
|
artist.Genres = artistResource.Genres;
|
||||||
artist.ArtistSlug = Parser.Parser.CleanArtistTitle(artist.ArtistName);
|
artist.ArtistSlug = Parser.Parser.CleanArtistTitle(artist.ArtistName);
|
||||||
|
//artist.Images = artistResource.Images;
|
||||||
|
|
||||||
artists.Add(artist);
|
artists.Add(artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
tuple = _artistInfo.GetArtistInfo(newArtist.SpotifyId);
|
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);
|
_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.Parser;
|
||||||
using NzbDrone.Core.Qualities;
|
using NzbDrone.Core.Qualities;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Profiles
|
namespace NzbDrone.Core.Profiles
|
||||||
{
|
{
|
||||||
|
@ -22,13 +23,13 @@ namespace NzbDrone.Core.Profiles
|
||||||
public class ProfileService : IProfileService, IHandle<ApplicationStartedEvent>
|
public class ProfileService : IProfileService, IHandle<ApplicationStartedEvent>
|
||||||
{
|
{
|
||||||
private readonly IProfileRepository _profileRepository;
|
private readonly IProfileRepository _profileRepository;
|
||||||
private readonly ISeriesService _seriesService;
|
private readonly IArtistService _artistService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public ProfileService(IProfileRepository profileRepository, ISeriesService seriesService, Logger logger)
|
public ProfileService(IProfileRepository profileRepository, IArtistService artistService, Logger logger)
|
||||||
{
|
{
|
||||||
_profileRepository = profileRepository;
|
_profileRepository = profileRepository;
|
||||||
_seriesService = seriesService;
|
_artistService = artistService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ namespace NzbDrone.Core.Profiles
|
||||||
|
|
||||||
public void Delete(int id)
|
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);
|
throw new ProfileInUseException(id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue