mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Fixed #1789
This commit is contained in:
parent
57b12f3664
commit
a5d83ed8d8
4 changed files with 83 additions and 12 deletions
|
@ -10,6 +10,9 @@ namespace Ombi.Api.Radarr
|
|||
Task<List<RadarrProfile>> GetProfiles(string apiKey, string baseUrl);
|
||||
Task<List<RadarrRootFolder>> GetRootFolders(string apiKey, string baseUrl);
|
||||
Task<SystemStatus> SystemStatus(string apiKey, string baseUrl);
|
||||
Task<MovieResponse> GetMovie(int id, string apiKey, string baseUrl);
|
||||
Task<MovieResponse> UpdateMovie(MovieResponse movie, string apiKey, string baseUrl);
|
||||
Task<bool> MovieSearch(int[] movieIds, string apiKey, string baseUrl);
|
||||
Task<RadarrAddMovieResponse> AddMovie(int tmdbId, string title, int year, int qualityId, string rootPath,string apiKey, string baseUrl, bool searchNow, string minimumAvailability);
|
||||
}
|
||||
}
|
17
src/Ombi.Api.Radarr/RadarrApi.CommandResult.cs
Normal file
17
src/Ombi.Api.Radarr/RadarrApi.CommandResult.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
namespace Ombi.Api.Radarr
|
||||
{
|
||||
public partial class RadarrApi
|
||||
{
|
||||
public class CommandResult
|
||||
{
|
||||
public string name { get; set; }
|
||||
public DateTime startedOn { get; set; }
|
||||
public DateTime stateChangeTime { get; set; }
|
||||
public bool sendUpdatesToClient { get; set; }
|
||||
public string state { get; set; }
|
||||
public int id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -10,7 +9,7 @@ using Ombi.Helpers;
|
|||
|
||||
namespace Ombi.Api.Radarr
|
||||
{
|
||||
public class RadarrApi : IRadarrApi
|
||||
public partial class RadarrApi : IRadarrApi
|
||||
{
|
||||
public RadarrApi(ILogger<RadarrApi> logger, IApi api)
|
||||
{
|
||||
|
@ -53,6 +52,23 @@ namespace Ombi.Api.Radarr
|
|||
return await Api.Request<List<MovieResponse>>(request);
|
||||
}
|
||||
|
||||
public async Task<MovieResponse> GetMovie(int id, string apiKey, string baseUrl)
|
||||
{
|
||||
var request = new Request($"/api/movie/{id}", baseUrl, HttpMethod.Get);
|
||||
AddHeaders(request, apiKey);
|
||||
|
||||
return await Api.Request<MovieResponse>(request);
|
||||
}
|
||||
|
||||
public async Task<MovieResponse> UpdateMovie(MovieResponse movie, string apiKey, string baseUrl)
|
||||
{
|
||||
var request = new Request($"/api/movie/", baseUrl, HttpMethod.Put);
|
||||
AddHeaders(request, apiKey);
|
||||
request.AddJsonBody(movie);
|
||||
|
||||
return await Api.Request<MovieResponse>(request);
|
||||
}
|
||||
|
||||
public async Task<RadarrAddMovieResponse> AddMovie(int tmdbId, string title, int year, int qualityId, string rootPath, string apiKey, string baseUrl, bool searchNow, string minimumAvailability)
|
||||
{
|
||||
var request = new Request("/api/movie", baseUrl, HttpMethod.Post);
|
||||
|
@ -103,6 +119,19 @@ namespace Ombi.Api.Radarr
|
|||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> MovieSearch(int[] movieIds, string apiKey, string baseUrl)
|
||||
{
|
||||
var result = await Command(apiKey, baseUrl, new { name = "MoviesSearch", movieIds });
|
||||
return result != null;
|
||||
}
|
||||
|
||||
private async Task<CommandResult> Command(string apiKey, string baseUrl, object body)
|
||||
{
|
||||
var request = new Request($"/api/Command/", baseUrl, HttpMethod.Post);
|
||||
request.AddHeader("X-Api-Key", apiKey);
|
||||
request.AddJsonBody(body);
|
||||
return await Api.Request<CommandResult>(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the required headers and also the authorization header
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Ombi.Core.Senders
|
|||
var dogSettings = await DogNzbSettings.GetSettingsAsync();
|
||||
if (dogSettings.Enabled)
|
||||
{
|
||||
await SendToDogNzb(model,dogSettings);
|
||||
await SendToDogNzb(model, dogSettings);
|
||||
return new SenderResult
|
||||
{
|
||||
Success = true,
|
||||
|
@ -95,11 +95,19 @@ namespace Ombi.Core.Senders
|
|||
}
|
||||
|
||||
var rootFolderPath = model.RootPathOverride <= 0 ? settings.DefaultRootPath : await RadarrRootPath(model.RootPathOverride, settings);
|
||||
var result = await RadarrApi.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year, qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly, settings.MinimumAvailability);
|
||||
|
||||
// Check if the movie already exists? Since it could be unmonitored
|
||||
var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);
|
||||
var existingMovie = movies.FirstOrDefault(x => x.tmdbId == model.TheMovieDbId);
|
||||
if (existingMovie == null)
|
||||
{
|
||||
var result = await RadarrApi.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
|
||||
qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
|
||||
settings.MinimumAvailability);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.Error?.message))
|
||||
{
|
||||
Log.LogError(LoggingEvents.RadarrCacher,result.Error.message);
|
||||
Log.LogError(LoggingEvents.RadarrCacher, result.Error.message);
|
||||
return new SenderResult { Success = false, Message = result.Error.message, Sent = false };
|
||||
}
|
||||
if (!string.IsNullOrEmpty(result.title))
|
||||
|
@ -108,6 +116,20 @@ namespace Ombi.Core.Senders
|
|||
}
|
||||
return new SenderResult { Success = true, Sent = false };
|
||||
}
|
||||
// We have the movie, check if we can request it or change the status
|
||||
if (!existingMovie.monitored)
|
||||
{
|
||||
// let's set it to monitored and search for it
|
||||
existingMovie.monitored = true;
|
||||
await RadarrApi.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);
|
||||
// Search for it
|
||||
await RadarrApi.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
|
||||
|
||||
return new SenderResult { Success = true, Sent = true };
|
||||
}
|
||||
|
||||
return new SenderResult { Success = false, Sent = false, Message = "Movie is already monitored" };
|
||||
}
|
||||
|
||||
private async Task<string> RadarrRootPath(int overrideId, RadarrSettings settings)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue