This commit is contained in:
Devin Buhl 2016-09-19 10:20:10 +00:00 committed by GitHub
commit 29d5506bf5
20 changed files with 325 additions and 30 deletions

View file

@ -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);

View file

@ -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" />

View file

@ -0,0 +1,38 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrProfile.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Collections.Generic;
namespace PlexRequests.Api.Models.Sonarr
{
public class SonarrRootFolder
{
public int id { get; set; }
public string path { get; set; }
public long freespace { get; set; }
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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; }
} }
} }

View file

@ -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

View file

@ -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]

View file

@ -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;

View file

@ -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);

View file

@ -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; }

View file

@ -0,0 +1,10 @@
namespace PlexRequests.UI.Models
{
public class RootFolderModel
{
public string Id { get; set; }
public string Path { get; set; }
public long FreeSpace { get; set; }
}
}

View file

@ -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()
{ {

View file

@ -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))

View file

@ -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();

View file

@ -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();

View file

@ -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" />

View file

@ -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();

View file

@ -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.");
} }
} }
} }

View file

@ -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();
@ -234,6 +276,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: "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");
}
});
});
var base = '@Html.GetBaseUrl()'; var base = '@Html.GetBaseUrl()';
$('#testSonarr').click(function (e) { $('#testSonarr').click(function (e) {