mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-22 22:14:44 -04:00
Implemented track lookup into skyhook.
This commit is contained in:
@@ -26,6 +26,15 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
public List<AlbumInfoResource> Items { get; set; }
|
||||
}
|
||||
|
||||
public class TrackResultResource
|
||||
{
|
||||
public TrackResultResource()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<TrackInfoResource> Items { get; set; }
|
||||
}
|
||||
public class ArtistResource
|
||||
{
|
||||
public ArtistResource()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class TrackInfoResource
|
||||
{
|
||||
public TrackInfoResource()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public int DiscNumber { get; set; }
|
||||
public int DurationMs { get; set; }
|
||||
public string Href { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int TrackNumber { get; set; }
|
||||
public bool Explicit { get; set; }
|
||||
public List<ArtistInfoResource> Artists { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
artist.ArtistName = httpResponse.Resource.Name;
|
||||
artist.SpotifyId = httpResponse.Resource.Id;
|
||||
artist.Genres = httpResponse.Resource.Genres;
|
||||
//Artist artist = MapArtists(httpResponse.Resource)[0];
|
||||
|
||||
|
||||
artist = MapAlbums(artist);
|
||||
@@ -149,6 +148,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
album.AlbumId = albumResource.Id;
|
||||
album.Title = albumResource.Name;
|
||||
album.ArtworkUrl = albumResource.Images[0].Url;
|
||||
album.Tracks = MapTracksToAlbum(album);
|
||||
albums.Add(album);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,44 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
artist.Albums = albums;
|
||||
return artist;
|
||||
}
|
||||
|
||||
|
||||
private List<Track> MapTracksToAlbum(Album album)
|
||||
{
|
||||
var httpRequest = _requestBuilder.Create()
|
||||
.SetSegment("route", "albums/" + album.AlbumId + "/tracks")
|
||||
.Build();
|
||||
|
||||
httpRequest.AllowAutoRedirect = true;
|
||||
httpRequest.SuppressHttpError = true;
|
||||
|
||||
var httpResponse = _httpClient.Get<TrackResultResource>(httpRequest);
|
||||
|
||||
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.Explict = trackResource.Explicit;
|
||||
track.Compilation = trackResource.Artists.Count > 1;
|
||||
track.TrackNumber = trackResource.TrackNumber;
|
||||
track.TrackExplicitName = trackResource.Name;
|
||||
track.TrackCensoredName = trackResource.Name;
|
||||
tracks.Add(track);
|
||||
}
|
||||
|
||||
return tracks;
|
||||
}
|
||||
|
||||
|
||||
public List<Artist> SearchForNewArtist(string title)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user