mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 13:53:19 -07:00
Added the support for TV Series integrating with Sonarr
This commit is contained in:
parent
31615ff69c
commit
5dd9885885
15 changed files with 250 additions and 10 deletions
|
@ -44,13 +44,16 @@ namespace PlexRequests.UI.Modules
|
|||
public class ApprovalModule : BaseModule
|
||||
{
|
||||
|
||||
public ApprovalModule(IRepository<RequestedModel> service, ISettingsService<CouchPotatoSettings> cpService, ICouchPotatoApi cpApi) : base("approval")
|
||||
public ApprovalModule(IRepository<RequestedModel> service, ISettingsService<CouchPotatoSettings> cpService, ICouchPotatoApi cpApi, ISonarrApi sonarrApi,
|
||||
ISettingsService<SonarrSettings> sonarrSettings) : base("approval")
|
||||
{
|
||||
this.RequiresAuthentication();
|
||||
|
||||
Service = service;
|
||||
CpService = cpService;
|
||||
CpApi = cpApi;
|
||||
SonarrApi = sonarrApi;
|
||||
SonarrSettings = sonarrSettings;
|
||||
|
||||
Post["/approve"] = parameters => Approve((int)Request.Form.requestid);
|
||||
Post["/approveall"] = x => ApproveAll();
|
||||
|
@ -59,7 +62,9 @@ namespace PlexRequests.UI.Modules
|
|||
private IRepository<RequestedModel> Service { get; set; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private ISettingsService<SonarrSettings> SonarrSettings { get; set; }
|
||||
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
||||
private ISonarrApi SonarrApi { get; set; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -95,8 +100,21 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response RequestTvAndUpdateStatus(RequestedModel request)
|
||||
{
|
||||
// TODO
|
||||
return Response.AsJson(new JsonResponseModel());
|
||||
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);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.title))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = false, Message = "Could not add the series to Sonarr"
|
||||
});
|
||||
}
|
||||
|
||||
private Response RequestMovieAndUpdateStatus(RequestedModel request)
|
||||
|
|
|
@ -32,6 +32,7 @@ using Nancy.Responses.Negotiation;
|
|||
using NLog;
|
||||
|
||||
using PlexRequests.Api;
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
|
@ -46,7 +47,7 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings,
|
||||
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
|
||||
IRequestService request) : base("search")
|
||||
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings) : base("search")
|
||||
{
|
||||
CpService = cpSettings;
|
||||
PrService = prSettings;
|
||||
|
@ -55,6 +56,8 @@ namespace PlexRequests.UI.Modules
|
|||
Cache = cache;
|
||||
Checker = checker;
|
||||
RequestService = request;
|
||||
SonarrApi = sonarrApi;
|
||||
SonarrService = sonarrSettings;
|
||||
|
||||
Get["/"] = parameters => RequestLoad();
|
||||
|
||||
|
@ -68,11 +71,13 @@ namespace PlexRequests.UI.Modules
|
|||
Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (bool)Request.Form.latest);
|
||||
}
|
||||
private TheMovieDbApi MovieApi { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private TheTvDbApi TvApi { get; }
|
||||
private IRequestService RequestService { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
||||
private ISettingsService<PlexRequestSettings> PrService { get; }
|
||||
private ISettingsService<SonarrSettings> SonarrService { get; }
|
||||
private IAvailabilityChecker Checker { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
|
||||
|
@ -257,10 +262,26 @@ namespace PlexRequests.UI.Modules
|
|||
RequestedDate = DateTime.Now,
|
||||
Approved = false,
|
||||
RequestedBy = Session[SessionKeys.UsernameKey].ToString(),
|
||||
Issues = IssueState.None
|
||||
Issues = IssueState.None,
|
||||
LatestTv = latest
|
||||
};
|
||||
|
||||
RequestService.AddRequest(showId, model);
|
||||
|
||||
var settings = PrService.GetSettings();
|
||||
if (!settings.RequireApproval)
|
||||
{
|
||||
var sonarrSettings = SonarrService.GetSettings();
|
||||
int qualityProfile;
|
||||
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
|
||||
var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
|
||||
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.LatestTv, sonarrSettings.ApiKey,
|
||||
sonarrSettings.FullUri);
|
||||
Log.Info("Added series {0} to Sonarr, Result: {1}", model.Title, result);
|
||||
Log.Trace("Model sent to Sonarr: ");
|
||||
Log.Trace(model.DumpJson());
|
||||
}
|
||||
|
||||
return Response.AsJson(new { Result = true });
|
||||
}
|
||||
private string GetAuthToken(TheTvDbApi api)
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<div class="form-group">
|
||||
<label for="authToken" class="control-label">Plex Authorization Token</label>
|
||||
<div class="">
|
||||
<input type="text" class="form-control-custom form-control " id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@Model.PlexAuthToken">
|
||||
<input type="text" class="form-control-custom form-control" id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@Model.PlexAuthToken">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<div class="">
|
||||
<button id="requestToken" class="btn btn-primary-outline-outline">Request Token <i class="fa fa-key"></i></button>
|
||||
<button id="requestToken" class="btn btn-primary-outline">Request Token <i class="fa fa-key"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
int port;
|
||||
if (Model.Port == 0)
|
||||
{
|
||||
port = 80;
|
||||
port = 8989;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -50,6 +50,31 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="RootPath" class="control-label">Root save directory for TV shows</label>
|
||||
<div>
|
||||
<input type="text" class="form-control form-control-custom " id="RootPath" name="RootPath" value="@Model.RootPath">
|
||||
<label>Enter the root folder where tv shows are saved. For example <strong>C:\Media\TV</strong>.</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@if (Model.SeasonFolders)
|
||||
{
|
||||
<input type="checkbox" id="SeasonFolders" name="SeasonFolders" checked="checked">
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="checkbox" id="SeasonFolders" name="SeasonFolders">
|
||||
}
|
||||
<label>Enable season folders</label>
|
||||
<label>Enabled Season Folders to organize seasons into individual folders within a show.</label>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="save" type="submit" class="btn btn-primary-outline ">Submit</button>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue