mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-21 22:04:31 -04:00
New DB Schema
Rearrange DB Schema for Album Centric Plan
This commit is contained in:
@@ -108,92 +108,96 @@ 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.Artists.Items[0].ArtistName;
|
||||
artist.SpotifyId = httpResponse.Resource.Artists.Items[0].Id;
|
||||
artist.Genres = httpResponse.Resource.Artists.Items[0].Genres;
|
||||
var albums = httpResponse.Resource.Albums.Select(MapAlbum);
|
||||
var tracks = httpResponse.Resource.Tracks.Select(MapTrack);
|
||||
var artist = MapArtist(httpResponse.Resource);
|
||||
|
||||
var albumRet = MapAlbums(artist);
|
||||
artist = albumRet.Item1;
|
||||
//artist.Name = httpResponse.Resource.Artists.Items[0].ArtistName;
|
||||
|
||||
//artist.ForeignArtistId = httpResponse.Resource.Artists.Items[0].Id;
|
||||
//artist.Genres = httpResponse.Resource.Artists.Items[0].Genres;
|
||||
|
||||
//var albumRet = MapAlbums(artist);
|
||||
//artist = albumRet.Item1;
|
||||
|
||||
|
||||
return new Tuple<Artist, List<Track>>(albumRet.Item1, albumRet.Item2);
|
||||
return new Tuple<Artist, List<Track>>(artist, tracks.ToList());
|
||||
}
|
||||
|
||||
private Tuple<Artist, List<Track>> MapAlbums(Artist artist)
|
||||
{
|
||||
|
||||
// Find all albums for the artist and all tracks for said album
|
||||
///v1/artists/{id}/albums
|
||||
var httpRequest = _requestBuilder.Create()
|
||||
.SetSegment("route", "artists/" + artist.SpotifyId + "/albums")
|
||||
.Build();
|
||||
httpRequest.AllowAutoRedirect = true;
|
||||
httpRequest.SuppressHttpError = true;
|
||||
|
||||
var httpResponse = _httpClient.Get<AlbumResultResource>(httpRequest);
|
||||
//private Tuple<Artist, List<Track>> MapAlbums(Artist artist)
|
||||
//{
|
||||
|
||||
if (httpResponse.HasHttpError)
|
||||
{
|
||||
throw new HttpException(httpRequest, httpResponse);
|
||||
}
|
||||
// // Find all albums for the artist and all tracks for said album
|
||||
// ///v1/artists/{id}/albums
|
||||
// var httpRequest = _requestBuilder.Create()
|
||||
// .SetSegment("route", "artists/" + artist.ForeignArtistId + "/albums")
|
||||
// .Build();
|
||||
// httpRequest.AllowAutoRedirect = true;
|
||||
// httpRequest.SuppressHttpError = true;
|
||||
|
||||
List<Track> masterTracks = new List<Track>();
|
||||
List<Album> albums = new List<Album>();
|
||||
foreach(var albumResource in httpResponse.Resource.Items)
|
||||
{
|
||||
Album album = new Album();
|
||||
album.AlbumId = albumResource.Id;
|
||||
album.Title = albumResource.AlbumName;
|
||||
album.ArtworkUrl = albumResource.Images.Count > 0 ? albumResource.Images[0].Url : "";
|
||||
album.Tracks = MapTracksToAlbum(album);
|
||||
masterTracks.InsertRange(masterTracks.Count, album.Tracks);
|
||||
albums.Add(album);
|
||||
}
|
||||
// var httpResponse = _httpClient.Get<AlbumResultResource>(httpRequest);
|
||||
|
||||
// TODO: We now need to get all tracks for each album
|
||||
// if (httpResponse.HasHttpError)
|
||||
// {
|
||||
// throw new HttpException(httpRequest, httpResponse);
|
||||
// }
|
||||
|
||||
artist.Albums = albums;
|
||||
return new Tuple<Artist, List<Track>>(artist, masterTracks);
|
||||
}
|
||||
// List<Track> masterTracks = new List<Track>();
|
||||
// List<Album> albums = new List<Album>();
|
||||
// foreach(var albumResource in httpResponse.Resource.Items)
|
||||
// {
|
||||
// Album album = new Album();
|
||||
// album.AlbumId = albumResource.Id;
|
||||
// album.Title = albumResource.AlbumName;
|
||||
// album.ArtworkUrl = albumResource.Images.Count > 0 ? albumResource.Images[0].Url : "";
|
||||
// album.Tracks = MapTracksToAlbum(album);
|
||||
// masterTracks.InsertRange(masterTracks.Count, album.Tracks);
|
||||
// albums.Add(album);
|
||||
// }
|
||||
|
||||
private List<Track> MapTracksToAlbum(Album album)
|
||||
{
|
||||
var httpRequest = _requestBuilder.Create()
|
||||
.SetSegment("route", "albums/" + album.AlbumId + "/tracks")
|
||||
.Build();
|
||||
// // TODO: We now need to get all tracks for each album
|
||||
|
||||
httpRequest.AllowAutoRedirect = true;
|
||||
httpRequest.SuppressHttpError = true;
|
||||
// artist.Albums = albums;
|
||||
// return new Tuple<Artist, List<Track>>(artist, masterTracks);
|
||||
//}
|
||||
|
||||
var httpResponse = _httpClient.Get<TrackResultResource>(httpRequest);
|
||||
//private List<Track> MapTracksToAlbum(Album album)
|
||||
//{
|
||||
// var httpRequest = _requestBuilder.Create()
|
||||
// .SetSegment("route", "albums/" + album.AlbumId + "/tracks")
|
||||
// .Build();
|
||||
|
||||
if (httpResponse.HasHttpError)
|
||||
{
|
||||
throw new HttpException(httpRequest, httpResponse);
|
||||
}
|
||||
// httpRequest.AllowAutoRedirect = true;
|
||||
// httpRequest.SuppressHttpError = true;
|
||||
|
||||
List<Track> tracks = new List<Track>();
|
||||
foreach(var trackResource in httpResponse.Resource.Items)
|
||||
{
|
||||
Track track = new Track();
|
||||
track.AlbumId = album.AlbumId;
|
||||
//track.Album = album; // This will cause infinite loop when trying to serialize.
|
||||
// TODO: Implement more track mapping
|
||||
//track.Artist = trackResource.Artists
|
||||
//track.ArtistId = album.
|
||||
track.SpotifyTrackId = trackResource.Id;
|
||||
track.ArtistSpotifyId = trackResource.Artists.Count > 0 ? trackResource.Artists[0].Id : null;
|
||||
track.Explict = trackResource.Explicit;
|
||||
track.Compilation = trackResource.Artists.Count > 1;
|
||||
track.TrackNumber = trackResource.TrackNumber;
|
||||
track.Title = trackResource.TrackName;
|
||||
tracks.Add(track);
|
||||
}
|
||||
// var httpResponse = _httpClient.Get<TrackResultResource>(httpRequest);
|
||||
|
||||
return tracks;
|
||||
}
|
||||
// if (httpResponse.HasHttpError)
|
||||
// {
|
||||
// throw new HttpException(httpRequest, httpResponse);
|
||||
// }
|
||||
|
||||
// List<Track> tracks = new List<Track>();
|
||||
// foreach(var trackResource in httpResponse.Resource.Items)
|
||||
// {
|
||||
// Track track = new Track();
|
||||
// track.AlbumId = album.AlbumId;
|
||||
// //track.Album = album; // This will cause infinite loop when trying to serialize.
|
||||
// // TODO: Implement more track mapping
|
||||
// //track.Artist = trackResource.Artists
|
||||
// //track.ArtistId = album.
|
||||
// track.SpotifyTrackId = trackResource.Id;
|
||||
// track.ArtistSpotifyId = trackResource.Artists.Count > 0 ? trackResource.Artists[0].Id : null;
|
||||
// track.Explict = trackResource.Explicit;
|
||||
// track.Compilation = trackResource.Artists.Count > 1;
|
||||
// track.TrackNumber = trackResource.TrackNumber;
|
||||
// track.Title = trackResource.TrackName;
|
||||
// tracks.Add(track);
|
||||
// }
|
||||
|
||||
// return tracks;
|
||||
//}
|
||||
|
||||
|
||||
public List<Artist> SearchForNewArtist(string title)
|
||||
@@ -230,12 +234,26 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
|
||||
|
||||
|
||||
var httpResponse = _httpClient.Get<ArtistResource>(httpRequest);
|
||||
var httpResponse = _httpClient.Get<List<ArtistResource>>(httpRequest);
|
||||
|
||||
return httpResponse.Resource.SelectList(MapArtist);
|
||||
//List<Artist> artists = MapArtists(httpResponse.Resource);
|
||||
//List<Artist> artists = new List<Artist>();
|
||||
//foreach (var artistResource in httpResponse.Resource.Artists.Items)
|
||||
//{
|
||||
// Artist artist = new Artist();
|
||||
// artist.Name = artistResource.ArtistName;
|
||||
// artist.ForeignArtistId = artistResource.Id; // TODO: Rename spotifyId to LidarrId
|
||||
// artist.Genres = artistResource.Genres;
|
||||
// artist.NameSlug = Parser.Parser.CleanArtistTitle(artist.Name);
|
||||
// artist.CleanName = Parser.Parser.CleanArtistTitle(artist.Name);
|
||||
//artist.Images = artistResource.Images;
|
||||
|
||||
// artists.Add(artist);
|
||||
//}
|
||||
|
||||
|
||||
List<Artist> artists = MapArtists(httpResponse.Resource);
|
||||
|
||||
return artists;
|
||||
//return artists;
|
||||
}
|
||||
catch (HttpException)
|
||||
{
|
||||
@@ -248,27 +266,37 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
}
|
||||
}
|
||||
|
||||
private List<Artist> MapArtists(ArtistResource resource)
|
||||
private static Album MapAlbum(AlbumResource resource)
|
||||
{
|
||||
Album album = new Album();
|
||||
return album;
|
||||
}
|
||||
|
||||
private static Track MapTrack(TrackResource resource)
|
||||
{
|
||||
Track track = new Track();
|
||||
return track;
|
||||
}
|
||||
|
||||
private static Artist MapArtist(ArtistResource resource)
|
||||
{
|
||||
|
||||
Artist artist = new Artist();
|
||||
|
||||
artist.Name = resource.ArtistName;
|
||||
artist.ForeignArtistId = resource.Id; // TODO: Rename spotifyId to LidarrId
|
||||
artist.Genres = resource.Genres;
|
||||
artist.Overview = resource.Overview;
|
||||
artist.NameSlug = Parser.Parser.CleanArtistTitle(artist.Name);
|
||||
artist.CleanName = Parser.Parser.CleanArtistTitle(artist.Name);
|
||||
//artist.Images = resource.Artists.Items[0].Images;
|
||||
|
||||
List<Artist> artists = new List<Artist>();
|
||||
foreach(var artistResource in resource.Artists.Items)
|
||||
{
|
||||
Artist artist = new Artist();
|
||||
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);
|
||||
}
|
||||
|
||||
// Maybe? Get all the albums for said artist
|
||||
|
||||
|
||||
return artists;
|
||||
return artist;
|
||||
}
|
||||
|
||||
//private Album MapAlbum(AlbumResource albumQuery)
|
||||
|
||||
Reference in New Issue
Block a user