mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Some small backend newsletter changes, we can now detect if there are any movies and/or tv shows, if there are none then we will no longer send out an empty newsletter.
Also fixed the issue where we were not escaping the sonarr root folders #1118
This commit is contained in:
parent
dc63693bf6
commit
2b8a5c6423
8 changed files with 73 additions and 24 deletions
|
@ -77,7 +77,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public string GetNewsletterHtml(bool test)
|
||||
public Newsletter GetNewsletter(bool test)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return string.Empty;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,11 +97,12 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
public List<EmbyEpisodeInformation> EpisodeInformation { get; set; }
|
||||
}
|
||||
|
||||
private string GetHtml(bool test)
|
||||
private Newsletter GetHtml(bool test)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var embySettings = EmbySettings.GetSettings();
|
||||
var newsletter = new Newsletter();
|
||||
|
||||
var embySettings = EmbySettings.GetSettings();
|
||||
var embyContent = Content.GetAll().ToList();
|
||||
|
||||
var series = embyContent.Where(x => x.Type == EmbyMediaType.Series).ToList();
|
||||
|
@ -129,6 +130,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
});
|
||||
}
|
||||
GenerateMovieHtml(info, sb);
|
||||
newsletter.MovieCount = info.Count;
|
||||
|
||||
info.Clear();
|
||||
foreach (var t in series)
|
||||
|
@ -155,6 +157,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
}
|
||||
GenerateTvHtml(info, sb);
|
||||
newsletter.TvCount = info.Count;
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
var html = template.LoadTemplate(sb.ToString());
|
||||
|
@ -182,7 +185,8 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
return escapedHtml;
|
||||
newsletter.Html = escapedHtml;
|
||||
return newsletter;
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(IEnumerable<EmbyRecentlyAddedModel> recentlyAddedMovies, StringBuilder sb)
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
{
|
||||
public interface IEmbyAddedNewsletter
|
||||
{
|
||||
string GetNewsletterHtml(bool test);
|
||||
Newsletter GetNewsletter(bool test);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,6 @@
|
|||
{
|
||||
public interface IPlexNewsletter
|
||||
{
|
||||
string GetNewsletterHtml(bool test);
|
||||
Newsletter GetNewsletter(bool test);
|
||||
}
|
||||
}
|
37
Ombi.Services/Jobs/RecentlyAddedNewsletter/Newsletter.cs
Normal file
37
Ombi.Services/Jobs/RecentlyAddedNewsletter/Newsletter.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: Newsletter.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 Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||
{
|
||||
public class Newsletter
|
||||
{
|
||||
public string Html { get; set; }
|
||||
public int MovieCount { get; set; }
|
||||
public int TvCount { get; set; }
|
||||
|
||||
public bool Send => MovieCount > 0 || TvCount > 0;
|
||||
}
|
||||
}
|
|
@ -42,11 +42,9 @@ using Ombi.Core.SettingModels;
|
|||
using Ombi.Helpers;
|
||||
using Ombi.Services.Jobs.Templates;
|
||||
using Ombi.Store.Models;
|
||||
using Ombi.Store.Models.Emby;
|
||||
using Ombi.Store.Models.Plex;
|
||||
using Ombi.Store.Repository;
|
||||
using TMDbLib.Objects.Exceptions;
|
||||
using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType;
|
||||
using PlexMediaType = Ombi.Store.Models.Plex.PlexMediaType;
|
||||
|
||||
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||
|
@ -81,7 +79,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public string GetNewsletterHtml(bool test)
|
||||
public Newsletter GetNewsletter(bool test)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -90,7 +88,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return string.Empty;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,9 +98,10 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
public PlexContent Content { get; set; }
|
||||
}
|
||||
|
||||
private string GetHtml(bool test)
|
||||
private Newsletter GetHtml(bool test)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var newsletter = new Newsletter();
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
|
||||
var plexContent = Content.GetAll().ToList();
|
||||
|
@ -134,6 +133,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
});
|
||||
}
|
||||
GenerateMovieHtml(info, sb);
|
||||
newsletter.MovieCount = info.Count;
|
||||
|
||||
info.Clear();
|
||||
foreach (var t in filteredSeries)
|
||||
|
@ -168,6 +168,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
//}
|
||||
}
|
||||
GenerateTvHtml(info, sb);
|
||||
newsletter.TvCount = info.Count;
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
var html = template.LoadTemplate(sb.ToString());
|
||||
|
@ -203,7 +204,8 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
return escapedHtml;
|
||||
newsletter.Html = escapedHtml;
|
||||
return newsletter;
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(IEnumerable<PlexRecentlyAddedModel> recentlyAddedMovies, StringBuilder sb)
|
||||
|
|
|
@ -137,22 +137,26 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
var embySettings = EmbySettings.GetSettings();
|
||||
if (embySettings.Enable)
|
||||
{
|
||||
var html = EmbyNewsletter.GetNewsletterHtml(testEmail);
|
||||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
SendNewsletter(newletterSettings, escapedHtml, testEmail, "New Content On Emby!");
|
||||
var letter = EmbyNewsletter.GetNewsletter(testEmail) ?? new Newsletter();
|
||||
if (letter.Send)
|
||||
{
|
||||
SendNewsletter(newletterSettings, letter.Html, testEmail, "New Content On Emby!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("There is no new content to send the newsletter");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
if (plexSettings.Enable)
|
||||
{
|
||||
var html = PlexNewsletter.GetNewsletterHtml(testEmail);
|
||||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
SendNewsletter(newletterSettings, html, testEmail);
|
||||
var letter = PlexNewsletter.GetNewsletter(testEmail) ?? new Newsletter();
|
||||
if (letter.Send)
|
||||
{
|
||||
SendNewsletter(newletterSettings, letter.Html, testEmail);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@
|
|||
<Compile Include="Jobs\EmbyEpisodeCacher.cs" />
|
||||
<Compile Include="Jobs\EmbyUserChecker.cs" />
|
||||
<Compile Include="Jobs\RadarrCacher.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\Newsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\PlexRecentlyAddedNewsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\EmbyRecentlyAddedNewsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\IPlexNewsletter.cs" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@using Ombi.UI.Helpers
|
||||
@using Ombi.UI.Helpers
|
||||
@Html.Partial("Shared/Partial/_Sidebar")
|
||||
@{
|
||||
int port;
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
{
|
||||
rootFolder = Model.RootPath.Replace("/", "//");
|
||||
rootFolder = rootFolder.Replace(@"\", @"\\");
|
||||
}
|
||||
}
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue