1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-22 22:16:13 -04:00
Files
Sonarr/src/Sonarr.Api.V3/Parse/ParseController.cs
T
2022-08-07 15:24:41 -07:00

62 lines
1.7 KiB
C#

using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Parser;
using Sonarr.Api.V3.Episodes;
using Sonarr.Api.V3.Series;
using Sonarr.Http;
namespace Sonarr.Api.V3.Parse
{
[V3ApiController]
public class ParseController : Controller
{
private readonly IParsingService _parsingService;
public ParseController(IParsingService parsingService)
{
_parsingService = parsingService;
}
[HttpGet]
[Produces("application/json")]
public ParseResource Parse(string title, string path)
{
if (title.IsNullOrWhiteSpace())
{
return null;
}
var parsedEpisodeInfo = path.IsNotNullOrWhiteSpace() ? Parser.ParsePath(path) : Parser.ParseTitle(title);
if (parsedEpisodeInfo == null)
{
return new ParseResource
{
Title = title
};
}
var remoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0);
if (remoteEpisode != null)
{
return new ParseResource
{
Title = title,
ParsedEpisodeInfo = remoteEpisode.ParsedEpisodeInfo,
Series = remoteEpisode.Series.ToResource(),
Episodes = remoteEpisode.Episodes.ToResource()
};
}
else
{
return new ParseResource
{
Title = title,
ParsedEpisodeInfo = parsedEpisodeInfo
};
}
}
}
}