Wow, that was a lot of work.

- So, I have now finished #40.
- Fixed a bug where we was not choosing the correct tv series (Because of TVMaze)
- Fixed a bug when checking for plex titles
- Fixed a bug where the wrong issue would clean on the UI (DB was correct)
- Refactored how we send tv shows
- And too many small changes to count.
pull/42/head
tidusjar 8 years ago
parent 803b12da0f
commit 9402d1409e

@ -0,0 +1,40 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: ISickRageApi.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 PlexRequests.Api.Models.SickRage;
namespace PlexRequests.Api.Interfaces
{
public interface ISickRageApi
{
SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey,
Uri baseUrl);
SickRagePing Ping(string apiKey, Uri baseUrl);
}
}

@ -49,6 +49,7 @@
<Compile Include="ICouchPotatoApi.cs" />
<Compile Include="IPlexApi.cs" />
<Compile Include="IPushbulletApi.cs" />
<Compile Include="ISickRageApi.cs" />
<Compile Include="ISonarrApi.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

@ -57,6 +57,9 @@
<Compile Include="Plex\PlexStatus.cs" />
<Compile Include="Plex\PlexUserRequest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SickRage\SickRagePing.cs" />
<Compile Include="SickRage\SickRageStatus.cs" />
<Compile Include="SickRage\SickRageTvAdd.cs" />
<Compile Include="Sonarr\SonarrAddSeries.cs" />
<Compile Include="Sonarr\SonarrProfile.cs" />
<Compile Include="Sonarr\SystemStatus.cs" />

@ -0,0 +1,40 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SickRagePing.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
namespace PlexRequests.Api.Models.SickRage
{
public class SickRagePingData
{
public int pid { get; set; }
}
public class SickRagePing
{
public SickRagePingData data { get; set; }
public string message { get; set; }
public string result { get; set; }
}
}

@ -0,0 +1,35 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SickRageStatus.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
namespace PlexRequests.Api.Models.SickRage
{
public static class SickRageStatus
{
public const string Wanted = "wanted";
public const string Skipped = "skipped";
public const string Ignored = "Ignored";
}
}

@ -0,0 +1,41 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SickRageTvAdd.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
namespace PlexRequests.Api.Models.SickRage
{
public class SickRageTvAddData
{
public string name { get; set; }
}
public class SickRageTvAdd
{
public SickRageTvAddData data { get; set; }
public string message { get; set; }
public string result { get; set; }
}
}

@ -1,4 +1,5 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CouchPotatoApi.cs
@ -23,46 +24,65 @@
// 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 System;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Sonarr;
using PlexRequests.Api.Models.SickRage;
using RestSharp;
namespace PlexRequests.Api
{
public class SickrageApi
public class SickrageApi : ISickRageApi
{
private static Logger Log = LogManager.GetCurrentClassLogger();
public SickrageApi()
{
Api = new ApiRequest();
}
private ApiRequest Api { get; set; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private ApiRequest Api { get; }
public SonarrAddSeries AddSeries(int tvdbId, string status, string futureStatus, string quality, string apiKey, Uri baseUrl)
public SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey,
Uri baseUrl)
{
//localhost:8081/api/e738882774aeb0b2210f4bc578cbb584/?cmd=show.addnew&tvdbid=101501&status=skipped&future_status=wanted&initial=fullhdbluray&sdtv
string status;
var futureStatus = SickRageStatus.Wanted;
status = latest ? SickRageStatus.Skipped : SickRageStatus.Wanted;
var request = new RestRequest
{
Resource = "/api/{apiKey}/?cmd=show.addnew",
Method = Method.GET
};
request.AddUrlSegment("apiKey", apiKey);
request.AddQueryParameter("tvdbid", tvdbId.ToString());
request.AddQueryParameter("status", status);
request.AddQueryParameter("future_status", futureStatus);
request.AddQueryParameter("initial", quality);
var obj = Api.ExecuteJson<SonarrAddSeries>(request, baseUrl);
var obj = Api.Execute<SickRageTvAdd>(request, baseUrl);
return obj;
}
public SickRagePing Ping(string apiKey, Uri baseUrl)
{
var request = new RestRequest
{
Resource = "/api/{apiKey}/?cmd=sb.ping",
Method = Method.GET
};
request.AddUrlSegment("apiKey", apiKey);
var obj = Api.ExecuteJson<SickRagePing>(request, baseUrl);
return obj;
}
}
}

@ -33,6 +33,10 @@ namespace PlexRequests.Helpers
{
public static string RemoveHtml(this string value)
{
if (string.IsNullOrEmpty(value))
{
return string.Empty;
}
var step1 = Regex.Replace(value, @"<[^>]+>|&nbsp;", "").Trim();
var step2 = Regex.Replace(step1, @"\s{2,}", " ");
return step2;

@ -108,7 +108,7 @@ namespace PlexRequests.Services.Tests
var requestMock = new Mock<IRequestService>();
var plexMock = new Mock<IPlexApi>();
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "wrong title", Year = "2011"} } };
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "wrong tistle", Year = "2011"} } };
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });

@ -97,11 +97,21 @@ namespace PlexRequests.Services
{
throw new ApplicationSettingsException("The settings are not configured for Plex or Authentication");
}
if (!string.IsNullOrEmpty(year))
{
var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri);
var result = results.Video?.FirstOrDefault(x => x.Title.Contains(title) && x.Year == year);
var directoryTitle = results.Directory?.Title == title && results.Directory?.Year == year;
return result?.Title != null || directoryTitle;
}
else
{
var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri);
var result = results.Video?.FirstOrDefault(x => x.Title.Contains(title));
var directoryTitle = results.Directory?.Title == title;
return result?.Title != null || directoryTitle;
}
var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri);
var result = results.Video?.FirstOrDefault(x => x.Title == title && x.Year == year);
var directoryTitle = results.Directory?.Title == title && results.Directory?.Year == year;
return result?.Title != null || directoryTitle;
}
private bool ValidateSettings(PlexSettings plex, AuthenticationSettings auth, IEnumerable<RequestedModel> requests)

@ -74,7 +74,7 @@ namespace PlexRequests.Store.Repository
public RequestBlobs Get(int id)
{
var key = TypeName + "Get";
var key = TypeName + "Get" + id;
var item = Cache.GetOrSet(key, () =>
{
using (var con = Db.DbConnection())

@ -62,12 +62,10 @@ namespace PlexRequests.UI
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
{
container.Register<IUserMapper, UserMapper>();
container.Register<ISqliteConfiguration, DbConfiguration>(new DbConfiguration(new SqliteFactory()));
container.Register<ISettingsRepository, SettingsJsonRepository>();
container.Register<ICacheProvider, MemoryCacheProvider>();
// Settings
container.Register<ISettingsService<PlexRequestSettings>, SettingsServiceV2<PlexRequestSettings>>();
container.Register<ISettingsService<CouchPotatoSettings>, SettingsServiceV2<CouchPotatoSettings>>();
container.Register<ISettingsService<AuthenticationSettings>, SettingsServiceV2<AuthenticationSettings>>();
@ -76,20 +74,22 @@ namespace PlexRequests.UI
container.Register<ISettingsService<SickRageSettings>, SettingsServiceV2<SickRageSettings>>();
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
// Repo's
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
container.Register<IRequestService, JsonRequestService>();
container.Register<ISettingsRepository, SettingsJsonRepository>();
// Services
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
container.Register<IConfigurationReader, ConfigurationReader>();
container.Register<IIntervals, UpdateInterval>();
// Api's
container.Register<ICouchPotatoApi, CouchPotatoApi>();
container.Register<IPushbulletApi, PushbulletApi>();
container.Register<ISickRageApi, SickrageApi>();
container.Register<ISonarrApi, SonarrApi>();
//container.Register<ISonarrApi, MockSonarrApi>();
container.Register<IPlexApi, PlexApi>();
SubscribeAllObservers(container);
@ -102,7 +102,7 @@ namespace PlexRequests.UI
TaskManager.Initialize(new PlexRegistry());
CookieBasedSessions.Enable(pipelines, CryptographyConfiguration.Default);
StaticConfiguration.DisableErrorTraces = false;
base.ApplicationStartup(container, pipelines);

@ -210,7 +210,7 @@ $(document).on("click", ".clear", function (e) {
if (checkJsonResponse(response)) {
generateNotify("Success! Issues Cleared.", "info");
$('#issueArea').html("<div>Issue: None</div>");
$('#issueArea'+buttonId).html("<div>Issue: None</div>");
}
},
error: function (e) {

@ -0,0 +1,77 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: TvSender.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 Nancy;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.SickRage;
using PlexRequests.Api.Models.Sonarr;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Store;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Helpers
{
public class TvSender
{
public TvSender(ISonarrApi sonarrApi, ISickRageApi srApi)
{
SonarrApi = sonarrApi;
SickrageApi = srApi;
}
private ISonarrApi SonarrApi { get; }
private ISickRageApi SickrageApi { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public SonarrAddSeries SendToSonarr(SonarrSettings sonarrSettings, RequestedModel model)
{
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.Trace("Sonarr Add Result: ");
Log.Trace(result.DumpJson());
return result;
}
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model)
{
var result = SickrageApi.AddSeries(model.ProviderId, model.LatestTv, sickRageSettings.QualityProfile,
sickRageSettings.ApiKey, sickRageSettings.FullUri);
Log.Trace("SickRage Add Result: ");
Log.Trace(result.DumpJson());
return result;
}
}
}

@ -43,7 +43,7 @@ namespace PlexRequests.UI.Modules
{
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi, IPlexApi plexApi,
ISettingsService<AuthenticationSettings> authSettings) : base("test")
ISettingsService<AuthenticationSettings> authSettings, ISickRageApi srApi) : base("test")
{
this.RequiresAuthentication();
@ -51,10 +51,12 @@ namespace PlexRequests.UI.Modules
SonarrApi = sonarrApi;
PlexApi = plexApi;
AuthSettings = authSettings;
SickRageApi = srApi;
Post["/cp"] = _ => CouchPotatoTest();
Post["/sonarr"] = _ => SonarrTest();
Post["/plex"] = _ => PlexTest();
Post["/sickrage"] = _ => SickRageTest();
}
@ -62,6 +64,7 @@ namespace PlexRequests.UI.Modules
private ISonarrApi SonarrApi { get; }
private ICouchPotatoApi CpApi { get; }
private IPlexApi PlexApi { get; }
private ISickRageApi SickRageApi { get; }
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
private Response CouchPotatoTest()
@ -99,7 +102,7 @@ namespace PlexRequests.UI.Modules
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Sonarr, please check your settings." });
}
catch (ApplicationException e) // Exceptions are expected if we cannot connect so we will just log and swallow them.
catch (ApplicationException e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
{
Log.Warn("Exception thrown when attempting to get Sonarr's status: ");
Log.Warn(e);
@ -128,7 +131,7 @@ namespace PlexRequests.UI.Modules
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Plex, please check your settings." });
}
catch (ApplicationException e) // Exceptions are expected if we cannot connect so we will just log and swallow them.
catch (ApplicationException e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
{
Log.Warn("Exception thrown when attempting to get Plex's status: ");
Log.Warn(e);
@ -140,5 +143,30 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
}
}
private Response SickRageTest()
{
var sickRageSettings = this.Bind<SickRageSettings>();
try
{
var status = SickRageApi.Ping(sickRageSettings.ApiKey, sickRageSettings.FullUri);
return status?.result == "success"
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to SickRage successfully!" })
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to SickRage, please check your settings." });
}
catch (ApplicationException e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
{
Log.Warn("Exception thrown when attempting to get SickRage's status: ");
Log.Warn(e);
var message = $"Could not connect to SickRage, please check your settings. <strong>Exception Message:</strong> {e.Message}";
if (e.InnerException != null)
{
message = $"Could not connect to SickRage, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
}
}
}
}

@ -27,7 +27,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Nancy;
using Nancy.Security;
@ -36,7 +36,9 @@ using PlexRequests.Api;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Store;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
@ -45,7 +47,7 @@ namespace PlexRequests.UI.Modules
{
public ApprovalModule(IRequestService service, ISettingsService<CouchPotatoSettings> cpService, ICouchPotatoApi cpApi, ISonarrApi sonarrApi,
ISettingsService<SonarrSettings> sonarrSettings) : base("approval")
ISettingsService<SonarrSettings> sonarrSettings, ISickRageApi srApi, ISettingsService<SickRageSettings> srSettings) : base("approval")
{
this.RequiresAuthentication();
@ -54,6 +56,8 @@ namespace PlexRequests.UI.Modules
CpApi = cpApi;
SonarrApi = sonarrApi;
SonarrSettings = sonarrSettings;
SickRageApi = srApi;
SickRageSettings = srSettings;
Post["/approve"] = parameters => Approve((int)Request.Form.requestid);
Post["/approveall"] = x => ApproveAll();
@ -63,8 +67,10 @@ namespace PlexRequests.UI.Modules
private static Logger Log = LogManager.GetCurrentClassLogger();
private ISettingsService<SonarrSettings> SonarrSettings { get; }
private ISettingsService<SickRageSettings> SickRageSettings { get; }
private ISettingsService<CouchPotatoSettings> CpService { get; }
private ISonarrApi SonarrApi { get; }
private ISickRageApi SickRageApi { get; }
private ICouchPotatoApi CpApi { get; }
/// <summary>
@ -74,6 +80,7 @@ namespace PlexRequests.UI.Modules
/// <returns></returns>
private Response Approve(int requestId)
{
Log.Info("approving request {0}", requestId);
if (!Context.CurrentUser.IsAuthenticated())
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "You are not an Admin, so you cannot approve any requests." });
@ -100,20 +107,63 @@ namespace PlexRequests.UI.Modules
private Response RequestTvAndUpdateStatus(RequestedModel request)
{
var sender = new TvSender(SonarrApi, SickRageApi);
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 (sonarrSettings.Enabled)
{
Log.Trace("Sending to Sonarr");
var result = sender.SendToSonarr(sonarrSettings, request);
Log.Trace("Sonarr Result: ");
Log.Trace(result.DumpJson());
if (!string.IsNullOrEmpty(result.title))
{
Log.Info("Sent successfully, Approving request now.");
request.Approved = true;
var requestResult = Service.UpdateRequest(request);
Log.Trace("Approval result: {0}",requestResult);
if (requestResult)
{
return Response.AsJson(new JsonResponseModel { Result = true });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Updated Sonarr but could not approve it in PlexRequests :("});
}
return Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Could not add the series to Sonarr"
});
}
if (!string.IsNullOrEmpty(result.title))
var srSettings = SickRageSettings.GetSettings();
if (srSettings.Enabled)
{
return Response.AsJson(new JsonResponseModel { Result = true });
Log.Trace("Sending to SickRage");
var result = sender.SendToSickRage(srSettings, request);
Log.Trace("SickRage Result: ");
Log.Trace(result.DumpJson());
if (result?.result == "success")
{
Log.Info("Sent successfully, Approving request now.");
request.Approved = true;
var requestResult = Service.UpdateRequest(request);
Log.Trace("Approval result: {0}", requestResult);
if (requestResult)
{
return Response.AsJson(new JsonResponseModel { Result = true });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Updated SickRage but could not approve it in PlexRequests :(" });
}
return Response.AsJson(new JsonResponseModel
{
Result = false,
Message = result?.message != null ? "<b>Message From SickRage: </b>" + result.message : "Could not add the series to SickRage"
});
}
return Response.AsJson(new JsonResponseModel
{
Result = false, Message = "Could not add the series to Sonarr"
Result = false,
Message = "SickRage or Sonarr are not set up!"
});
}
@ -184,12 +234,42 @@ namespace PlexRequests.UI.Modules
}
else
{
Log.Error("Could not approve send the movie {0} to couch potato!", r.Title);
Log.Error("Could not approve and send the movie {0} to couch potato!", r.Title);
}
}
if (r.Type == RequestType.TvShow)
{
// TODO
var sender = new TvSender(SonarrApi,SickRageApi);
var sr = SickRageSettings.GetSettings();
var sonarr = SonarrSettings.GetSettings();
if (sr.Enabled)
{
var result = sender.SendToSickRage(sr, r);
if (result?.result == "success")
{
r.Approved = true;
updatedRequests.Add(r);
}
else
{
Log.Error("Could not approve and send the TV {0} to SickRage!", r.Title);
Log.Error("SickRage Message: {0}", result?.message);
}
}
if (sonarr.Enabled)
{
var result = sender.SendToSonarr(sonarr, r);
if (result != null)
{
r.Approved = true;
updatedRequests.Add(r);
}
else
{
Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title);
}
}
}
}
try
@ -208,7 +288,6 @@ namespace PlexRequests.UI.Modules
}
private bool SendMovie(CouchPotatoSettings settings, RequestedModel r, ICouchPotatoApi cp)
{
Log.Info("Adding movie to CP : {0}", r.Title);

@ -42,6 +42,7 @@ using PlexRequests.Helpers;
using PlexRequests.Services.Interfaces;
using PlexRequests.Services.Notification;
using PlexRequests.Store;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
@ -51,7 +52,7 @@ namespace PlexRequests.UI.Modules
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings,
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings,
ICouchPotatoApi cpApi) : base("search")
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi) : base("search")
{
CpService = cpSettings;
PrService = prSettings;
@ -63,6 +64,8 @@ namespace PlexRequests.UI.Modules
SonarrApi = sonarrApi;
SonarrService = sonarrSettings;
CouchPotatoApi = cpApi;
SickRageService = sickRageService;
SickrageApi = srApi;
Get["/"] = parameters => RequestLoad();
@ -79,11 +82,13 @@ namespace PlexRequests.UI.Modules
private ICouchPotatoApi CouchPotatoApi { get; }
private ISonarrApi SonarrApi { get; }
private TheTvDbApi TvApi { get; }
private ISickRageApi SickrageApi { 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 ISettingsService<SickRageSettings> SickRageService { get; }
private IAvailabilityChecker Checker { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
@ -124,7 +129,7 @@ namespace PlexRequests.UI.Modules
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg
Banner = t.show.image?.medium,
FirstAired = t.show.premiered,
Id = t.show.id,
Id = t.show.externals?.thetvdb ?? 0,
ImdbId = t.show.externals?.imdb,
Network = t.show.network?.name,
NetworkId = t.show.network?.id.ToString(),
@ -133,7 +138,7 @@ namespace PlexRequests.UI.Modules
Runtime = t.show.runtime.ToString(),
SeriesId = t.show.id,
SeriesName = t.show.name,
Status = t.show.status,
});
}
@ -186,12 +191,12 @@ namespace PlexRequests.UI.Modules
Log.Trace("Getting movie info from TheMovieDb");
Log.Trace(movieInfo.DumpJson);
//#if !DEBUG
//#if !DEBUG
if (CheckIfTitleExistsInPlex(movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString()))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{movieInfo.Title} is already in Plex!" });
}
//#endif
//#endif
var model = new RequestedModel
{
@ -215,7 +220,7 @@ namespace PlexRequests.UI.Modules
if (!settings.RequireApproval)
{
Log.Info("Adding movie to CP (No approval required)");
var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri,cpSettings.ProfileId);
var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri, cpSettings.ProfileId);
Log.Debug("Adding movie to CP result {0}", result);
if (result)
{
@ -260,21 +265,21 @@ namespace PlexRequests.UI.Modules
var tvApi = new TvMazeApi();
var showInfo = tvApi.ShowLookup(showId);
var showInfo = tvApi.ShowLookupByTheTvDbId(showId);
//#if !DEBUG
if (CheckIfTitleExistsInPlex(showInfo.name, showInfo.premiered.Substring(0,4))) // Take only the year Format = 2014-01-01
//#if !DEBUG
if (CheckIfTitleExistsInPlex(showInfo.name, showInfo.premiered?.Substring(0, 4))) // Take only the year Format = 2014-01-01
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{showInfo.name} is already in Plex!" });
}
//#endif
//#endif
DateTime firstAir;
DateTime.TryParse(showInfo.premiered, out firstAir);
var model = new RequestedModel
{
ProviderId = showInfo.id,
ProviderId = showInfo.externals?.thetvdb ?? 0,
Type = RequestType.TvShow,
Overview = showInfo.summary.RemoveHtml(),
PosterPath = showInfo.image?.medium,
@ -293,20 +298,39 @@ namespace PlexRequests.UI.Modules
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);
if (result != null)
var sender = new TvSender(SonarrApi, SickrageApi);
if (sonarrSettings.Enabled)
{
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required)");
RequestService.AddRequest(model);
var result = sender.SendToSonarr(sonarrSettings, model);
if (result != null)
{
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
RequestService.AddRequest(model);
return Response.AsJson(new JsonResponseModel { Result = true });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to Sonarr! Please check your settings." });
return Response.AsJson(new JsonResponseModel { Result = true });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
var srSettings = SickRageService.GetSettings();
if (srSettings.Enabled)
{
var result = sender.SendToSickRage(srSettings, model);
if (result?.result == "success")
{
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
RequestService.AddRequest(model);
return Response.AsJson(new JsonResponseModel { Result = true });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = result?.message != null ? "<b>Message From SickRage: </b>" + result.message : "Something went wrong adding the movie to SickRage! Please check your settings." });
}
return Response.AsJson("The request of TV Shows is not correctly set up. Please contact your admin.");
}
RequestService.AddRequest(model);
@ -314,15 +338,30 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new { Result = true });
}
private string GetTvDbAuthToken(TheTvDbApi api)
{
return Cache.GetOrSet(CacheKeys.TvDbToken, api.Authenticate, 50);
}
private bool CheckIfTitleExistsInPlex(string title, string year)
{
var result = Checker.IsAvailable(title, year);
return result;
}
private Response SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model)
{
var result = SickrageApi.AddSeries(model.ProviderId, model.LatestTv, sickRageSettings.QualityProfile,
sickRageSettings.ApiKey, sickRageSettings.FullUri);
Log.Trace("SickRage Result: ");
Log.Trace(result.DumpJson());
if (result?.result == "success")
{
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
RequestService.AddRequest(model);
return Response.AsJson(new JsonResponseModel { Result = true });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to SickRage! Please check your settings." });
}
}
}

@ -160,6 +160,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstrapper.cs" />
<Compile Include="Helpers\TvSender.cs" />
<Compile Include="Helpers\ValidationHelper.cs" />
<Compile Include="Validators\PushbulletSettingsValidator.cs" />
<Compile Include="Validators\EmailNotificationSettingsValidator.cs" />

@ -68,15 +68,15 @@
<label for="profiles" class="control-label">Quality Profiles</label>
<div id="profiles">
<select class="form-control" value="selected">
<option selected="selected" value="default">Use Deafult</option>
<option value="sdtv">SD TV</option>
<option value="sddvd">SD DVD</option>
<option value="hdtv">HD TV</option>
<option value="rawhdtv">Raw HD TV</option>
<option value="hdwebdl">HD Web DL</option>
<option value="fullhdwebdl">Full HD Web DL</option>
<option value="hdbluray">HD Bluray</option>
<option value="fullhdbluray">Full HD Bluray</option>
<option id="default" value="default">Use Deafult</option>
<option id="sdtv" value="sdtv">SD TV</option>
<option id="sddvd" value="sddvd">SD DVD</option>
<option id="hdtv" value="hdtv">HD TV</option>
<option id="rawhdtv" value="rawhdtv">Raw HD TV</option>
<option id="hdwebdl" value="hdwebdl">HD Web DL</option>
<option id="fullhdwebdl" value="fullhdwebdl">Full HD Web DL</option>
<option id="hdbluray" value="hdbluray">HD Bluray</option>
<option id="fullhdbluray" value="fullhdbluray">Full HD Bluray</option>
</select>
</div>
</div>
@ -100,10 +100,17 @@
<script>
$(function () {
$(function() {
$('#save').click(function(e) {
@if (!string.IsNullOrEmpty(Model.QualityProfile))
{
<text>
var qualitySelected = '@Model.QualityProfile';
$('#' + qualitySelected).prop("selected", "selected");
</text>
}
$('#save').click(function (e) {
e.preventDefault();
var port = $('#portNumber').val();
if (isNaN(port)) {
@ -136,44 +143,12 @@
});
});
$('#getProfiles').click(function (e) {
e.preventDefault();
if (!$('#Ip').val()) {
generateNotify("Please enter a valid IP/Hostname.", "warning");
return;
}
if (!$('#portNumber').val()) {
generateNotify("Please enter a valid Port Number.", "warning");
return;
}
if (!$('#ApiKey').val()) {
generateNotify("Please enter a valid ApiKey.", "warning");
return;
}
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: "sonarrprofiles",
dataType: "json",
success: function (response) {
response.forEach(function (result) {
$("#select").append("<option value='" + result.id + "'>" + result.name + "</option>");
});
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
$('#testSonarr').click(function (e) {
$('#testSickRage').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
url: "/test/sonarr",
url: "/test/sickrage",
data: $form.serialize(),
dataType: "json",
success: function (response) {

@ -146,11 +146,6 @@
generateNotify("Something went wrong!", "danger");
}
});
</text>
}

@ -95,7 +95,7 @@
</div>
<div>Requested By: {{requestedBy}}</div>
<div>Requested Date: {{requestedDate}}</div>
<div id="issueArea">
<div id="issueArea{{requestId}}">
{{#if otherMessage}}
<div>Message: {{otherMessage}}</div>
{{else}}

Loading…
Cancel
Save