2016-03-25 02:56:29 +02:00
|
|
|
using NzbDrone.Api.Episodes;
|
|
|
|
using NzbDrone.Api.Series;
|
2017-08-22 06:24:15 +02:00
|
|
|
using NzbDrone.Common.Extensions;
|
2016-03-25 02:56:29 +02:00
|
|
|
using NzbDrone.Core.Parser;
|
2017-02-11 08:46:39 +02:00
|
|
|
using Sonarr.Http;
|
2020-05-17 23:01:41 +02:00
|
|
|
using Sonarr.Http.REST;
|
2015-04-10 16:30:06 +02:00
|
|
|
|
|
|
|
namespace NzbDrone.Api.Parse
|
|
|
|
{
|
2017-02-11 08:46:39 +02:00
|
|
|
public class ParseModule : SonarrRestModule<ParseResource>
|
2015-04-10 16:30:06 +02:00
|
|
|
{
|
|
|
|
private readonly IParsingService _parsingService;
|
|
|
|
|
|
|
|
public ParseModule(IParsingService parsingService)
|
|
|
|
{
|
|
|
|
_parsingService = parsingService;
|
|
|
|
|
|
|
|
GetResourceSingle = Parse;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ParseResource Parse()
|
|
|
|
{
|
2016-03-25 02:56:29 +02:00
|
|
|
var title = Request.Query.Title.Value as string;
|
2017-08-22 06:24:15 +02:00
|
|
|
var path = Request.Query.Path.Value as string;
|
2020-05-17 23:01:41 +02:00
|
|
|
|
|
|
|
if (path.IsNullOrWhiteSpace() && title.IsNullOrWhiteSpace())
|
|
|
|
{
|
|
|
|
throw new BadRequestException("title or path is missing");
|
|
|
|
}
|
|
|
|
|
2017-08-22 06:24:15 +02:00
|
|
|
var parsedEpisodeInfo = path.IsNotNullOrWhiteSpace() ? Parser.ParsePath(path) : Parser.ParseTitle(title);
|
2015-04-10 16:30:06 +02:00
|
|
|
|
|
|
|
if (parsedEpisodeInfo == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-09-26 10:45:13 +02:00
|
|
|
var remoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0);
|
2015-04-10 16:30:06 +02:00
|
|
|
|
2016-03-25 02:56:29 +02:00
|
|
|
if (remoteEpisode != null)
|
2015-04-10 16:30:06 +02:00
|
|
|
{
|
|
|
|
return new ParseResource
|
2016-03-25 02:56:29 +02:00
|
|
|
{
|
|
|
|
Title = title,
|
|
|
|
ParsedEpisodeInfo = remoteEpisode.ParsedEpisodeInfo,
|
|
|
|
Series = remoteEpisode.Series.ToResource(),
|
|
|
|
Episodes = remoteEpisode.Episodes.ToResource()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new ParseResource
|
|
|
|
{
|
|
|
|
Title = title,
|
|
|
|
ParsedEpisodeInfo = parsedEpisodeInfo
|
|
|
|
};
|
2015-04-10 16:30:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|