Finished Radarr integration
This commit is contained in:
@@ -37,6 +37,30 @@ public class RadarrController : Controller
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", Configuration.RadarrAPIKey);
|
||||
}
|
||||
|
||||
private async Task<ObjectResult> GetRadarrMovieInfo(MovieInfo movieInfo){
|
||||
var uriBuilder = new UriBuilder($"{Configuration.RadarrAddress}/api/v3/movie");
|
||||
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
|
||||
|
||||
query["tmdbId"] = movieInfo.TmdbId;
|
||||
query["excludeLocalCovers"] = "false";
|
||||
|
||||
uriBuilder.Query = query.ToString();
|
||||
var response = await _httpClient.GetAsync(uriBuilder.Uri).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
var movies = JsonSerializer.Deserialize<List<RadarrMovie>>(responseBody);
|
||||
var movie = movies?.FirstOrDefault();
|
||||
|
||||
if (movie == null)
|
||||
{
|
||||
return NotFound("Movie not found in Radarr library.");
|
||||
}
|
||||
|
||||
return Ok(movie);
|
||||
}
|
||||
|
||||
[HttpPost("deleteMovieFromRadarr")]
|
||||
public async Task<IActionResult> DeleteMovieFromRadarr([FromBody] MovieInfo movieInfo){
|
||||
|
||||
@@ -47,27 +71,27 @@ public class RadarrController : Controller
|
||||
|
||||
try
|
||||
{
|
||||
var uriBuilder = new UriBuilder($"{Configuration.RadarrAddress}/api/v3/movie");
|
||||
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
|
||||
var radarrMovieInfoResult = await GetRadarrMovieInfo(movieInfo).ConfigureAwait(false);
|
||||
|
||||
query["tmdbId"] = movieInfo.TmdbId;
|
||||
query["excludeLocalCovers"] = "false";
|
||||
|
||||
uriBuilder.Query = query.ToString();
|
||||
var response = await _httpClient.GetAsync(uriBuilder.Uri).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
var movies = JsonSerializer.Deserialize<List<RadarrMovie>>(responseBody);
|
||||
var movie = movies?.FirstOrDefault();
|
||||
|
||||
if (movie == null)
|
||||
{
|
||||
return NotFound("Movie not found in Radarr library.");
|
||||
if(radarrMovieInfoResult.StatusCode != StatusCodes.Status200OK || radarrMovieInfoResult.Value is not RadarrMovie){
|
||||
return radarrMovieInfoResult;
|
||||
}
|
||||
|
||||
return Ok(movie);
|
||||
RadarrMovie movie = (RadarrMovie)radarrMovieInfoResult.Value;
|
||||
|
||||
var uriBuilder = new UriBuilder($"{Configuration.RadarrAddress}/api/v3/movie/{movie.Id}");
|
||||
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
|
||||
|
||||
query["deleteFiles"] = "true";
|
||||
query["addImportExclusion"] = "true";
|
||||
|
||||
uriBuilder.Query = query.ToString();
|
||||
|
||||
using var request = new HttpRequestMessage(HttpMethod.Delete, uriBuilder.Uri);
|
||||
var response = await _httpClient.SendAsync(request).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user