mirror of
https://github.com/fergalmoran/Readarr.git
synced 2025-12-22 09:29:59 +00:00
(cherry picked from commit 10dc884fa87a8337e9f0622c269adede0b262029) Co-authored-by: optimous012 Closes #145
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NzbDrone.Core.MediaCover;
|
|
using NzbDrone.Core.MetadataSource;
|
|
using Readarr.Http;
|
|
|
|
namespace Readarr.Api.V1.Books
|
|
{
|
|
[V1ApiController("book/lookup")]
|
|
public class BookLookupController : Controller
|
|
{
|
|
private readonly ISearchForNewBook _searchProxy;
|
|
private readonly IMapCoversToLocal _coverMapper;
|
|
|
|
public BookLookupController(ISearchForNewBook searchProxy, IMapCoversToLocal coverMapper)
|
|
{
|
|
_searchProxy = searchProxy;
|
|
_coverMapper = coverMapper;
|
|
}
|
|
|
|
[HttpGet]
|
|
public object Search(string term)
|
|
{
|
|
var searchResults = _searchProxy.SearchForNewBook(term, null);
|
|
return MapToResource(searchResults).ToList();
|
|
}
|
|
|
|
private IEnumerable<BookResource> MapToResource(IEnumerable<NzbDrone.Core.Books.Book> books)
|
|
{
|
|
foreach (var currentBook in books)
|
|
{
|
|
var resource = currentBook.ToResource();
|
|
|
|
_coverMapper.ConvertToLocalUrls(resource.Id, MediaCoverEntity.Book, resource.Images);
|
|
|
|
var cover = currentBook.Editions.Value.Single(x => x.Monitored).Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Cover);
|
|
|
|
if (cover != null)
|
|
{
|
|
resource.RemoteCover = cover.Url;
|
|
}
|
|
|
|
yield return resource;
|
|
}
|
|
}
|
|
}
|
|
}
|