From 4e7546f63565cca232162de4dd477a9991591a16 Mon Sep 17 00:00:00 2001
From: sephrat <34862846+sephrat@users.noreply.github.com>
Date: Sat, 5 Feb 2022 22:13:32 +0100
Subject: [PATCH] fix(newsletter):Declutter newsletter info for series (#4494)
* Declutter newsletter info for series
- Do not list episodes if the series is complete
- Do not list all episodes of a season if the season is complete
* Use proper empty string constant
[skip ci]
---
src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 62 +++++++++++++-------
1 file changed, 40 insertions(+), 22 deletions(-)
diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs
index f965625f6..dbb343126 100644
--- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs
+++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs
@@ -726,28 +726,8 @@ namespace Ombi.Schedule.Jobs.Ombi
AddTvTitle(tvInfo);
- // Group by the season number
- var results = t.Episodes.GroupBy(p => p.SeasonNumber,
- (key, g) => new
- {
- SeasonNumber = key,
- Episodes = g.ToList(),
- EpisodeAirDate = tvInfo?.seasons?.Where(x => x.season_number == key)?.Select(x => x.air_date).FirstOrDefault()
- }
- );
-
- // Group the episodes
- var finalsb = new StringBuilder();
- foreach (var epInformation in results.OrderBy(x => x.SeasonNumber))
- {
- var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
- var episodeString = StringHelper.BuildEpisodeList(orderedEpisodes.Select(x => x.EpisodeNumber));
- var episodeAirDate = epInformation.EpisodeAirDate;
- finalsb.Append($"{Texts.SeasonLabel} {epInformation.SeasonNumber} - {Texts.EpisodesLabel} {episodeString} {episodeAirDate}");
- finalsb.Append("
");
- }
-
- AddTvEpisodesSummaryGenres(finalsb.ToString(), tvInfo);
+ var tvEpisodesString = GetTvEpisodesString(tvInfo, t.Episodes);
+ AddTvEpisodesSummaryGenres(tvEpisodesString, tvInfo);
}
catch (Exception e)
@@ -769,6 +749,44 @@ namespace Ombi.Schedule.Jobs.Ombi
}
}
+ private string GetTvEpisodesString(TvInfo tvInfo, ICollection episodes)
+ {
+ if (episodes.Count >= tvInfo.number_of_episodes)
+ {
+ // do not list individual episodes when the series is complete
+ return string.Empty;
+ }
+
+ var sb = new StringBuilder();
+ // Group by the season number
+ var seasons = episodes.GroupBy(p => p.SeasonNumber,
+ (key, g) => new
+ {
+ SeasonNumber = key,
+ Episodes = g.ToList(),
+ Header = tvInfo?.seasons?.Where(x => x.season_number == key).FirstOrDefault(),
+ }
+ );
+ // Group the episodes
+ foreach (var season in seasons.OrderBy(x => x.SeasonNumber))
+ {
+ string episodeList;
+ if (season.Episodes.Count >= season.Header.episode_count)
+ {
+ // do not list individual episodes when the season is complete
+ episodeList = string.Empty;
+ }
+ else
+ {
+ var orderedEpisodes = season.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
+ episodeList = $"{Texts.EpisodesLabel} {StringHelper.BuildEpisodeList(orderedEpisodes.Select(x => x.EpisodeNumber))}";
+ }
+ var episodeAirDate = season.Header.air_date;
+ sb.Append($"{Texts.SeasonLabel} {season.SeasonNumber} - {episodeList} {episodeAirDate}");
+ sb.Append("
");
+ }
+ return sb.ToString();
+ }
private void AddTvTitle(TvInfo tvInfo)
{
var title = "";