Implemented track lookup into skyhook.

pull/7/head
Joseph Milazzo 7 years ago
parent a09d5d0b69
commit acb7d33d09

@ -17,7 +17,8 @@ namespace NzbDrone.Common.Cloud
Services = new HttpRequestBuilder("http://services.lidarr.tv/v1/")
.CreateFactory();
Search = new HttpRequestBuilder("https://api.spotify.com/v1/{route}/") // TODO: maybe use {version}
Search = new HttpRequestBuilder("https://api.spotify.com/{version}/{route}/") // TODO: maybe use {version}
.SetSegment("version", "v1")
.CreateFactory();
InternalSearch = new HttpRequestBuilder("https://itunes.apple.com/WebObjects/MZStore.woa/wa/{route}") //viewArtist or search

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

@ -18,6 +18,7 @@ namespace NzbDrone.Core.Music
public string Title { get; set; } // NOTE: This should be CollectionName in API
public int Year { get; set; }
public int TrackCount { get; set; }
public List<Track> Tracks { get; set; }
public int DiscCount { get; set; }
public bool Monitored { get; set; }
public List<MediaCover.MediaCover> Images { get; set; }

@ -824,6 +824,7 @@
<Compile Include="MetadataSource\SkyHook\Resource\SeasonResource.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\ShowResource.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\TimeOfDayResource.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\TrackInfoResource.cs" />
<Compile Include="MetadataSource\SkyHook\SkyHookProxy.cs" />
<Compile Include="MetadataSource\SearchSeriesComparer.cs" />
<Compile Include="MetadataSource\SkyHook\SkyHookException.cs" />

Loading…
Cancel
Save