mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Add Parse endpoint to V3 API
This commit is contained in:
parent
7ea749e93c
commit
abe8a06c11
61
src/Radarr.Api.V3/Parse/ParseModule.cs
Normal file
61
src/Radarr.Api.V3/Parse/ParseModule.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.Parser;
|
||||
using Radarr.Api.V3.Movies;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Parse
|
||||
{
|
||||
public class ParseModule : RadarrRestModule<ParseResource>
|
||||
{
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public ParseModule(IParsingService parsingService, IConfigService configService)
|
||||
{
|
||||
_parsingService = parsingService;
|
||||
_configService = configService;
|
||||
|
||||
GetResourceSingle = Parse;
|
||||
}
|
||||
|
||||
private ParseResource Parse()
|
||||
{
|
||||
var title = Request.Query.Title.Value as string;
|
||||
|
||||
if (title.IsNullOrWhiteSpace())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var parsedMovieInfo = _parsingService.ParseMovieInfo(title, new List<object>());
|
||||
|
||||
if (parsedMovieInfo == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var remoteMovie = _parsingService.Map(parsedMovieInfo, "");
|
||||
|
||||
if (remoteMovie != null)
|
||||
{
|
||||
return new ParseResource
|
||||
{
|
||||
Title = title,
|
||||
ParsedMovieInfo = remoteMovie.RemoteMovie.ParsedMovieInfo,
|
||||
Movie = remoteMovie.Movie.ToResource(_configService.AvailabilityDelay)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ParseResource
|
||||
{
|
||||
Title = title,
|
||||
ParsedMovieInfo = parsedMovieInfo
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
src/Radarr.Api.V3/Parse/ParseResource.cs
Normal file
13
src/Radarr.Api.V3/Parse/ParseResource.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using Radarr.Api.V3.Movies;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V3.Parse
|
||||
{
|
||||
public class ParseResource : RestResource
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public ParsedMovieInfo ParsedMovieInfo { get; set; }
|
||||
public MovieResource Movie { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user