Added the Movie Sender, Movies will be sent to Radarr now #865

This commit is contained in:
Jamie.Rees 2017-06-07 15:07:41 +01:00
parent 2c4ef05af1
commit 4c797733ca
13 changed files with 223 additions and 59 deletions

View file

@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Ombi.Api.Radarr.Models;
using Ombi.Helpers;
namespace Ombi.Api.Radarr
{
@ -50,6 +53,56 @@ namespace Ombi.Api.Radarr
return await Api.Request<List<MovieResponse>>(request);
}
public async Task<RadarrAddMovieResponse> AddMovie(int tmdbId, string title, int year, int qualityId, string rootPath, string apiKey, string baseUrl, bool searchNow = false)
{
var request = new Request(baseUrl, "/api/movie", HttpMethod.Post);
var options = new RadarrAddMovieResponse
{
title = title,
tmdbId = tmdbId,
qualityProfileId = qualityId,
rootFolderPath = rootPath,
titleSlug = title,
monitored = true,
year = year
};
if (searchNow)
{
options.addOptions = new RadarrAddOptions
{
searchForMovie = true
};
}
request.AddHeader("X-Api-Key", apiKey);
request.AddJsonBody(options);
try
{
var response = await Api.Request(request);
if (response.Contains("\"message\":"))
{
var error = JsonConvert.DeserializeObject<RadarrError>(response);
return new RadarrAddMovieResponse { Error = error };
}
if (response.Contains("\"errorMessage\":"))
{
var error = JsonConvert.DeserializeObject<List<RadarrErrorResponse>>(response).FirstOrDefault();
return new RadarrAddMovieResponse { Error = new RadarrError { message = error?.errorMessage } };
}
return JsonConvert.DeserializeObject<RadarrAddMovieResponse>(response);
}
catch (JsonSerializationException jse)
{
Logger.LogError(LoggingEvents.RadarrApiException,jse, "Error When adding movie to Radarr");
}
return null;
}
/// <summary>
/// Adds the required headers and also the authorization header
/// </summary>