You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
62 lines
1.7 KiB
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
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|