mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-22 22:23:34 -07:00
The begining of grabbing sonarr root folders and approving requests with sepecific root folders
This commit is contained in:
parent
a3d1cd1d2d
commit
05ded0df7d
18 changed files with 277 additions and 30 deletions
|
@ -35,7 +35,10 @@ namespace PlexRequests.Api.Interfaces
|
||||||
{
|
{
|
||||||
List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl);
|
List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
|
List<SonarrRootFolder> GetRootFolders(string apiKey, Uri baseUrl);
|
||||||
|
|
||||||
SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath,
|
SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath,
|
||||||
|
int rootFolderId,
|
||||||
int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true,
|
int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true,
|
||||||
bool searchForMissingEpisodes = false);
|
bool searchForMissingEpisodes = false);
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
<Compile Include="Sonarr\SonarrEpisodes.cs" />
|
<Compile Include="Sonarr\SonarrEpisodes.cs" />
|
||||||
<Compile Include="Sonarr\SonarrError.cs" />
|
<Compile Include="Sonarr\SonarrError.cs" />
|
||||||
<Compile Include="Sonarr\SonarrProfile.cs" />
|
<Compile Include="Sonarr\SonarrProfile.cs" />
|
||||||
|
<Compile Include="Sonarr\SonarrRootFolder.cs" />
|
||||||
<Compile Include="Sonarr\SystemStatus.cs" />
|
<Compile Include="Sonarr\SystemStatus.cs" />
|
||||||
<Compile Include="Tv\Authentication.cs" />
|
<Compile Include="Tv\Authentication.cs" />
|
||||||
<Compile Include="Tv\TvMazeEpisodes.cs" />
|
<Compile Include="Tv\TvMazeEpisodes.cs" />
|
||||||
|
|
|
@ -64,7 +64,24 @@ namespace PlexRequests.Api
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false)
|
|
||||||
|
public List<SonarrRootFolder> GetRootFolders(string apiKey, Uri baseUrl)
|
||||||
|
{
|
||||||
|
var request = new RestRequest { Resource = "/api/rootfolder", Method = Method.GET };
|
||||||
|
|
||||||
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
|
var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetRootFolders for Sonarr, Retrying {0}", timespan), new TimeSpan[] {
|
||||||
|
TimeSpan.FromSeconds (2),
|
||||||
|
TimeSpan.FromSeconds(5),
|
||||||
|
TimeSpan.FromSeconds(10)
|
||||||
|
});
|
||||||
|
|
||||||
|
var obj = policy.Execute(() => Api.ExecuteJson<List<SonarrRootFolder>>(request, baseUrl));
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int rootFolderId, int seasonCount, int[] seasons, string apiKey, Uri baseUrl, bool monitor = true, bool searchForMissingEpisodes = false)
|
||||||
{
|
{
|
||||||
Log.Debug("Adding series {0}", title);
|
Log.Debug("Adding series {0}", title);
|
||||||
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
|
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace PlexRequests.Core
|
||||||
public const string PlexEpisodes = nameof(PlexEpisodes);
|
public const string PlexEpisodes = nameof(PlexEpisodes);
|
||||||
public const string TvDbToken = nameof(TvDbToken);
|
public const string TvDbToken = nameof(TvDbToken);
|
||||||
public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles);
|
public const string SonarrQualityProfiles = nameof(SonarrQualityProfiles);
|
||||||
|
public const string SonarrRootFolders = nameof(SonarrRootFolders);
|
||||||
public const string SonarrQueued = nameof(SonarrQueued);
|
public const string SonarrQueued = nameof(SonarrQueued);
|
||||||
public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles);
|
public const string SickRageQualityProfiles = nameof(SickRageQualityProfiles);
|
||||||
public const string SickRageQueued = nameof(SickRageQueued);
|
public const string SickRageQueued = nameof(SickRageQueued);
|
||||||
|
|
|
@ -31,8 +31,10 @@ namespace PlexRequests.Core.SettingModels
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
public string QualityProfile { get; set; }
|
public string QualityProfile { get; set; }
|
||||||
public bool SeasonFolders { get; set; }
|
public string RootFolder { get; set; }
|
||||||
public string RootPath { get; set; }
|
public string RootPath { get; set; }
|
||||||
|
public bool SeasonFolders { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -135,6 +135,20 @@ namespace PlexRequests.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CacheRootFolders()
|
||||||
|
{
|
||||||
|
var mc = new MemoryCacheProvider();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Task.Run(() => { CacheSonarrRootFolders(mc); });
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Log.Error("Failed to cache quality profiles on startup!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void CacheSonarrQualityProfiles(MemoryCacheProvider cacheProvider)
|
private void CacheSonarrQualityProfiles(MemoryCacheProvider cacheProvider)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -157,6 +171,28 @@ namespace PlexRequests.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CacheSonarrRootFolders(MemoryCacheProvider cacheProvider)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log.Info("Executing GetSettings call to Sonarr for root folders");
|
||||||
|
var sonarrSettingsService = new SettingsServiceV2<SonarrSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
|
||||||
|
var sonarrSettings = sonarrSettingsService.GetSettings();
|
||||||
|
if (sonarrSettings.Enabled)
|
||||||
|
{
|
||||||
|
Log.Info("Begin executing GetSettings call to Sonarr for root folders");
|
||||||
|
SonarrApi sonarrApi = new SonarrApi();
|
||||||
|
var rootFolders = sonarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
|
cacheProvider.Set(CacheKeys.SonarrRootFolders, rootFolders);
|
||||||
|
Log.Info("Finished executing GetSettings call to Sonarr for root folders");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Failed to cache Sonarr quality profiles!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void CacheCouchPotatoQualityProfiles(MemoryCacheProvider cacheProvider)
|
private void CacheCouchPotatoQualityProfiles(MemoryCacheProvider cacheProvider)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -76,6 +76,7 @@ namespace PlexRequests.UI.Tests
|
||||||
It.IsAny<bool>(),
|
It.IsAny<bool>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<int>(),
|
||||||
It.IsAny<int[]>(),
|
It.IsAny<int[]>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<Uri>(),
|
It.IsAny<Uri>(),
|
||||||
|
@ -93,6 +94,7 @@ namespace PlexRequests.UI.Tests
|
||||||
It.IsAny<bool>(),
|
It.IsAny<bool>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<int>(),
|
||||||
It.IsAny<int[]>(),
|
It.IsAny<int[]>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<Uri>(),
|
It.IsAny<Uri>(),
|
||||||
|
@ -113,6 +115,7 @@ namespace PlexRequests.UI.Tests
|
||||||
It.IsAny<bool>(),
|
It.IsAny<bool>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
|
It.IsAny<int>(),
|
||||||
It.IsAny<int[]>(),
|
It.IsAny<int[]>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<Uri>(),
|
It.IsAny<Uri>(),
|
||||||
|
@ -142,19 +145,23 @@ namespace PlexRequests.UI.Tests
|
||||||
var model = F.Build<RequestedModel>().With(x => x.ProviderId, 1)
|
var model = F.Build<RequestedModel>().With(x => x.ProviderId, 1)
|
||||||
.With(x => x.Episodes, episodes).Create();
|
.With(x => x.Episodes, episodes).Create();
|
||||||
|
|
||||||
var result = await Sender.SendToSonarr(GetSonarrSettings(), model, "2");
|
var result = await Sender.SendToSonarr(GetSonarrSettings(), model, "2", "1");
|
||||||
|
|
||||||
Assert.That(result, Is.EqualTo(seriesResult));
|
Assert.That(result, Is.EqualTo(seriesResult));
|
||||||
SonarrMock.Verify(x => x.AddSeries(It.IsAny<int>(),
|
SonarrMock.Verify(x => x.AddSeries(
|
||||||
|
It.IsAny<int>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
It.IsAny<bool>(),
|
It.IsAny<bool>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
|
It.IsAny<int>(), // rootFolderId
|
||||||
It.IsAny<int>(),
|
It.IsAny<int>(),
|
||||||
It.IsAny<int[]>(),
|
It.IsAny<int[]>(),
|
||||||
It.IsAny<string>(),
|
It.IsAny<string>(),
|
||||||
It.IsAny<Uri>(),
|
It.IsAny<Uri>(),
|
||||||
true, It.IsAny<bool>()), Times.Once);
|
true,
|
||||||
|
It.IsAny<bool>()
|
||||||
|
), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -55,10 +55,10 @@ namespace PlexRequests.UI.Helpers
|
||||||
|
|
||||||
public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model)
|
public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model)
|
||||||
{
|
{
|
||||||
return await SendToSonarr(sonarrSettings, model, string.Empty);
|
return await SendToSonarr(sonarrSettings, model, string.Empty, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId)
|
public async Task<SonarrAddSeries> SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model, string qualityId, string rootFolderId)
|
||||||
{
|
{
|
||||||
var qualityProfile = 0;
|
var qualityProfile = 0;
|
||||||
var episodeRequest = model.Episodes.Any();
|
var episodeRequest = model.Episodes.Any();
|
||||||
|
@ -72,6 +72,17 @@ namespace PlexRequests.UI.Helpers
|
||||||
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
|
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rootFolder = 0;
|
||||||
|
if (!string.IsNullOrEmpty(rootFolderId))
|
||||||
|
{
|
||||||
|
int.TryParse(qualityId, out rootFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootFolder <= 0)
|
||||||
|
{
|
||||||
|
int.TryParse(sonarrSettings.RootFolder, out rootFolder);
|
||||||
|
}
|
||||||
|
|
||||||
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
||||||
|
|
||||||
if (episodeRequest)
|
if (episodeRequest)
|
||||||
|
@ -88,7 +99,9 @@ namespace PlexRequests.UI.Helpers
|
||||||
|
|
||||||
// Series doesn't exist, need to add it as unmonitored.
|
// Series doesn't exist, need to add it as unmonitored.
|
||||||
var addResult = await Task.Run(() => SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
|
var addResult = await Task.Run(() => SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
|
||||||
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, new int[0], sonarrSettings.ApiKey,
|
sonarrSettings.SeasonFolders, sonarrSettings.RootPath,
|
||||||
|
1, // rootFolderId
|
||||||
|
0, new int[0], sonarrSettings.ApiKey,
|
||||||
sonarrSettings.FullUri, false));
|
sonarrSettings.FullUri, false));
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,7 +173,9 @@ namespace PlexRequests.UI.Helpers
|
||||||
|
|
||||||
|
|
||||||
var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
|
var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
|
||||||
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.SeasonCount, model.SeasonList, sonarrSettings.ApiKey,
|
sonarrSettings.SeasonFolders, sonarrSettings.RootPath,
|
||||||
|
rootFolder,
|
||||||
|
model.SeasonCount, model.SeasonList, sonarrSettings.ApiKey,
|
||||||
sonarrSettings.FullUri, true, true);
|
sonarrSettings.FullUri, true, true);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -50,6 +50,7 @@ namespace PlexRequests.UI.ModelDataProviders
|
||||||
with.Property(x => x.SubDir).Description("Subdir/BaseUrl of Sonarr").Required(false);
|
with.Property(x => x.SubDir).Description("Subdir/BaseUrl of Sonarr").Required(false);
|
||||||
with.Property(x => x.ApiKey).Description("Sonarr's API key").Required(true);
|
with.Property(x => x.ApiKey).Description("Sonarr's API key").Required(true);
|
||||||
with.Property(x => x.QualityProfile).Description("Sonarr's quality profile").Required(true);
|
with.Property(x => x.QualityProfile).Description("Sonarr's quality profile").Required(true);
|
||||||
|
with.Property(x => x.RootFolder).Description("Sonarr's root folder").Required(true);
|
||||||
|
|
||||||
with.Property(x => x.SeasonFolders).Description("Sonarr's season folders").Required(false);
|
with.Property(x => x.SeasonFolders).Description("Sonarr's season folders").Required(false);
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace PlexRequests.UI.Models
|
||||||
public string TvSeriesRequestType { get; set; }
|
public string TvSeriesRequestType { get; set; }
|
||||||
public string MusicBrainzId { get; set; }
|
public string MusicBrainzId { get; set; }
|
||||||
public QualityModel[] Qualities { get; set; }
|
public QualityModel[] Qualities { get; set; }
|
||||||
|
public RootFolderModel[] RootFolders { get; set; }
|
||||||
public string ArtistName { get; set; }
|
public string ArtistName { get; set; }
|
||||||
public Store.EpisodesModel[] Episodes { get; set; }
|
public Store.EpisodesModel[] Episodes { get; set; }
|
||||||
public bool Denied { get; set; }
|
public bool Denied { get; set; }
|
||||||
|
|
|
@ -170,6 +170,7 @@ namespace PlexRequests.UI.Modules
|
||||||
Post["/sickrage"] = _ => SaveSickrage();
|
Post["/sickrage"] = _ => SaveSickrage();
|
||||||
|
|
||||||
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
|
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
|
||||||
|
Post["/sonarrrootfolders"] = _ => GetSonarrRootFolders();
|
||||||
Post["/cpprofiles", true] = async (x, ct) => await GetCpProfiles();
|
Post["/cpprofiles", true] = async (x, ct) => await GetCpProfiles();
|
||||||
Post["/cpapikey"] = x => GetCpApiKey();
|
Post["/cpapikey"] = x => GetCpApiKey();
|
||||||
|
|
||||||
|
@ -470,6 +471,19 @@ namespace PlexRequests.UI.Modules
|
||||||
return Response.AsJson(profiles);
|
return Response.AsJson(profiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Response GetSonarrRootFolders()
|
||||||
|
{
|
||||||
|
var settings = this.Bind<SonarrSettings>();
|
||||||
|
var rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
|
||||||
|
|
||||||
|
// set the cache
|
||||||
|
if (rootFolders != null)
|
||||||
|
{
|
||||||
|
Cache.Set(CacheKeys.SonarrRootFolders, rootFolders);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.AsJson(rootFolders);
|
||||||
|
}
|
||||||
|
|
||||||
private Negotiator EmailNotifications()
|
private Negotiator EmailNotifications()
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace PlexRequests.UI.Modules
|
||||||
HeadphonesSettings = hpSettings;
|
HeadphonesSettings = hpSettings;
|
||||||
HeadphoneApi = hpApi;
|
HeadphoneApi = hpApi;
|
||||||
|
|
||||||
Post["/approve", true] = async (x, ct) => await Approve((int)Request.Form.requestid, (string)Request.Form.qualityId);
|
Post["/approve", true] = async (x, ct) => await Approve((int)Request.Form.requestid, (string)Request.Form.qualityId, (string)Request.Form.rootFolderId);
|
||||||
Post["/deny", true] = async (x, ct) => await DenyRequest((int)Request.Form.requestid, (string)Request.Form.reason);
|
Post["/deny", true] = async (x, ct) => await DenyRequest((int)Request.Form.requestid, (string)Request.Form.reason);
|
||||||
Post["/approveall", true] = async (x, ct) => await ApproveAll();
|
Post["/approveall", true] = async (x, ct) => await ApproveAll();
|
||||||
Post["/approveallmovies", true] = async (x, ct) => await ApproveAllMovies();
|
Post["/approveallmovies", true] = async (x, ct) => await ApproveAllMovies();
|
||||||
|
@ -91,7 +91,7 @@ namespace PlexRequests.UI.Modules
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestId">The request identifier.</param>
|
/// <param name="requestId">The request identifier.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<Response> Approve(int requestId, string qualityId)
|
private async Task<Response> Approve(int requestId, string qualityId, string rootFolderId)
|
||||||
{
|
{
|
||||||
Log.Info("approving request {0}", requestId);
|
Log.Info("approving request {0}", requestId);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ namespace PlexRequests.UI.Modules
|
||||||
case RequestType.Movie:
|
case RequestType.Movie:
|
||||||
return await RequestMovieAndUpdateStatus(request, qualityId);
|
return await RequestMovieAndUpdateStatus(request, qualityId);
|
||||||
case RequestType.TvShow:
|
case RequestType.TvShow:
|
||||||
return await RequestTvAndUpdateStatus(request, qualityId);
|
return await RequestTvAndUpdateStatus(request, qualityId, rootFolderId);
|
||||||
case RequestType.Album:
|
case RequestType.Album:
|
||||||
return await RequestAlbumAndUpdateStatus(request);
|
return await RequestAlbumAndUpdateStatus(request);
|
||||||
default:
|
default:
|
||||||
|
@ -117,7 +117,7 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Response> RequestTvAndUpdateStatus(RequestedModel request, string qualityId)
|
private async Task<Response> RequestTvAndUpdateStatus(RequestedModel request, string qualityId, string rootFolderId)
|
||||||
{
|
{
|
||||||
var sender = new TvSender(SonarrApi, SickRageApi);
|
var sender = new TvSender(SonarrApi, SickRageApi);
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ namespace PlexRequests.UI.Modules
|
||||||
if (sonarrSettings.Enabled)
|
if (sonarrSettings.Enabled)
|
||||||
{
|
{
|
||||||
Log.Trace("Sending to Sonarr");
|
Log.Trace("Sending to Sonarr");
|
||||||
var result = await sender.SendToSonarr(sonarrSettings, request, qualityId);
|
var result = await sender.SendToSonarr(sonarrSettings, request, qualityId, rootFolderId);
|
||||||
Log.Trace("Sonarr Result: ");
|
Log.Trace("Sonarr Result: ");
|
||||||
Log.Trace(result.DumpJson());
|
Log.Trace(result.DumpJson());
|
||||||
if (!string.IsNullOrEmpty(result.title))
|
if (!string.IsNullOrEmpty(result.title))
|
||||||
|
|
|
@ -186,6 +186,37 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerable<RootFolderModel> rootFolders = new List<RootFolderModel>();
|
||||||
|
if (IsAdmin)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sonarrSettings = await SonarrSettings.GetSettingsAsync();
|
||||||
|
if (sonarrSettings.Enabled)
|
||||||
|
{
|
||||||
|
var result = Cache.GetOrSetAsync(CacheKeys.SonarrRootFolders, async () =>
|
||||||
|
{
|
||||||
|
return await Task.Run(() => SonarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri));
|
||||||
|
});
|
||||||
|
rootFolders = result.Result.Select(x => new RootFolderModel { Id = x.id.ToString(), Path = x.path }).ToList();
|
||||||
|
}
|
||||||
|
// @TODO Sick Rage Root Folders
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// var sickRageSettings = await SickRageSettings.GetSettingsAsync();
|
||||||
|
// if (sickRageSettings.Enabled)
|
||||||
|
// {
|
||||||
|
// qualities = sickRageSettings.Qualities.Select(x => new QualityModel { Id = x.Key, Name = x.Value }).ToList();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Info(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var viewModel = dbTv.Select(tv => new RequestViewModel
|
var viewModel = dbTv.Select(tv => new RequestViewModel
|
||||||
{
|
{
|
||||||
ProviderId = tv.ProviderId,
|
ProviderId = tv.ProviderId,
|
||||||
|
@ -209,6 +240,7 @@ namespace PlexRequests.UI.Modules
|
||||||
IssueId = tv.IssueId,
|
IssueId = tv.IssueId,
|
||||||
TvSeriesRequestType = tv.SeasonsRequested,
|
TvSeriesRequestType = tv.SeasonsRequested,
|
||||||
Qualities = qualities.ToArray(),
|
Qualities = qualities.ToArray(),
|
||||||
|
RootFolders = rootFolders.ToArray(),
|
||||||
Episodes = tv.Episodes.ToArray(),
|
Episodes = tv.Episodes.ToArray(),
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
|
|
@ -230,6 +230,38 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IEnumerable<RootFolderModel> rootFolders = new List<RootFolderModel>();
|
||||||
|
if (IsAdmin)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sonarrSettings = await SonarrSettings.GetSettingsAsync();
|
||||||
|
if (sonarrSettings.Enabled)
|
||||||
|
{
|
||||||
|
var result = Cache.GetOrSetAsync(CacheKeys.SonarrRootFolders, async () =>
|
||||||
|
{
|
||||||
|
return await Task.Run(() => SonarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri));
|
||||||
|
});
|
||||||
|
rootFolders = result.Result.Select(x => new RootFolderModel { Id = x.id.ToString(), Path = x.path }).ToList();
|
||||||
|
}
|
||||||
|
// @TODO Sick Rage Root Folders
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// var sickRageSettings = await SickRageSettings.GetSettingsAsync();
|
||||||
|
// if (sickRageSettings.Enabled)
|
||||||
|
// {
|
||||||
|
// qualities = sickRageSettings.Qualities.Select(x => new QualityModel { Id = x.Key, Name = x.Value }).ToList();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Info(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var viewModel = dbTv.Select(tv => new RequestViewModel
|
var viewModel = dbTv.Select(tv => new RequestViewModel
|
||||||
{
|
{
|
||||||
ProviderId = tv.ProviderId,
|
ProviderId = tv.ProviderId,
|
||||||
|
@ -255,6 +287,7 @@ namespace PlexRequests.UI.Modules
|
||||||
DeniedReason = tv.DeniedReason,
|
DeniedReason = tv.DeniedReason,
|
||||||
TvSeriesRequestType = tv.SeasonsRequested,
|
TvSeriesRequestType = tv.SeasonsRequested,
|
||||||
Qualities = qualities.ToArray(),
|
Qualities = qualities.ToArray(),
|
||||||
|
RootFolders = rootFolders.ToArray(),
|
||||||
Episodes = tv.Episodes.ToArray(),
|
Episodes = tv.Episodes.ToArray(),
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
|
|
@ -233,6 +233,7 @@
|
||||||
<Compile Include="Models\LandingPageViewModel.cs" />
|
<Compile Include="Models\LandingPageViewModel.cs" />
|
||||||
<Compile Include="Models\MovieSearchType.cs" />
|
<Compile Include="Models\MovieSearchType.cs" />
|
||||||
<Compile Include="Models\QualityModel.cs" />
|
<Compile Include="Models\QualityModel.cs" />
|
||||||
|
<Compile Include="Models\RootFolderModel.cs" />
|
||||||
<Compile Include="Models\ScheduledJobsViewModel.cs" />
|
<Compile Include="Models\ScheduledJobsViewModel.cs" />
|
||||||
<Compile Include="Models\SearchViewModel.cs" />
|
<Compile Include="Models\SearchViewModel.cs" />
|
||||||
<Compile Include="Models\SearchMusicViewModel.cs" />
|
<Compile Include="Models\SearchMusicViewModel.cs" />
|
||||||
|
|
|
@ -75,6 +75,7 @@ namespace PlexRequests.UI
|
||||||
var s = new Setup();
|
var s = new Setup();
|
||||||
var cn = s.SetupDb(baseUrl);
|
var cn = s.SetupDb(baseUrl);
|
||||||
s.CacheQualityProfiles();
|
s.CacheQualityProfiles();
|
||||||
|
s.CacheRootFolders();
|
||||||
ConfigureTargets(cn);
|
ConfigureTargets(cn);
|
||||||
SetupLogging();
|
SetupLogging();
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ namespace PlexRequests.UI.Validators
|
||||||
RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name.");
|
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.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().WithMessage("You must specify a Quality Profile.");
|
||||||
|
RuleFor(request => request.RootFolder).NotEmpty().WithMessage("You must specify a Root Folder.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -80,12 +80,24 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
<div>
|
||||||
|
<button type="submit" id="getRootFolders" class="btn btn-primary-outline">Get RootFolders <div id="getRootFolderSpinner" /></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="selectRootFolder" class="control-label">Root Folders</label>
|
||||||
|
<div id="rootFolders">
|
||||||
|
<select class="form-control form-control-custom" id="selectRootFolder"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@*<div class="form-group">
|
||||||
<label for="RootPath" class="control-label">Root save directory for TV shows</label>
|
<label for="RootPath" class="control-label">Root save directory for TV shows</label>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" class="form-control form-control-custom " placeholder="C:\Media\Tv" id="RootPath" name="RootPath" value="@Model.RootPath">
|
<input type="text" class="form-control form-control-custom " placeholder="C:\Media\Tv" 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>
|
<label>Enter the root folder where tv shows are saved. For example <strong>C:\Media\TV</strong>.</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>*@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
|
@ -126,12 +138,10 @@
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(Model.QualityProfile))
|
@if (!string.IsNullOrEmpty(Model.QualityProfile))
|
||||||
{
|
{
|
||||||
|
|
||||||
<text>
|
<text>
|
||||||
|
|
||||||
preLoad();
|
console.log('Hit profiles..');
|
||||||
|
|
||||||
function preLoad() {
|
|
||||||
var qualitySelected = @Model.QualityProfile;
|
var qualitySelected = @Model.QualityProfile;
|
||||||
if (!qualitySelected) {
|
if (!qualitySelected) {
|
||||||
return;
|
return;
|
||||||
|
@ -145,7 +155,6 @@
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
response.forEach(function(result) {
|
response.forEach(function(result) {
|
||||||
if (result.id == qualitySelected) {
|
if (result.id == qualitySelected) {
|
||||||
|
|
||||||
$("#select").append("<option selected='selected' value='" + result.id + "'>" + result.name + "</option>");
|
$("#select").append("<option selected='selected' value='" + result.id + "'>" + result.name + "</option>");
|
||||||
} else {
|
} else {
|
||||||
$("#select").append("<option value='" + result.id + "'>" + result.name + "</option>");
|
$("#select").append("<option value='" + result.id + "'>" + result.name + "</option>");
|
||||||
|
@ -157,11 +166,44 @@
|
||||||
generateNotify("Something went wrong!", "danger");
|
generateNotify("Something went wrong!", "danger");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
</text>
|
||||||
</text>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@if (!string.IsNullOrEmpty(Model.RootFolder))
|
||||||
|
{
|
||||||
|
<text>
|
||||||
|
|
||||||
|
console.log('Hit root folders..');
|
||||||
|
|
||||||
|
var rootFolderSelected = @Model.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) {
|
||||||
|
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) {
|
$('#save').click(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var port = $('#portNumber').val();
|
var port = $('#portNumber').val();
|
||||||
|
@ -201,17 +243,17 @@
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!$('#Ip').val()) {
|
if (!$('#Ip').val()) {
|
||||||
generateNotify("Please enter a valid IP/Hostname.", "warning");
|
generateNotify("Please enter a valid IP/Hostname.", "warning");
|
||||||
$('#getSpinner').attr("class", "fa fa-times");
|
$('#getSpinner').attr("class", "fa fa-times");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!$('#portNumber').val()) {
|
if (!$('#portNumber').val()) {
|
||||||
generateNotify("Please enter a valid Port Number.", "warning");
|
generateNotify("Please enter a valid Port Number.", "warning");
|
||||||
$('#getSpinner').attr("class", "fa fa-times");
|
$('#getSpinner').attr("class", "fa fa-times");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!$('#ApiKey').val()) {
|
if (!$('#ApiKey').val()) {
|
||||||
generateNotify("Please enter a valid ApiKey.", "warning");
|
generateNotify("Please enter a valid ApiKey.", "warning");
|
||||||
$('#getSpinner').attr("class", "fa fa-times");
|
$('#getSpinner').attr("class", "fa fa-times");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var $form = $("#mainForm");
|
var $form = $("#mainForm");
|
||||||
|
@ -222,13 +264,52 @@
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
response.forEach(function (result) {
|
response.forEach(function (result) {
|
||||||
$('#getSpinner').attr("class", "fa fa-check");
|
$('#getSpinner').attr("class", "fa fa-check");
|
||||||
$("#select").append("<option value='" + result.id + "'>" + result.name + "</option>");
|
$("#select").append("<option value='" + result.id + "'>" + result.name + "</option>");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function (e) {
|
error: function (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
$('#getSpinner').attr("class", "fa fa-times");
|
$('#getSpinner').attr("class", "fa fa-times");
|
||||||
|
generateNotify("Something went wrong!", "danger");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#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: "sonarrrootfolders",
|
||||||
|
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");
|
generateNotify("Something went wrong!", "danger");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -245,7 +326,7 @@
|
||||||
|
|
||||||
var data = $form.serialize();
|
var data = $form.serialize();
|
||||||
data = data + "&qualityProfile=" + qualityProfile;
|
data = data + "&qualityProfile=" + qualityProfile;
|
||||||
|
|
||||||
var url = createBaseUrl(base, '/test/sonarr');
|
var url = createBaseUrl(base, '/test/sonarr');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: $form.prop("method"),
|
type: $form.prop("method"),
|
||||||
|
@ -256,16 +337,16 @@
|
||||||
console.log(response);
|
console.log(response);
|
||||||
if (response.result === true) {
|
if (response.result === true) {
|
||||||
generateNotify(response.message, "success");
|
generateNotify(response.message, "success");
|
||||||
$('#spinner').attr("class", "fa fa-check");
|
$('#spinner').attr("class", "fa fa-check");
|
||||||
} else {
|
} else {
|
||||||
generateNotify(response.message, "warning");
|
generateNotify(response.message, "warning");
|
||||||
$('#spinner').attr("class", "fa fa-times");
|
$('#spinner').attr("class", "fa fa-times");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (e) {
|
error: function (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
generateNotify("Something went wrong!", "danger");
|
generateNotify("Something went wrong!", "danger");
|
||||||
$('#spinner').attr("class", "fa fa-times");
|
$('#spinner').attr("class", "fa fa-times");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue