1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-03-07 15:20:58 +02:00
Sonarr/src/NzbDrone.Api/Parse/ParseModule.cs

52 lines
1.5 KiB
C#
Raw Normal View History

using NzbDrone.Api.Episodes;
using NzbDrone.Api.Series;
2017-08-21 21:24:15 -07:00
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Parser;
2015-04-10 07:30:06 -07:00
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 as string;
2017-08-21 21:24:15 -07:00
var path = Request.Query.Path.Value as string;
var parsedEpisodeInfo = path.IsNotNullOrWhiteSpace() ? Parser.ParsePath(path) : Parser.ParseTitle(title);
2015-04-10 07:30:06 -07:00
if (parsedEpisodeInfo == null)
{
return null;
}
var remoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0);
2015-04-10 07:30:06 -07:00
if (remoteEpisode != null)
2015-04-10 07:30:06 -07:00
{
return new ParseResource
{
Title = title,
ParsedEpisodeInfo = remoteEpisode.ParsedEpisodeInfo,
Series = remoteEpisode.Series.ToResource(),
Episodes = remoteEpisode.Episodes.ToResource()
};
}
else
{
return new ParseResource
{
Title = title,
ParsedEpisodeInfo = parsedEpisodeInfo
};
2015-04-10 07:30:06 -07:00
}
}
}
}