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]
pull/4500/head
sephrat 3 years ago committed by GitHub
parent ddf63fbed0
commit 4e7546f635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -726,28 +726,8 @@ namespace Ombi.Schedule.Jobs.Ombi
AddTvTitle(tvInfo); AddTvTitle(tvInfo);
// Group by the season number var tvEpisodesString = GetTvEpisodesString(tvInfo, t.Episodes);
var results = t.Episodes.GroupBy(p => p.SeasonNumber, AddTvEpisodesSummaryGenres(tvEpisodesString, tvInfo);
(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("<br />");
}
AddTvEpisodesSummaryGenres(finalsb.ToString(), tvInfo);
} }
catch (Exception e) catch (Exception e)
@ -769,6 +749,44 @@ namespace Ombi.Schedule.Jobs.Ombi
} }
} }
private string GetTvEpisodesString(TvInfo tvInfo, ICollection<IMediaServerEpisode> 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("<br />");
}
return sb.ToString();
}
private void AddTvTitle(TvInfo tvInfo) private void AddTvTitle(TvInfo tvInfo)
{ {
var title = ""; var title = "";

Loading…
Cancel
Save