mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
Added root folder and approving quality profiles in radarr #1065
This commit is contained in:
parent
10ef372cfd
commit
a93c18bc04
14 changed files with 395 additions and 32 deletions
|
@ -69,6 +69,7 @@ namespace Ombi.UI.Modules.Admin
|
|||
|
||||
|
||||
Post["/sonarrrootfolders"] = _ => GetSonarrRootFolders();
|
||||
Post["/radarrrootfolders"] = _ => GetSonarrRootFolders();
|
||||
|
||||
Get["/watcher", true] = async (x, ct) => await Watcher();
|
||||
Post["/watcher", true] = async (x, ct) => await SaveWatcher();
|
||||
|
@ -191,7 +192,22 @@ namespace Ombi.UI.Modules.Admin
|
|||
{
|
||||
var settings = this.Bind<SonarrSettings>();
|
||||
|
||||
var rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
||||
var rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
||||
|
||||
// set the cache
|
||||
if (rootFolders != null)
|
||||
{
|
||||
Cache.Set(CacheKeys.SonarrRootFolders, rootFolders);
|
||||
}
|
||||
|
||||
return Response.AsJson(rootFolders);
|
||||
}
|
||||
|
||||
private Response GetRadarrRootFolders()
|
||||
{
|
||||
var settings = this.Bind<RadarrSettings>();
|
||||
|
||||
var rootFolders = RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
||||
|
||||
// set the cache
|
||||
if (rootFolders != null)
|
||||
|
|
|
@ -69,7 +69,9 @@ namespace Ombi.UI.Modules
|
|||
IEmbyNotificationEngine embyEngine,
|
||||
ISecurityExtensions security,
|
||||
ISettingsService<CustomizationSettings> customSettings,
|
||||
ISettingsService<EmbySettings> embyS) : base("requests", prSettings, security)
|
||||
ISettingsService<EmbySettings> embyS,
|
||||
ISettingsService<RadarrSettings> radarr,
|
||||
IRadarrApi radarrApi) : base("requests", prSettings, security)
|
||||
{
|
||||
Service = service;
|
||||
PrSettings = prSettings;
|
||||
|
@ -87,6 +89,8 @@ namespace Ombi.UI.Modules
|
|||
EmbyNotificationEngine = embyEngine;
|
||||
CustomizationSettings = customSettings;
|
||||
EmbySettings = embyS;
|
||||
Radarr = radarr;
|
||||
RadarrApi = radarrApi;
|
||||
|
||||
Get["/", true] = async (x, ct) => await LoadRequests();
|
||||
Get["/movies", true] = async (x, ct) => await GetMovies();
|
||||
|
@ -115,8 +119,10 @@ namespace Ombi.UI.Modules
|
|||
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
||||
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
||||
private ISettingsService<RadarrSettings> Radarr { get; }
|
||||
private ISettingsService<EmbySettings> EmbySettings { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private IRadarrApi RadarrApi { get; }
|
||||
private ISickRageApi SickRageApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
|
@ -144,28 +150,58 @@ namespace Ombi.UI.Modules
|
|||
}
|
||||
|
||||
List<QualityModel> qualities = new List<QualityModel>();
|
||||
var rootFolders = new List<RootFolderModel>();
|
||||
|
||||
var radarr = await Radarr.GetSettingsAsync();
|
||||
if (IsAdmin)
|
||||
{
|
||||
var cpSettings = CpSettings.GetSettings();
|
||||
if (cpSettings.Enabled)
|
||||
try
|
||||
{
|
||||
try
|
||||
var cpSettings = await CpSettings.GetSettingsAsync();
|
||||
if (cpSettings.Enabled)
|
||||
{
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
||||
try
|
||||
{
|
||||
return await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey)).ConfigureAwait(false);
|
||||
});
|
||||
if (result != null)
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
||||
{
|
||||
return
|
||||
await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey))
|
||||
.ConfigureAwait(false);
|
||||
});
|
||||
if (result != null)
|
||||
{
|
||||
qualities =
|
||||
result.list.Select(x => new QualityModel {Id = x._id, Name = x.label}).ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
qualities = result.list.Select(x => new QualityModel { Id = x._id, Name = x.label }).ToList();
|
||||
Log.Info(e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
if (radarr.Enabled)
|
||||
{
|
||||
Log.Info(e);
|
||||
var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.RadarrRootFolders, async () =>
|
||||
{
|
||||
return await Task.Run(() => RadarrApi.GetRootFolders(radarr.ApiKey, radarr.FullUri));
|
||||
});
|
||||
|
||||
rootFolders =
|
||||
rootFoldersResult.Select(
|
||||
x => new RootFolderModel {Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace})
|
||||
.ToList();
|
||||
|
||||
var result = await Cache.GetOrSetAsync(CacheKeys.RadarrQualityProfiles, async () =>
|
||||
{
|
||||
return await Task.Run(() => RadarrApi.GetProfiles(radarr.ApiKey, radarr.FullUri));
|
||||
});
|
||||
qualities = result.Select(x => new QualityModel { Id = x.id.ToString(), Name = x.name }).ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -194,6 +230,9 @@ namespace Ombi.UI.Modules
|
|||
Denied = movie.Denied,
|
||||
DeniedReason = movie.DeniedReason,
|
||||
Qualities = qualities.ToArray(),
|
||||
HasRootFolders = rootFolders.Any(),
|
||||
RootFolders = rootFolders.ToArray(),
|
||||
CurrentRootPath = radarr.Enabled ? GetRootPath(movie.RootFolderSelected, radarr).Result : null
|
||||
}).ToList();
|
||||
|
||||
return Response.AsJson(viewModel);
|
||||
|
@ -313,6 +352,32 @@ namespace Ombi.UI.Modules
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<string> GetRootPath(int pathId, RadarrSettings radarrSettings)
|
||||
{
|
||||
var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.RadarrRootFolders, async () =>
|
||||
{
|
||||
return await Task.Run(() => RadarrApi.GetRootFolders(radarrSettings.ApiKey, radarrSettings.FullUri));
|
||||
});
|
||||
|
||||
foreach (var r in rootFoldersResult.Where(r => r.id == pathId))
|
||||
{
|
||||
return r.path;
|
||||
}
|
||||
|
||||
int outRoot;
|
||||
var defaultPath = int.TryParse(radarrSettings.RootPath, out outRoot);
|
||||
|
||||
if (defaultPath)
|
||||
{
|
||||
// Return default path
|
||||
return rootFoldersResult.FirstOrDefault(x => x.id.Equals(outRoot))?.path ?? string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return rootFoldersResult.FirstOrDefault()?.path ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Response> GetAlbumRequests()
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
|
|
|
@ -37,7 +37,8 @@ namespace Ombi.UI.Validators
|
|||
RuleFor(request => request.ApiKey).NotEmpty().WithMessage("You must specify a Api Key.");
|
||||
RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name.");
|
||||
RuleFor(request => request.Port).NotEmpty().WithMessage("You must specify a Port.");
|
||||
RuleFor(request => request.QualityProfile).NotEmpty().WithMessage("You must specify a Quality Profile.");
|
||||
RuleFor(request => request.QualityProfile).NotEmpty().NotNull().WithMessage("You must specify a Quality Profile.");
|
||||
RuleFor(request => request.RootPath).NotEmpty().NotNull().WithMessage("You must enter a root path.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,13 @@
|
|||
{
|
||||
port = Model.Port;
|
||||
}
|
||||
|
||||
var rootFolder = string.Empty;
|
||||
if (!string.IsNullOrEmpty(Model.RootPath))
|
||||
|
||||
{
|
||||
rootFolder = Model.RootPath.Replace("/", "//");
|
||||
}
|
||||
}
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
<form class="form-horizontal" method="POST" id="mainForm">
|
||||
|
@ -64,10 +71,17 @@
|
|||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="RootPath" class="control-label">Root save directory for Movies</label>
|
||||
<div>
|
||||
<input type="text" class="form-control form-control-custom " placeholder="C:\Media\Movies" id="RootPath" name="RootPath" value="@Model.RootPath">
|
||||
<label>Enter the root folder where movies are saved. For example <strong>C:\Media\Movies</strong>.</label>
|
||||
<button type="submit" id="getRootFolders" class="btn btn-primary-outline">Get Root Folders <div id="getRootFolderSpinner" /></button>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="selectRootFolder" class="control-label">Default Root Folders</label>
|
||||
<div id="rootFolders">
|
||||
<select class="form-control form-control-custom" id="selectRootFolder"></select>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -128,6 +142,39 @@
|
|||
}
|
||||
</text>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(Model.RootPath))
|
||||
{
|
||||
<text>
|
||||
|
||||
console.log('Hit root folders..');
|
||||
|
||||
var rootFolderSelected = '@rootFolder';
|
||||
if (!rootFolderSelected) {
|
||||
return;
|
||||
}
|
||||
var $form = $("#mainForm");
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
data: $form.serialize(),
|
||||
url: "sonarrrootfolders",
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
response.forEach(function(result) {
|
||||
$('#selectedRootFolder').html("");
|
||||
if (result.id == rootFolderSelected) {
|
||||
$("#selectRootFolder").append("<option selected='selected' value='" + result.id + "'>" + result.path + "</option>");
|
||||
} else {
|
||||
$("#selectRootFolder").append("<option value='" + result.id + "'>" + result.path + "</option>");
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(e) {
|
||||
console.log(e);
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
</text>
|
||||
}
|
||||
|
||||
|
||||
$('#save').click(function(e) {
|
||||
|
@ -138,11 +185,14 @@
|
|||
return;
|
||||
}
|
||||
var qualityProfile = $("#profiles option:selected").val();
|
||||
var rootFolder = $("#rootFolders option:selected").val();
|
||||
var rootFolderPath = $('#rootFolders option:selected').text();
|
||||
$('#fullRootPath').val(rootFolderPath);
|
||||
|
||||
var $form = $("#mainForm");
|
||||
|
||||
var data = $form.serialize();
|
||||
data = data + "&qualityProfile=" + qualityProfile;
|
||||
data = data + "&qualityProfile=" + qualityProfile + "&rootPath=" + rootFolder;
|
||||
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
|
@ -202,6 +252,45 @@
|
|||
});
|
||||
});
|
||||
|
||||
$('#getRootFolders').click(function (e) {
|
||||
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-spinner fa-spin");
|
||||
e.preventDefault();
|
||||
if (!$('#Ip').val()) {
|
||||
generateNotify("Please enter a valid IP/Hostname.", "warning");
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
return;
|
||||
}
|
||||
if (!$('#portNumber').val()) {
|
||||
generateNotify("Please enter a valid Port Number.", "warning");
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
return;
|
||||
}
|
||||
if (!$('#ApiKey').val()) {
|
||||
generateNotify("Please enter a valid ApiKey.", "warning");
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
return;
|
||||
}
|
||||
var $form = $("#mainForm");
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
data: $form.serialize(),
|
||||
url: "radarrrootfolders",
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
response.forEach(function (result) {
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-check");
|
||||
$("#selectRootFolder").append("<option value='" + result.id + "'>" + result.path + "</option>");
|
||||
});
|
||||
},
|
||||
error: function (e) {
|
||||
console.log(e);
|
||||
$('#getRootFolderSpinner').attr("class", "fa fa-times");
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var base = '@Html.GetBaseUrl()';
|
||||
$('#testRadarr').click(function (e) {
|
||||
|
||||
|
@ -213,7 +302,7 @@
|
|||
|
||||
var data = $form.serialize();
|
||||
data = data + "&qualityProfile=" + qualityProfile;
|
||||
|
||||
|
||||
var url = createBaseUrl(base, '/test/radarr');
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue