mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Added the Movie Sender, Movies will be sent to Radarr now #865
This commit is contained in:
parent
2c4ef05af1
commit
4c797733ca
13 changed files with 223 additions and 59 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue