mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-26 15:52:42 +00:00
parent
54e9f88648
commit
8cb8059b2f
6 changed files with 111 additions and 7 deletions
|
@ -8,10 +8,8 @@ public class album_releases_fix : NzbDroneMigrationBase
|
|||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Delete.Column("Releases").FromTable("Albums");
|
||||
Delete.Column("CurrentRelease").FromTable("Albums");
|
||||
Alter.Table("Albums").AddColumn("Releases").AsString().WithDefaultValue("[]").NotNullable();
|
||||
Alter.Table("Albums").AddColumn("CurrentRelease").AsString().WithDefaultValue("").NotNullable();
|
||||
Alter.Table("Albums").AlterColumn("Releases").AsString().NotNullable();
|
||||
Alter.Table("Albums").AlterColumn("CurrentRelease").AsString().NotNullable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
src/NzbDrone.Core/MetadataSource/ISearchForNewAlbum.cs
Normal file
11
src/NzbDrone.Core/MetadataSource/ISearchForNewAlbum.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface ISearchForNewAlbum
|
||||
{
|
||||
List<Album> SearchForNewAlbum(string title, string artist, DateTime releaseDate);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class AlbumArtistResource
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ public class AlbumResource
|
|||
public AlbumResource()
|
||||
{
|
||||
Media = new List<MediumResource>();
|
||||
Releases = new List<ReleaseResource>();
|
||||
}
|
||||
|
||||
public List<ArtistResource> Artists { get; set; } // Will always be length of 1 unless a compilation
|
||||
|
@ -27,6 +28,7 @@ public AlbumResource()
|
|||
public List<TrackResource> Tracks { get; set; }
|
||||
public List<ReleaseResource> Releases { get; set; }
|
||||
public string SelectedRelease { get; set; }
|
||||
public AlbumArtistResource Artist { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,12 +15,13 @@
|
|||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
public class SkyHookProxy : IProvideArtistInfo, ISearchForNewArtist, IProvideAlbumInfo
|
||||
public class SkyHookProxy : IProvideArtistInfo, ISearchForNewArtist, IProvideAlbumInfo, ISearchForNewAlbum
|
||||
{
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly IAlbumService _albumService;
|
||||
private readonly IHttpRequestBuilderFactory _requestBuilder;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IMetadataProfileService _metadataProfileService;
|
||||
|
@ -29,7 +30,9 @@ public class SkyHookProxy : IProvideArtistInfo, ISearchForNewArtist, IProvideAlb
|
|||
|
||||
public SkyHookProxy(IHttpClient httpClient,
|
||||
ILidarrCloudRequestBuilder requestBuilder,
|
||||
IArtistService artistService, Logger logger,
|
||||
IArtistService artistService,
|
||||
IAlbumService albumService,
|
||||
Logger logger,
|
||||
IConfigService configService,
|
||||
IMetadataProfileService metadataProfileService)
|
||||
{
|
||||
|
@ -38,6 +41,7 @@ public SkyHookProxy(IHttpClient httpClient,
|
|||
_metadataProfileService = metadataProfileService;
|
||||
_requestBuilder = requestBuilder.Search;
|
||||
_artistService = artistService;
|
||||
_albumService = albumService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
@ -48,7 +52,8 @@ public Tuple<Artist, List<Album>> GetArtistInfo(string foreignArtistId, int meta
|
|||
|
||||
SetCustomProvider();
|
||||
|
||||
var metadataProfile = _metadataProfileService.Get(metadataProfileId);
|
||||
var metadataProfile = _metadataProfileService.Exists(metadataProfileId) ? _metadataProfileService.Get(metadataProfileId) : _metadataProfileService.All().FirstOrDefault();
|
||||
|
||||
|
||||
var primaryTypes = metadataProfile.PrimaryAlbumTypes.Where(s => s.Allowed).Select(s => s.PrimaryAlbumType.Name);
|
||||
var secondaryTypes = metadataProfile.SecondaryAlbumTypes.Where(s => s.Allowed).Select(s => s.SecondaryAlbumType.Name);
|
||||
|
@ -183,6 +188,61 @@ public List<Artist> SearchForNewArtist(string title)
|
|||
}
|
||||
}
|
||||
|
||||
public List<Album> SearchForNewAlbum(string title, string artist, DateTime releaseDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lowerTitle = title.ToLowerInvariant();
|
||||
|
||||
if (lowerTitle.StartsWith("lidarr:") || lowerTitle.StartsWith("lidarrid:"))
|
||||
{
|
||||
var slug = lowerTitle.Split(':')[1].Trim();
|
||||
|
||||
Guid searchGuid;
|
||||
|
||||
bool isValid = Guid.TryParse(slug, out searchGuid);
|
||||
|
||||
if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || isValid == false)
|
||||
{
|
||||
return new List<Album>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new List<Album> { GetAlbumInfo(searchGuid.ToString(), null).Item1 };
|
||||
}
|
||||
catch (ArtistNotFoundException)
|
||||
{
|
||||
return new List<Album>();
|
||||
}
|
||||
}
|
||||
|
||||
SetCustomProvider();
|
||||
|
||||
var httpRequest = _customerRequestBuilder.Create()
|
||||
.SetSegment("route", "search")
|
||||
.AddQueryParam("type", "album")
|
||||
.AddQueryParam("query", title.ToLower().Trim())
|
||||
.AddQueryParam("artist", artist.ToLower().Trim())
|
||||
.Build();
|
||||
|
||||
|
||||
|
||||
var httpResponse = _httpClient.Get<List<AlbumResource>>(httpRequest);
|
||||
|
||||
return httpResponse.Resource.SelectList(MapSearhResult);
|
||||
}
|
||||
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 MapSearhResult(ArtistResource resource)
|
||||
{
|
||||
var artist = _artistService.FindById(resource.Id) ?? MapArtist(resource);
|
||||
|
@ -190,6 +250,13 @@ private Artist MapSearhResult(ArtistResource resource)
|
|||
return artist;
|
||||
}
|
||||
|
||||
private Album MapSearhResult(AlbumResource resource)
|
||||
{
|
||||
var album = _albumService.FindById(resource.Id) ?? MapAlbum(resource);
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
private static Album MapAlbum(AlbumResource resource)
|
||||
{
|
||||
Album album = new Album();
|
||||
|
@ -214,6 +281,16 @@ private static Album MapAlbum(AlbumResource resource)
|
|||
album.CurrentRelease = album.Releases.FirstOrDefault(s => s.Id == resource.SelectedRelease);
|
||||
}
|
||||
|
||||
if (resource.Artist != null)
|
||||
{
|
||||
album.Artist = new Artist
|
||||
{
|
||||
ForeignArtistId = resource.Artist.Id,
|
||||
Name = resource.Artist.Name
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
|
|
|
@ -182,6 +182,7 @@
|
|||
<Compile Include="Datastore\Migration\006_separate_automatic_and_interactive_search.cs" />
|
||||
<Compile Include="Datastore\Migration\007_change_album_path_to_relative.cs" />
|
||||
<Compile Include="Datastore\Migration\009_album_releases.cs" />
|
||||
<Compile Include="Datastore\Migration\010_album_releases_fix.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" />
|
||||
|
@ -731,8 +732,10 @@
|
|||
<Compile Include="Messaging\Events\IHandle.cs" />
|
||||
<Compile Include="Messaging\IProcessMessage.cs" />
|
||||
<Compile Include="MetadataSource\IProvideArtistInfo.cs" />
|
||||
<Compile Include="MetadataSource\ISearchForNewAlbum.cs" />
|
||||
<Compile Include="MetadataSource\ISearchForNewArtist.cs" />
|
||||
<Compile Include="MetadataSource\IProvideAlbumInfo.cs" />
|
||||
<Compile Include="MetadataSource\SkyHook\Resource\AlbumArtistResource.cs" />
|
||||
<Compile Include="MetadataSource\SkyHook\Resource\MediumResource.cs" />
|
||||
<Compile Include="MetadataSource\SkyHook\Resource\MemberResource.cs" />
|
||||
<Compile Include="MetadataSource\SkyHook\Resource\AlbumResource.cs" />
|
||||
|
|
Loading…
Reference in a new issue