From 09897747122e1b17a8f4392057fb63bec32f3b6f Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Tue, 1 Feb 2022 17:25:37 +0100 Subject: [PATCH] bug(newsletter): Drop TVMaze from Newsletter (#4486) #4444 * Stop using TVMaze in newsletter * Better logging when an item is not published --- src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 48 ++++++++++---------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index 49101c52a..59aabe873 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -12,7 +12,6 @@ using Ombi.Api.Lidarr; using Ombi.Api.Lidarr.Models; using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb.Models; -using Ombi.Api.TvMaze; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; @@ -33,7 +32,7 @@ namespace Ombi.Schedule.Jobs.Ombi public class NewsletterJob : HtmlTemplateGenerator, INewsletterJob { public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, IJellyfinContentRepository jellyfin, IRepository addedLog, - IMovieDbApi movieApi, ITvMazeApi tvApi, IEmailProvider email, ISettingsService custom, + IMovieDbApi movieApi, IEmailProvider email, ISettingsService custom, ISettingsService emailSettings, INotificationTemplatesRepository templateRepo, UserManager um, ISettingsService newsletter, ILogger log, ILidarrApi lidarrApi, IExternalRepository albumCache, ISettingsService lidarrSettings, @@ -45,7 +44,6 @@ namespace Ombi.Schedule.Jobs.Ombi _jellyfin = jellyfin; _recentlyAddedLog = addedLog; _movieApi = movieApi; - _tvApi = tvApi; _email = email; _customizationSettings = custom; _templateRepo = templateRepo; @@ -73,7 +71,6 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly IMediaServerContentRepository _jellyfin; private readonly IRepository _recentlyAddedLog; private readonly IMovieDbApi _movieApi; - private readonly ITvMazeApi _tvApi; private readonly IEmailProvider _email; private readonly ISettingsService _customizationSettings; private readonly INotificationTemplatesRepository _templateRepo; @@ -264,7 +261,7 @@ namespace Ombi.Schedule.Jobs.Ombi recentlyAddedLog.Add(new RecentlyAddedLog { AddedAt = DateTime.Now, - Type = p.Series.RecentlyAddedType, + Type = p.Series.RecentlyAddedType, ContentType = ContentType.Episode, ContentId = StringHelper.IntParseLinq(p.Series.TvDbId), EpisodeNumber = p.EpisodeNumber, @@ -311,7 +308,7 @@ namespace Ombi.Schedule.Jobs.Ombi private HashSet GetSeriesContent(IMediaServerContentRepository repository, bool test) where T : class, IMediaServerContent { var content = repository.GetAllEpisodes().Include(x => x.Series).OrderByDescending(x => x.Series.AddedAt).AsNoTracking(); - + HashSet episodesToSend; if (test) { @@ -505,12 +502,14 @@ namespace Ombi.Schedule.Jobs.Ombi int.TryParse(content.TheMovieDbId, out var movieDbId); if (movieDbId <= 0) { + _log.LogWarning($"{content.Title} does not have a TMDB ID, it won't be published."); continue; } var info = await _movieApi.GetMovieInformationWithExtraInfo(movieDbId, defaultLanguageCode); var mediaurl = content.Url; if (info == null) { + _log.LogWarning($"TMDB does not know movie {content.Title}, it won't be published."); continue; } try @@ -674,6 +673,8 @@ namespace Ombi.Schedule.Jobs.Ombi var externals = await _movieApi.GetTvExternals(movieId); if (externals == null || externals.tvdb_id <= 0) { + // needed later for recently added log + _log.LogWarning($"{t.Title} has no TVDB ID, it won't be published."); continue; } t.TvDbId = externals.tvdb_id.ToString(); @@ -692,23 +693,17 @@ namespace Ombi.Schedule.Jobs.Ombi } - int.TryParse(t.TvDbId, out var tvdbId); - var info = await _tvApi.ShowLookupByTheTvDbId(tvdbId); - if (info == null) - { - continue; - } - try { - var banner = info.image?.original; - if (!string.IsNullOrEmpty(banner)) + var tvInfo = await _movieApi.GetTVInfo(t.TheMovieDbId, languageCode); + if (tvInfo == null) { - banner = banner.ToHttpsUrl(); // Always use the Https banners + _log.LogWarning($"TMDB does not know series {t.Title}, it won't be published."); + continue; } - var tvInfo = await _movieApi.GetTVInfo(t.TheMovieDbId, languageCode); - if (tvInfo != null && tvInfo.backdrop_path.HasValue()) + + if (tvInfo.backdrop_path.HasValue()) { AddBackgroundInsideTable($"https://image.tmdb.org/t/p/w500{tvInfo.backdrop_path}"); @@ -717,11 +712,18 @@ namespace Ombi.Schedule.Jobs.Ombi { AddBackgroundInsideTable($"https://image.tmdb.org/t/p/w1280/"); } + + var banner = tvInfo.poster_path; + if (!string.IsNullOrEmpty(banner)) + { + banner = $"https://image.tmdb.org/t/p/w300/{banner?.TrimStart('/') ?? string.Empty}"; + }; AddPosterInsideTable(banner); AddMediaServerUrl(t.Url, banner); + AddInfoTable(); - AddTvTitle(info, tvInfo); + AddTvTitle(tvInfo); // Group by the season number var results = t.Episodes.GroupBy(p => p.SeasonNumber, @@ -766,18 +768,18 @@ namespace Ombi.Schedule.Jobs.Ombi } } - private void AddTvTitle(Api.TvMaze.Models.TvMazeShow info, TvInfo tvInfo) + private void AddTvTitle(TvInfo tvInfo) { var title = ""; - if (!String.IsNullOrEmpty(info.premiered) && info.premiered.Length > 4) + if (!String.IsNullOrEmpty(tvInfo.first_air_date) && tvInfo.first_air_date.Length > 4) { - title = $"{tvInfo.name} ({info.premiered.Remove(4)})"; + title = $"{tvInfo.name} ({tvInfo.first_air_date.Remove(4)})"; } else { title = $"{tvInfo.name}"; } - AddTitle($"https://www.imdb.com/title/{info.externals.imdb}/", title); + AddTitle($"https://www.themoviedb.org/tv/{tvInfo.id}/", title); } private void AddTvEpisodesSummaryGenres(string episodes, TvInfo tvInfo)