mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 01:32:55 -07:00
parent
6e3e290359
commit
e563b5bf3d
12 changed files with 108 additions and 31 deletions
|
@ -38,6 +38,6 @@ namespace PlexRequests.Api.Interfaces
|
||||||
CouchPotatoProfiles GetProfiles(Uri url, string apiKey);
|
CouchPotatoProfiles GetProfiles(Uri url, string apiKey);
|
||||||
CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status);
|
CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status);
|
||||||
|
|
||||||
CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password);
|
CouchPotatoApiKey GetApiKey(Uri baseUrl, string username, string password);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: CoucPotatoApiKey.cs
|
// File: CouchPotatoApiKey.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
@ -28,10 +28,10 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace PlexRequests.Api.Models.Movie
|
namespace PlexRequests.Api.Models.Movie
|
||||||
{
|
{
|
||||||
public class CoucPotatoApiKey
|
public class CouchPotatoApiKey
|
||||||
{
|
{
|
||||||
[JsonProperty("success")]
|
[JsonProperty("success")]
|
||||||
public bool Result { get; set; }
|
public bool success { get; set; }
|
||||||
[JsonProperty("api_key")]
|
[JsonProperty("api_key")]
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
}
|
}
|
|
@ -49,7 +49,7 @@
|
||||||
<Compile Include="Movie\CouchPotatoMovies.cs" />
|
<Compile Include="Movie\CouchPotatoMovies.cs" />
|
||||||
<Compile Include="Movie\CouchPotatoProfiles.cs" />
|
<Compile Include="Movie\CouchPotatoProfiles.cs" />
|
||||||
<Compile Include="Movie\CouchPotatoStatus.cs" />
|
<Compile Include="Movie\CouchPotatoStatus.cs" />
|
||||||
<Compile Include="Movie\CoucPotatoApiKey.cs" />
|
<Compile Include="Movie\CouchPotatoApiKey.cs" />
|
||||||
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
|
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
|
||||||
<Compile Include="Music\HeadphonesArtistSearchResult.cs" />
|
<Compile Include="Music\HeadphonesArtistSearchResult.cs" />
|
||||||
<Compile Include="Music\HeadphonesGetIndex.cs" />
|
<Compile Include="Music\HeadphonesGetIndex.cs" />
|
||||||
|
|
|
@ -160,18 +160,18 @@ namespace PlexRequests.Api
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password)
|
public CouchPotatoApiKey GetApiKey(Uri baseUrl, string username, string password)
|
||||||
{
|
{
|
||||||
var request = new RestRequest
|
var request = new RestRequest
|
||||||
{
|
{
|
||||||
Resource = "getkey/?p={username}&u={password}",
|
Resource = "getkey/?u={username}&p={password}",
|
||||||
Method = Method.GET
|
Method = Method.GET
|
||||||
};
|
};
|
||||||
|
|
||||||
request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username));
|
request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username));
|
||||||
request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password));
|
request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password));
|
||||||
|
|
||||||
var obj = RetryHandler.Execute(() => Api.Execute<CoucPotatoApiKey>(request, baseUrl),
|
var obj = RetryHandler.Execute(() => Api.Execute<CouchPotatoApiKey>(request, baseUrl),
|
||||||
(exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan), null);
|
(exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan), null);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
|
10
PlexRequests.Services/Jobs/IRecentlyAdded.cs
Normal file
10
PlexRequests.Services/Jobs/IRecentlyAdded.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using Quartz;
|
||||||
|
|
||||||
|
namespace PlexRequests.Services.Jobs
|
||||||
|
{
|
||||||
|
public interface IRecentlyAdded
|
||||||
|
{
|
||||||
|
void Execute(IJobExecutionContext context);
|
||||||
|
void Test();
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,7 +45,7 @@ using Quartz;
|
||||||
|
|
||||||
namespace PlexRequests.Services.Jobs
|
namespace PlexRequests.Services.Jobs
|
||||||
{
|
{
|
||||||
public class RecentlyAdded : IJob
|
public class RecentlyAdded : IJob, IRecentlyAdded
|
||||||
{
|
{
|
||||||
public RecentlyAdded(IPlexApi api, ISettingsService<PlexSettings> plexSettings, ISettingsService<EmailNotificationSettings> email,
|
public RecentlyAdded(IPlexApi api, ISettingsService<PlexSettings> plexSettings, ISettingsService<EmailNotificationSettings> email,
|
||||||
ISettingsService<ScheduledJobsSettings> scheduledService, IJobRecord rec)
|
ISettingsService<ScheduledJobsSettings> scheduledService, IJobRecord rec)
|
||||||
|
@ -95,10 +95,16 @@ namespace PlexRequests.Services.Jobs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
public void Test()
|
||||||
|
{
|
||||||
|
Start(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start(bool testEmail = false)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var plexSettings = PlexSettings.GetSettings();
|
var plexSettings = PlexSettings.GetSettings();
|
||||||
|
|
||||||
var recentlyAdded = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
var recentlyAdded = Api.RecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
||||||
|
|
||||||
var movies =
|
var movies =
|
||||||
|
@ -115,7 +121,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
var template = new RecentlyAddedTemplate();
|
var template = new RecentlyAddedTemplate();
|
||||||
var html = template.LoadTemplate(sb.ToString());
|
var html = template.LoadTemplate(sb.ToString());
|
||||||
|
|
||||||
Send(html, plexSettings);
|
Send(html, plexSettings, testEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateMovieHtml(IEnumerable<RecentlyAddedChild> movies, PlexSettings plexSettings, ref StringBuilder sb)
|
private void GenerateMovieHtml(IEnumerable<RecentlyAddedChild> movies, PlexSettings plexSettings, ref StringBuilder sb)
|
||||||
|
@ -194,10 +200,15 @@ namespace PlexRequests.Services.Jobs
|
||||||
sb.Append("</table><br/><br/>");
|
sb.Append("</table><br/><br/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Send(string html, PlexSettings plexSettings)
|
private void Send(string html, PlexSettings plexSettings, bool testEmail = false)
|
||||||
{
|
{
|
||||||
var users = Api.GetUsers(plexSettings.PlexAuthToken);
|
|
||||||
var settings = EmailSettings.GetSettings();
|
var settings = EmailSettings.GetSettings();
|
||||||
|
|
||||||
|
if (!settings.Enabled || string.IsNullOrEmpty(settings.EmailHost))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var body = new BodyBuilder { HtmlBody = html, TextBody = "This email is only available on devices that support HTML." };
|
var body = new BodyBuilder { HtmlBody = html, TextBody = "This email is only available on devices that support HTML." };
|
||||||
var message = new MimeMessage
|
var message = new MimeMessage
|
||||||
{
|
{
|
||||||
|
@ -205,10 +216,15 @@ namespace PlexRequests.Services.Jobs
|
||||||
Subject = "New Content on Plex!",
|
Subject = "New Content on Plex!",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!testEmail)
|
||||||
|
{
|
||||||
|
var users = Api.GetUsers(plexSettings.PlexAuthToken);
|
||||||
foreach (var user in users.User)
|
foreach (var user in users.User)
|
||||||
{
|
{
|
||||||
message.Bcc.Add(new MailboxAddress(user.Username, user.Email));
|
message.Bcc.Add(new MailboxAddress(user.Username, user.Email));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender)); // Include the admin
|
||||||
|
|
||||||
message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender));
|
message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender));
|
||||||
try
|
try
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Interfaces\IJobRecord.cs" />
|
<Compile Include="Interfaces\IJobRecord.cs" />
|
||||||
<Compile Include="Interfaces\INotificationEngine.cs" />
|
<Compile Include="Interfaces\INotificationEngine.cs" />
|
||||||
|
<Compile Include="Jobs\IRecentlyAdded.cs" />
|
||||||
<Compile Include="Jobs\JobRecord.cs" />
|
<Compile Include="Jobs\JobRecord.cs" />
|
||||||
<Compile Include="Jobs\JobNames.cs" />
|
<Compile Include="Jobs\JobNames.cs" />
|
||||||
<Compile Include="Jobs\PlexEpisodeCacher.cs" />
|
<Compile Include="Jobs\PlexEpisodeCacher.cs" />
|
||||||
|
|
|
@ -48,6 +48,7 @@ using PlexRequests.UI.Models;
|
||||||
using PlexRequests.UI.Modules;
|
using PlexRequests.UI.Modules;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.Helpers.Analytics;
|
using PlexRequests.Helpers.Analytics;
|
||||||
|
using PlexRequests.Services.Jobs;
|
||||||
using PlexRequests.UI.Helpers;
|
using PlexRequests.UI.Helpers;
|
||||||
|
|
||||||
namespace PlexRequests.UI.Tests
|
namespace PlexRequests.UI.Tests
|
||||||
|
@ -81,6 +82,7 @@ namespace PlexRequests.UI.Tests
|
||||||
private Mock<ISlackApi> SlackApi { get; set; }
|
private Mock<ISlackApi> SlackApi { get; set; }
|
||||||
private Mock<IAnalytics> Analytics { get; set; }
|
private Mock<IAnalytics> Analytics { get; set; }
|
||||||
private Mock<ISettingsService<NotificationSettingsV2>> NotifyV2 { get; set; }
|
private Mock<ISettingsService<NotificationSettingsV2>> NotifyV2 { get; set; }
|
||||||
|
private Mock<IRecentlyAdded> RecentlyAdded { get; set; }
|
||||||
|
|
||||||
private ConfigurableBootstrapper Bootstrapper { get; set; }
|
private ConfigurableBootstrapper Bootstrapper { get; set; }
|
||||||
|
|
||||||
|
@ -122,6 +124,7 @@ namespace PlexRequests.UI.Tests
|
||||||
RecorderMock = new Mock<IJobRecord>();
|
RecorderMock = new Mock<IJobRecord>();
|
||||||
Analytics = new Mock<IAnalytics>();
|
Analytics = new Mock<IAnalytics>();
|
||||||
NotifyV2= new Mock<ISettingsService<NotificationSettingsV2>>();
|
NotifyV2= new Mock<ISettingsService<NotificationSettingsV2>>();
|
||||||
|
RecentlyAdded = new Mock<IRecentlyAdded>();
|
||||||
|
|
||||||
|
|
||||||
Bootstrapper = new ConfigurableBootstrapper(with =>
|
Bootstrapper = new ConfigurableBootstrapper(with =>
|
||||||
|
@ -153,6 +156,7 @@ namespace PlexRequests.UI.Tests
|
||||||
with.Dependency(SlackSettings.Object);
|
with.Dependency(SlackSettings.Object);
|
||||||
with.Dependency(ScheduledJobsSettingsMock.Object);
|
with.Dependency(ScheduledJobsSettingsMock.Object);
|
||||||
with.Dependency(RecorderMock.Object);
|
with.Dependency(RecorderMock.Object);
|
||||||
|
with.Dependency(RecentlyAdded.Object);
|
||||||
with.RootPathProvider<TestRootPathProvider>();
|
with.RootPathProvider<TestRootPathProvider>();
|
||||||
with.RequestStartup((container, pipelines, context) =>
|
with.RequestStartup((container, pipelines, context) =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,7 @@ using PlexRequests.Helpers;
|
||||||
using PlexRequests.Helpers.Analytics;
|
using PlexRequests.Helpers.Analytics;
|
||||||
using PlexRequests.Helpers.Exceptions;
|
using PlexRequests.Helpers.Exceptions;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
|
using PlexRequests.Services.Jobs;
|
||||||
using PlexRequests.Services.Notification;
|
using PlexRequests.Services.Notification;
|
||||||
using PlexRequests.Store.Models;
|
using PlexRequests.Store.Models;
|
||||||
using PlexRequests.Store.Repository;
|
using PlexRequests.Store.Repository;
|
||||||
|
@ -94,6 +95,7 @@ namespace PlexRequests.UI.Modules
|
||||||
private ISlackApi SlackApi { get; }
|
private ISlackApi SlackApi { get; }
|
||||||
private IJobRecord JobRecorder { get; }
|
private IJobRecord JobRecorder { get; }
|
||||||
private IAnalytics Analytics { get; }
|
private IAnalytics Analytics { get; }
|
||||||
|
private IRecentlyAdded RecentlyAdded { get; }
|
||||||
private ISettingsService<NotificationSettingsV2> NotifySettings { get; }
|
private ISettingsService<NotificationSettingsV2> NotifySettings { get; }
|
||||||
|
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
@ -118,7 +120,7 @@ namespace PlexRequests.UI.Modules
|
||||||
ICacheProvider cache, ISettingsService<SlackNotificationSettings> slackSettings,
|
ICacheProvider cache, ISettingsService<SlackNotificationSettings> slackSettings,
|
||||||
ISlackApi slackApi, ISettingsService<LandingPageSettings> lp,
|
ISlackApi slackApi, ISettingsService<LandingPageSettings> lp,
|
||||||
ISettingsService<ScheduledJobsSettings> scheduler, IJobRecord rec, IAnalytics analytics,
|
ISettingsService<ScheduledJobsSettings> scheduler, IJobRecord rec, IAnalytics analytics,
|
||||||
ISettingsService<NotificationSettingsV2> notifyService) : base("admin", prService)
|
ISettingsService<NotificationSettingsV2> notifyService, IRecentlyAdded recentlyAdded) : base("admin", prService)
|
||||||
{
|
{
|
||||||
PrService = prService;
|
PrService = prService;
|
||||||
CpService = cpService;
|
CpService = cpService;
|
||||||
|
@ -146,6 +148,7 @@ namespace PlexRequests.UI.Modules
|
||||||
JobRecorder = rec;
|
JobRecorder = rec;
|
||||||
Analytics = analytics;
|
Analytics = analytics;
|
||||||
NotifySettings = notifyService;
|
NotifySettings = notifyService;
|
||||||
|
RecentlyAdded = recentlyAdded;
|
||||||
|
|
||||||
this.RequiresClaims(UserClaims.Admin);
|
this.RequiresClaims(UserClaims.Admin);
|
||||||
|
|
||||||
|
@ -216,6 +219,8 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
Get["/notificationsettings", true] = async (x, ct) => await NotificationSettings();
|
Get["/notificationsettings", true] = async (x, ct) => await NotificationSettings();
|
||||||
Post["/notificationsettings", true] = async (x, ct) => await SaveNotificationSettings();
|
Post["/notificationsettings", true] = async (x, ct) => await SaveNotificationSettings();
|
||||||
|
|
||||||
|
Post["/recentlyAddedTest"] = x => RecentlyAddedTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Negotiator> Authentication()
|
private async Task<Negotiator> Authentication()
|
||||||
|
@ -985,5 +990,19 @@ namespace PlexRequests.UI.Modules
|
||||||
var model = this.Bind<NotificationSettingsV2>();
|
var model = this.Bind<NotificationSettingsV2>();
|
||||||
return View["NotificationSettings", model];
|
return View["NotificationSettings", model];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Response RecentlyAddedTest()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RecentlyAdded.Test();
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Sent email to administrator" });
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,6 +45,7 @@ namespace PlexRequests.UI.NinjectModules
|
||||||
Bind<ICouchPotatoCacher>().To<CouchPotatoCacher>();
|
Bind<ICouchPotatoCacher>().To<CouchPotatoCacher>();
|
||||||
Bind<ISonarrCacher>().To<SonarrCacher>();
|
Bind<ISonarrCacher>().To<SonarrCacher>();
|
||||||
Bind<ISickRageCacher>().To<SickRageCacher>();
|
Bind<ISickRageCacher>().To<SickRageCacher>();
|
||||||
|
Bind<IRecentlyAdded>().To<RecentlyAdded>();
|
||||||
Bind<IJobFactory>().To<CustomJobFactory>();
|
Bind<IJobFactory>().To<CustomJobFactory>();
|
||||||
|
|
||||||
Bind<IAnalytics>().To<Analytics>();
|
Bind<IAnalytics>().To<Analytics>();
|
||||||
|
|
|
@ -160,6 +160,7 @@
|
||||||
|
|
||||||
$('#requestToken').click(function (e) {
|
$('#requestToken').click(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
debugger;
|
||||||
var $form = $("#mainForm");
|
var $form = $("#mainForm");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: $form.prop("method"),
|
type: $form.prop("method"),
|
||||||
|
@ -167,7 +168,7 @@
|
||||||
data: $form.serialize(),
|
data: $form.serialize(),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.result === true) {
|
if (response.apiKey) {
|
||||||
generateNotify("Success!", "success");
|
generateNotify("Success!", "success");
|
||||||
$('#ApiKey').val(response.apiKey);
|
$('#ApiKey').val(response.apiKey);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin</button>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
|
@ -372,5 +373,29 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#recentlyAddedBtn').click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var base = '@Html.GetBaseUrl()';
|
||||||
|
var url = createBaseUrl(base, '/admin/recentlyAddedTest');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: url,
|
||||||
|
dataType: "json",
|
||||||
|
success: function (response) {
|
||||||
|
if (response) {
|
||||||
|
generateNotify(response.message, "success");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
generateNotify(response.message, "danger");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (e) {
|
||||||
|
console.log(e);
|
||||||
|
generateNotify("Something went wrong!", "danger");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue