mirror of
https://github.com/Readarr/Readarr
synced 2025-12-15 04:46:13 +01:00
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using NzbDrone.Core.Parser;
|
|
using Readarr.Api.V1.Author;
|
|
using Readarr.Api.V1.Books;
|
|
using Readarr.Http;
|
|
|
|
namespace Readarr.Api.V1.Parse
|
|
{
|
|
public class ParseModule : ReadarrRestModule<ParseResource>
|
|
{
|
|
private readonly IParsingService _parsingService;
|
|
|
|
public ParseModule(IParsingService parsingService)
|
|
{
|
|
_parsingService = parsingService;
|
|
|
|
GetResourceSingle = Parse;
|
|
}
|
|
|
|
private ParseResource Parse()
|
|
{
|
|
var title = Request.Query.Title.Value as string;
|
|
var parsedAlbumInfo = Parser.ParseBookTitle(title);
|
|
|
|
if (parsedAlbumInfo == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var remoteAlbum = _parsingService.Map(parsedAlbumInfo);
|
|
|
|
if (remoteAlbum != null)
|
|
{
|
|
return new ParseResource
|
|
{
|
|
Title = title,
|
|
ParsedBookInfo = remoteAlbum.ParsedBookInfo,
|
|
Author = remoteAlbum.Author.ToResource(),
|
|
Books = remoteAlbum.Books.ToResource()
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return new ParseResource
|
|
{
|
|
Title = title,
|
|
ParsedBookInfo = parsedAlbumInfo
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|