From 3a634c7920109aae1f44112f3fef28f08c9a45df Mon Sep 17 00:00:00 2001 From: adamworley Date: Sun, 18 Oct 2020 09:51:25 +0100 Subject: [PATCH] Use the MovieDb to get episode info and set aired date --- src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index edd0802d8..7e3fff12e 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using MimeKit; +using Nito.AsyncEx; using Ombi.Api.CouchPotato.Models; using Ombi.Api.Lidarr; using Ombi.Api.Lidarr.Models; @@ -808,12 +809,14 @@ namespace Ombi.Schedule.Jobs.Ombi } ); + var allSeasonInfo = await results.Select(x => _movieApi.GetTVSeasonInfo(t.TheMovieDbId, x.SeasonNumber)).WhenAll(); + // 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 = BuildEpisodeList(orderedEpisodes.Select(x => (x.EpisodeNumber, x.Aired))); + var episodeString = BuildEpisodeList(orderedEpisodes.Select(x => (x.EpisodeNumber, GetDateAired(x, allSeasonInfo)))); var seasonAirDate = epInformation.SeasonAirDate; finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {episodeString} {seasonAirDate}"); finalsb.Append("
"); @@ -852,6 +855,14 @@ namespace Ombi.Schedule.Jobs.Ombi } } + private static DateTime? GetDateAired(PlexEpisode episode, TvSeason[] allSeasonInfo) + { + return DateTime.TryParse(allSeasonInfo.FirstOrDefault(_ => _.season_number == episode.SeasonNumber)?.episodes + .FirstOrDefault(e => e.episode_number == episode.EpisodeNumber)?.air_date, out var airedDate) + ? airedDate + : (DateTime?)null; + } + public static string BuildEpisodeList(IEnumerable<(int EpisodeNumber, DateTime? Aired)> orderedEpisodes) { var epSb = new StringBuilder();