You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/src/Readarr.Api.V1/Books/BookLookupController.cs

43 lines
1.3 KiB

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;
public BookLookupController(ISearchForNewBook searchProxy)
{
_searchProxy = searchProxy;
}
[HttpGet]
public object Search(string term)
{
var searchResults = _searchProxy.SearchForNewBook(term, null);
return MapToResource(searchResults).ToList();
}
private static IEnumerable<BookResource> MapToResource(IEnumerable<NzbDrone.Core.Books.Book> books)
{
foreach (var currentBook in books)
{
var resource = currentBook.ToResource();
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;
}
}
}
}