New: Add/remove individual albums

This commit is contained in:
ta264
2019-12-16 21:21:32 +00:00
committed by GitHub
parent 6af29da4c9
commit 8a20c0fa83
128 changed files with 2796 additions and 743 deletions
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
namespace NzbDrone.Core.MetadataSource
{
public interface ISearchForNewEntity
{
List<Object> SearchForNewEntity(string title);
}
}
@@ -0,0 +1,10 @@
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
{
public class EntityResource
{
public int Score { get; set; }
public ArtistResource Artist { get; set; }
public AlbumResource Album { get; set; }
}
}
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using NLog;
using NzbDrone.Common.Cloud;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Exceptions;
@@ -15,7 +14,7 @@ using NzbDrone.Core.Profiles.Metadata;
namespace NzbDrone.Core.MetadataSource.SkyHook
{
public class SkyHookProxy : IProvideArtistInfo, ISearchForNewArtist, IProvideAlbumInfo, ISearchForNewAlbum
public class SkyHookProxy : IProvideArtistInfo, ISearchForNewArtist, IProvideAlbumInfo, ISearchForNewAlbum, ISearchForNewEntity
{
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
@@ -247,6 +246,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
.AddQueryParam("type", "album")
.AddQueryParam("query", title.ToLower().Trim())
.AddQueryParam("artist", artist.IsNotNullOrWhiteSpace() ? artist.ToLower().Trim() : string.Empty)
.AddQueryParam("includeTracks", "1")
.Build();
@@ -266,6 +266,31 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
}
}
public List<Object> SearchForNewEntity(string title)
{
try
{
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
.SetSegment("route", "search")
.AddQueryParam("type", "all")
.AddQueryParam("query", title.ToLower().Trim())
.Build();
var httpResponse = _httpClient.Get<List<EntityResource>>(httpRequest);
return httpResponse.Resource.SelectList(MapSearchResult);
}
catch (HttpException)
{
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with LidarrAPI.", title);
}
catch (Exception ex)
{
_logger.Warn(ex, ex.Message);
throw new SkyHookException("Search for '{0}' failed. Invalid response received from LidarrAPI.", title);
}
}
private Artist MapSearchResult(ArtistResource resource)
{
var artist = _artistService.FindById(resource.Id);
@@ -280,20 +305,34 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
private Album MapSearchResult(AlbumResource resource)
{
var album = _albumService.FindById(resource.Id) ?? MapAlbum(resource, null);
var artists = resource.Artists.Select(MapArtistMetadata).ToDictionary(x => x.ForeignArtistId, x => x);
var artist = _artistService.FindById(resource.ArtistId);
if (artist == null)
{
artist = new Artist();
artist.Metadata = MapArtistMetadata(resource.Artists.Single(x => x.Id == resource.ArtistId));
artist.Metadata = artists[resource.ArtistId];
}
var album = _albumService.FindById(resource.Id) ?? MapAlbum(resource, artists);
album.Artist = artist;
album.ArtistMetadata = artist.Metadata;
album.ArtistMetadata = artist.Metadata.Value;
return album;
}
private Object MapSearchResult(EntityResource resource)
{
if (resource.Artist != null)
{
return MapSearchResult(resource.Artist);
}
else
{
return MapSearchResult(resource.Album);
}
}
private static Album MapAlbum(AlbumResource resource, Dictionary<string, ArtistMetadata> artistDict)
{
Album album = new Album();