2015-04-10 14:30:06 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-26 08:45:13 +00:00
|
|
|
|
var remoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0);
|
2015-04-10 14:30:06 +00:00
|
|
|
|
|
|
|
|
|
if (remoteEpisode == null)
|
|
|
|
|
{
|
|
|
|
|
remoteEpisode = new RemoteEpisode
|
|
|
|
|
{
|
|
|
|
|
ParsedEpisodeInfo = parsedEpisodeInfo
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new ParseResource
|
|
|
|
|
{
|
|
|
|
|
Title = title,
|
|
|
|
|
ParsedEpisodeInfo = parsedEpisodeInfo
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resource = ToResource(remoteEpisode);
|
|
|
|
|
resource.Title = title;
|
|
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|