mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 06:00:50 -07:00
Wow, that was a lot of work.
- So, I have now finished #40. - Fixed a bug where we was not choosing the correct tv series (Because of TVMaze) - Fixed a bug when checking for plex titles - Fixed a bug where the wrong issue would clean on the UI (DB was correct) - Refactored how we send tv shows - And too many small changes to count.
This commit is contained in:
parent
803b12da0f
commit
9402d1409e
21 changed files with 510 additions and 122 deletions
|
@ -27,7 +27,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using System.Linq.Expressions;
|
||||
using Nancy;
|
||||
using Nancy.Security;
|
||||
|
||||
|
@ -36,7 +36,9 @@ using PlexRequests.Api;
|
|||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
|
@ -45,7 +47,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
|
||||
public ApprovalModule(IRequestService service, ISettingsService<CouchPotatoSettings> cpService, ICouchPotatoApi cpApi, ISonarrApi sonarrApi,
|
||||
ISettingsService<SonarrSettings> sonarrSettings) : base("approval")
|
||||
ISettingsService<SonarrSettings> sonarrSettings, ISickRageApi srApi, ISettingsService<SickRageSettings> srSettings) : base("approval")
|
||||
{
|
||||
this.RequiresAuthentication();
|
||||
|
||||
|
@ -54,6 +56,8 @@ namespace PlexRequests.UI.Modules
|
|||
CpApi = cpApi;
|
||||
SonarrApi = sonarrApi;
|
||||
SonarrSettings = sonarrSettings;
|
||||
SickRageApi = srApi;
|
||||
SickRageSettings = srSettings;
|
||||
|
||||
Post["/approve"] = parameters => Approve((int)Request.Form.requestid);
|
||||
Post["/approveall"] = x => ApproveAll();
|
||||
|
@ -63,8 +67,10 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
||||
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private ISickRageApi SickRageApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -74,6 +80,7 @@ namespace PlexRequests.UI.Modules
|
|||
/// <returns></returns>
|
||||
private Response Approve(int requestId)
|
||||
{
|
||||
Log.Info("approving request {0}", requestId);
|
||||
if (!Context.CurrentUser.IsAuthenticated())
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "You are not an Admin, so you cannot approve any requests." });
|
||||
|
@ -100,20 +107,63 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response RequestTvAndUpdateStatus(RequestedModel request)
|
||||
{
|
||||
var sonarrSettings = SonarrSettings.GetSettings();
|
||||
int qualityProfile;
|
||||
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
|
||||
var result = SonarrApi.AddSeries(request.ProviderId, request.Title, qualityProfile,
|
||||
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, request.LatestTv, sonarrSettings.ApiKey,
|
||||
sonarrSettings.FullUri);
|
||||
var sender = new TvSender(SonarrApi, SickRageApi);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.title))
|
||||
var sonarrSettings = SonarrSettings.GetSettings();
|
||||
if (sonarrSettings.Enabled)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
Log.Trace("Sending to Sonarr");
|
||||
var result = sender.SendToSonarr(sonarrSettings, request);
|
||||
Log.Trace("Sonarr Result: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
if (!string.IsNullOrEmpty(result.title))
|
||||
{
|
||||
Log.Info("Sent successfully, Approving request now.");
|
||||
request.Approved = true;
|
||||
var requestResult = Service.UpdateRequest(request);
|
||||
Log.Trace("Approval result: {0}",requestResult);
|
||||
if (requestResult)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Updated Sonarr but could not approve it in PlexRequests :("});
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = false,
|
||||
Message = "Could not add the series to Sonarr"
|
||||
});
|
||||
}
|
||||
|
||||
var srSettings = SickRageSettings.GetSettings();
|
||||
if (srSettings.Enabled)
|
||||
{
|
||||
Log.Trace("Sending to SickRage");
|
||||
var result = sender.SendToSickRage(srSettings, request);
|
||||
Log.Trace("SickRage Result: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
if (result?.result == "success")
|
||||
{
|
||||
Log.Info("Sent successfully, Approving request now.");
|
||||
request.Approved = true;
|
||||
var requestResult = Service.UpdateRequest(request);
|
||||
Log.Trace("Approval result: {0}", requestResult);
|
||||
if (requestResult)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Updated SickRage but could not approve it in PlexRequests :(" });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = false,
|
||||
Message = result?.message != null ? "<b>Message From SickRage: </b>" + result.message : "Could not add the series to SickRage"
|
||||
});
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = false, Message = "Could not add the series to Sonarr"
|
||||
Result = false,
|
||||
Message = "SickRage or Sonarr are not set up!"
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -184,12 +234,42 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Could not approve send the movie {0} to couch potato!", r.Title);
|
||||
Log.Error("Could not approve and send the movie {0} to couch potato!", r.Title);
|
||||
}
|
||||
}
|
||||
if (r.Type == RequestType.TvShow)
|
||||
{
|
||||
// TODO
|
||||
var sender = new TvSender(SonarrApi,SickRageApi);
|
||||
var sr = SickRageSettings.GetSettings();
|
||||
var sonarr = SonarrSettings.GetSettings();
|
||||
if (sr.Enabled)
|
||||
{
|
||||
var result = sender.SendToSickRage(sr, r);
|
||||
if (result?.result == "success")
|
||||
{
|
||||
r.Approved = true;
|
||||
updatedRequests.Add(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Could not approve and send the TV {0} to SickRage!", r.Title);
|
||||
Log.Error("SickRage Message: {0}", result?.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (sonarr.Enabled)
|
||||
{
|
||||
var result = sender.SendToSonarr(sonarr, r);
|
||||
if (result != null)
|
||||
{
|
||||
r.Approved = true;
|
||||
updatedRequests.Add(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try
|
||||
|
@ -208,7 +288,6 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
}
|
||||
|
||||
|
||||
private bool SendMovie(CouchPotatoSettings settings, RequestedModel r, ICouchPotatoApi cp)
|
||||
{
|
||||
Log.Info("Adding movie to CP : {0}", r.Title);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue