mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 21:33:15 -07:00
Made the episode list in the newsletter easier to read. Rather than 1,2,3,4,5,10 we will now show 1-5, 10
This commit is contained in:
parent
856ec03377
commit
479bae8a6a
3 changed files with 94 additions and 34 deletions
43
src/Ombi.Schedule.Tests/NewsletterTests.cs
Normal file
43
src/Ombi.Schedule.Tests/NewsletterTests.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Schedule.Jobs.Ombi;
|
||||||
|
using Ombi.Settings.Settings.Models;
|
||||||
|
using Ombi.Settings.Settings.Models.Notifications;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
|
||||||
|
namespace Ombi.Schedule.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class NewsletterTests
|
||||||
|
{
|
||||||
|
[TestCaseSource(nameof(EpisodeListData))]
|
||||||
|
public string BuildEpisodeListTest(List<int> episodes)
|
||||||
|
{
|
||||||
|
var emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>();
|
||||||
|
var customziation = new Mock<ISettingsService<CustomizationSettings>>();
|
||||||
|
var newsletterSettings = new Mock<ISettingsService<NewsletterSettings>>();
|
||||||
|
var newsletter = new NewsletterJob(null, null, null, null, null, null, customziation.Object, emailSettings.Object, null, null, newsletterSettings.Object, null);
|
||||||
|
|
||||||
|
var ep = new List<int>();
|
||||||
|
foreach (var i in episodes)
|
||||||
|
{
|
||||||
|
ep.Add(i);
|
||||||
|
}
|
||||||
|
var result = newsletter.BuildEpisodeList(ep);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<TestCaseData> EpisodeListData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return new TestCaseData(new List<int>{1,2,3,4,5,6}).Returns("1-6").SetName("Simple 1-6");
|
||||||
|
yield return new TestCaseData(new List<int>{1,2,3,4,5,6,8,9}).Returns("1-6, 8-9").SetName("Simple 1-6, 8-9");
|
||||||
|
yield return new TestCaseData(new List<int>{1,99,101,555,468,469}).Returns("1, 99, 101, 555, 468-469").SetName("More Complex");
|
||||||
|
yield return new TestCaseData(new List<int>{1}).Returns("1").SetName("Single Episode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,10 +8,10 @@
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
|
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
|
||||||
<PackageReference Include="Moq" Version="4.7.99" />
|
<PackageReference Include="Moq" Version="4.7.99" />
|
||||||
<PackageReference Include="Nunit" Version="3.8.1" />
|
<PackageReference Include="Nunit" Version="3.10.1" />
|
||||||
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
|
<PackageReference Include="NUnit.ConsoleRunner" Version="3.8.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
|
||||||
<packagereference Include="Microsoft.NET.Test.Sdk" Version="15.6.1"></packagereference>
|
<packagereference Include="Microsoft.NET.Test.Sdk" Version="15.7.0"></packagereference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -557,21 +557,8 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
foreach (var epInformation in results.OrderBy(x => x.SeasonNumber))
|
foreach (var epInformation in results.OrderBy(x => x.SeasonNumber))
|
||||||
{
|
{
|
||||||
var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
|
var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
|
||||||
var epSb = new StringBuilder();
|
var episodeString = BuildEpisodeList(orderedEpisodes.Select(x => x.EpisodeNumber));
|
||||||
for (var i = 0; i < orderedEpisodes.Count; i++)
|
finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {episodeString}");
|
||||||
{
|
|
||||||
var ep = orderedEpisodes[i];
|
|
||||||
if (i < orderedEpisodes.Count - 1)
|
|
||||||
{
|
|
||||||
epSb.Append($"{ep.EpisodeNumber},");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
epSb.Append($"{ep.EpisodeNumber}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {epSb}");
|
|
||||||
finalsb.Append("<br />");
|
finalsb.Append("<br />");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,6 +595,49 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string BuildEpisodeList(IEnumerable<int> orderedEpisodes)
|
||||||
|
{
|
||||||
|
var epSb = new StringBuilder();
|
||||||
|
var previousEpisodes = new List<int>();
|
||||||
|
var previousEpisode = -1;
|
||||||
|
foreach (var ep in orderedEpisodes)
|
||||||
|
{
|
||||||
|
if (ep - 1 == previousEpisode)
|
||||||
|
{
|
||||||
|
// This is the next one
|
||||||
|
previousEpisodes.Add(ep);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (previousEpisodes.Count > 1)
|
||||||
|
{
|
||||||
|
// End it
|
||||||
|
epSb.Append($"{previousEpisodes.First()}-{previousEpisodes.Last()}, ");
|
||||||
|
}
|
||||||
|
else if (previousEpisodes.Count == 1)
|
||||||
|
{
|
||||||
|
epSb.Append($"{previousEpisodes.FirstOrDefault()}, ");
|
||||||
|
}
|
||||||
|
// New one
|
||||||
|
previousEpisodes.Clear();
|
||||||
|
previousEpisodes.Add(ep);
|
||||||
|
}
|
||||||
|
previousEpisode = ep;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previousEpisodes.Count > 1)
|
||||||
|
{
|
||||||
|
// Got some left over
|
||||||
|
epSb.Append($"{previousEpisodes.First()}-{previousEpisodes.Last()}");
|
||||||
|
}
|
||||||
|
else if(previousEpisodes.Count == 1)
|
||||||
|
{
|
||||||
|
epSb.Append(previousEpisodes.FirstOrDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
return epSb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task ProcessEmbyTv(HashSet<EmbyEpisode> embyContent, StringBuilder sb)
|
private async Task ProcessEmbyTv(HashSet<EmbyEpisode> embyContent, StringBuilder sb)
|
||||||
{
|
{
|
||||||
var series = new List<EmbyContent>();
|
var series = new List<EmbyContent>();
|
||||||
|
@ -681,21 +711,8 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
foreach (var epInformation in results.OrderBy(x => x.SeasonNumber))
|
foreach (var epInformation in results.OrderBy(x => x.SeasonNumber))
|
||||||
{
|
{
|
||||||
var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
|
var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
|
||||||
var epSb = new StringBuilder();
|
var episodeString = BuildEpisodeList(orderedEpisodes.Select(x => x.EpisodeNumber));
|
||||||
for (var i = 0; i < orderedEpisodes.Count; i++)
|
finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {episodeString}");
|
||||||
{
|
|
||||||
var ep = orderedEpisodes[i];
|
|
||||||
if (i < orderedEpisodes.Count - 1)
|
|
||||||
{
|
|
||||||
epSb.Append($"{ep.EpisodeNumber},");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
epSb.Append($"{ep.EpisodeNumber}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {epSb}");
|
|
||||||
finalsb.Append("<br />");
|
finalsb.Append("<br />");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue