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 }; } } } }