Added the code to get the quality profiles from Sonarr

Started plugging that into the UI
pull/13/head
Jamie Rees 9 years ago
parent 452ad07ba0
commit 640e76e167

@ -48,6 +48,7 @@
<Compile Include="Plex\PlexSearch.cs" />
<Compile Include="Plex\PlexUserRequest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sonarr\SonarrProfile.cs" />
<Compile Include="Tv\Authentication.cs" />
<Compile Include="Tv\TvSearchResult.cs" />
<Compile Include="Tv\TvShow.cs" />

@ -0,0 +1,57 @@
#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 Cutoff
{
public int id { get; set; }
public string name { get; set; }
}
public class Quality
{
public int id { get; set; }
public string name { get; set; }
}
public class Item
{
public Quality quality { get; set; }
public bool allowed { get; set; }
}
public class SonarrProfile
{
public string name { get; set; }
public Cutoff cutoff { get; set; }
public List<Item> items { get; set; }
public int id { get; set; }
}
}

@ -66,6 +66,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApiRequest.cs" />
<Compile Include="SonarrApi.cs" />
<Compile Include="CouchPotatoApi.cs" />
<Compile Include="MovieBase.cs" />
<Compile Include="PlexApi.cs" />

@ -0,0 +1,58 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CouchPotatoApi.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;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Sonarr;
using RestSharp;
namespace PlexRequests.Api
{
public class SonarrApi
{
public SonarrApi()
{
Api = new ApiRequest();
}
private ApiRequest Api { get; set; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public List<SonarrProfile> GetProfiles(string apiKey, Uri baseUrl)
{
var request = new RestRequest { Resource = "/api/profile", Method = Method.GET};
request.AddHeader("X-Api-Key", apiKey);
var obj = Api.ExecuteJson<List<SonarrProfile>>(request, baseUrl);
return obj;
}
}
}

@ -24,6 +24,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Newtonsoft.Json;
using PlexRequests.Helpers;
namespace PlexRequests.Core.SettingModels
{
public class SonarrSettings : Settings
@ -31,6 +36,16 @@ namespace PlexRequests.Core.SettingModels
public string Ip { get; set; }
public int Port { get; set; }
public string ApiKey { get; set; }
public bool Enabled { get; set; }
public string QualityProfile { get; set; }
[JsonIgnore]
public Uri FullUri
{
get
{
var formatted = Ip.ReturnUri(Port);
return formatted;
}
}
}
}

@ -69,6 +69,7 @@ namespace PlexRequests.UI
container.Register<ISettingsService<CouchPotatoSettings>, SettingsServiceV2<CouchPotatoSettings>>();
container.Register<ISettingsService<AuthenticationSettings>, SettingsServiceV2<AuthenticationSettings>>();
container.Register<ISettingsService<PlexSettings>, SettingsServiceV2<PlexSettings>>();
container.Register<ISettingsService<SonarrSettings>, SettingsServiceV2<SonarrSettings>>();
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
container.Register<IRequestService, RequestService>();

@ -49,14 +49,20 @@ namespace PlexRequests.UI.Modules
private ISettingsService<CouchPotatoSettings> CpService { get; set; }
private ISettingsService<AuthenticationSettings> AuthService { get; set; }
private ISettingsService<PlexSettings> PlexService { get; set; }
private ISettingsService<SonarrSettings> SonarrService { get; set; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public AdminModule(ISettingsService<PlexRequestSettings> rpService, ISettingsService<CouchPotatoSettings> cpService, ISettingsService<AuthenticationSettings> auth, ISettingsService<PlexSettings> plex) : base("admin")
public AdminModule(ISettingsService<PlexRequestSettings> rpService,
ISettingsService<CouchPotatoSettings> cpService,
ISettingsService<AuthenticationSettings> auth
, ISettingsService<PlexSettings> plex,
ISettingsService<SonarrSettings> sonarr ) : base("admin")
{
RpService = rpService;
CpService = cpService;
AuthService = auth;
PlexService = plex;
SonarrService = sonarr;
#if !DEBUG
this.RequiresAuthentication();
@ -77,6 +83,11 @@ namespace PlexRequests.UI.Modules
Get["/plex"] = _ => Plex();
Post["/plex"] = _ => SavePlex();
Get["/sonarr"] = _ => Sonarr();
Post["/sonarr"] = _ => SaveSonarr();
Get["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
}
private Negotiator Authentication()
@ -201,5 +212,29 @@ namespace PlexRequests.UI.Modules
return Context.GetRedirect("~/admin/plex");
}
private Negotiator Sonarr()
{
var settings = SonarrService.GetSettings();
return View["Sonarr", settings];
}
private Response SaveSonarr()
{
var plexSettings = this.Bind<SonarrSettings>();
SonarrService.SaveSettings(plexSettings);
return Context.GetRedirect("~/admin/Sonarr");
}
private Response GetSonarrQualityProfiles()
{
var settings = SonarrService.GetSettings();
var api = new SonarrApi();
var profiles = api.GetProfiles(settings.ApiKey, settings.FullUri);
return Response.AsJson(profiles);
}
}
}

@ -273,6 +273,9 @@
<Content Include="Views\Admin\Plex.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Admin\Sonarr.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>

@ -0,0 +1,84 @@
@Html.Partial("_Sidebar")
@{
int port;
if (Model.Port == 0)
{
port = 80;
}
else
{
port = Model.Port;
}
}
<div class="col-sm-8 col-sm-push-1">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset>
<legend>Sonarr Settings</legend>
<div class="form-group">
<label for="Ip" class="control-label">Sonarr Hostname or IP</label>
<div class="">
<input type="text" class="form-control form-control-custom " id="Ip" name="Ip" placeholder="localhost" value="@Model.Ip">
</div>
</div>
<div class="form-group">
<label for="portNumber" class="control-label">Port</label>
<div class="">
<input type="text" class="form-control form-control-custom " id="portNumber" name="Port" placeholder="Port Number" value="@port">
</div>
</div>
<div class="form-group">
<label for="ApiKey" class="control-label">Sonarr API Key</label>
<div>
<input type="text" class="form-control form-control-custom " id="ApiKey" name="ApiKey" value="@Model.ApiKey">
</div>
</div>
<div class="form-group">
<label for="select" class="control-label">Quality Profiles</label>
<div>
<select class="form-control" id="select">
</select>
</div>
</div>
<div class="form-group">
<div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
<script>
$(function () {
$.ajax({
type: "GET",
url: "sonarrprofiles",
dataType: "json",
success: function (response) {
response.forEach(function (result) {
$("#select").append("<option>" + result.name + "</option>");
});
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
})
</script>

@ -43,6 +43,15 @@
<li><a href="/search">Search</a></li>
}
@if (Context.Request.Path == "/requests")
{
<li class="active"><a href="/requests">Requests</a></li>
}
else
{
<li><a href="/requests">Requests</a></li>
}
@if (Context.CurrentUser.IsAuthenticated())
{
if (Context.Request.Path == "/admin")
@ -54,14 +63,6 @@
<li><a href="/admin">Admin</a></li>
}
}
@if (Context.Request.Path == "/requests")
{
<li class="active"><a href="/requests">Requests</a></li>
}
else
{
<li><a href="/requests">Requests</a></li>
}
</ul>
<ul class="nav navbar-nav navbar-right">
@if (!Context.CurrentUser.IsAuthenticated())

Loading…
Cancel
Save