mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-21 22:05:38 -04:00
API endpoint to parse a release title
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Api.Parse
|
||||
{
|
||||
public class ParseModule : NzbDroneRestModule<ParseResource>
|
||||
{
|
||||
private readonly IParsingService _parsingService;
|
||||
|
||||
public ParseModule(IParsingService parsingService)
|
||||
{
|
||||
_parsingService = parsingService;
|
||||
|
||||
GetResourceSingle = Parse;
|
||||
}
|
||||
|
||||
private ParseResource Parse()
|
||||
{
|
||||
var title = Request.Query.Title.Value;
|
||||
var parsedEpisodeInfo = Parser.ParseTitle(title);
|
||||
|
||||
if (parsedEpisodeInfo == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var remoteEpisode = _parsingService.Map(parsedEpisodeInfo);
|
||||
|
||||
if (remoteEpisode == null)
|
||||
{
|
||||
remoteEpisode = new RemoteEpisode
|
||||
{
|
||||
ParsedEpisodeInfo = parsedEpisodeInfo
|
||||
};
|
||||
|
||||
return new ParseResource
|
||||
{
|
||||
Title = title,
|
||||
ParsedEpisodeInfo = parsedEpisodeInfo
|
||||
};
|
||||
}
|
||||
|
||||
var resource = ToResource(remoteEpisode);
|
||||
resource.Title = title;
|
||||
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user