bug(newsletter): Drop TVMaze from Newsletter (#4486) #4444

* Stop using TVMaze in newsletter

* Better logging when an item is not published
l10n_develop
sephrat 3 years ago committed by GitHub
parent aacdb4cb2a
commit 0989774712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,7 +12,6 @@ using Ombi.Api.Lidarr;
using Ombi.Api.Lidarr.Models; using Ombi.Api.Lidarr.Models;
using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models; using Ombi.Api.TheMovieDb.Models;
using Ombi.Api.TvMaze;
using Ombi.Core.Settings; using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External; using Ombi.Core.Settings.Models.External;
using Ombi.Helpers; using Ombi.Helpers;
@ -33,7 +32,7 @@ namespace Ombi.Schedule.Jobs.Ombi
public class NewsletterJob : HtmlTemplateGenerator, INewsletterJob public class NewsletterJob : HtmlTemplateGenerator, INewsletterJob
{ {
public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, IJellyfinContentRepository jellyfin, IRepository<RecentlyAddedLog> addedLog, public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, IJellyfinContentRepository jellyfin, IRepository<RecentlyAddedLog> addedLog,
IMovieDbApi movieApi, ITvMazeApi tvApi, IEmailProvider email, ISettingsService<CustomizationSettings> custom, IMovieDbApi movieApi, IEmailProvider email, ISettingsService<CustomizationSettings> custom,
ISettingsService<EmailNotificationSettings> emailSettings, INotificationTemplatesRepository templateRepo, ISettingsService<EmailNotificationSettings> emailSettings, INotificationTemplatesRepository templateRepo,
UserManager<OmbiUser> um, ISettingsService<NewsletterSettings> newsletter, ILogger<NewsletterJob> log, UserManager<OmbiUser> um, ISettingsService<NewsletterSettings> newsletter, ILogger<NewsletterJob> log,
ILidarrApi lidarrApi, IExternalRepository<LidarrAlbumCache> albumCache, ISettingsService<LidarrSettings> lidarrSettings, ILidarrApi lidarrApi, IExternalRepository<LidarrAlbumCache> albumCache, ISettingsService<LidarrSettings> lidarrSettings,
@ -45,7 +44,6 @@ namespace Ombi.Schedule.Jobs.Ombi
_jellyfin = jellyfin; _jellyfin = jellyfin;
_recentlyAddedLog = addedLog; _recentlyAddedLog = addedLog;
_movieApi = movieApi; _movieApi = movieApi;
_tvApi = tvApi;
_email = email; _email = email;
_customizationSettings = custom; _customizationSettings = custom;
_templateRepo = templateRepo; _templateRepo = templateRepo;
@ -73,7 +71,6 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly IMediaServerContentRepository<JellyfinContent> _jellyfin; private readonly IMediaServerContentRepository<JellyfinContent> _jellyfin;
private readonly IRepository<RecentlyAddedLog> _recentlyAddedLog; private readonly IRepository<RecentlyAddedLog> _recentlyAddedLog;
private readonly IMovieDbApi _movieApi; private readonly IMovieDbApi _movieApi;
private readonly ITvMazeApi _tvApi;
private readonly IEmailProvider _email; private readonly IEmailProvider _email;
private readonly ISettingsService<CustomizationSettings> _customizationSettings; private readonly ISettingsService<CustomizationSettings> _customizationSettings;
private readonly INotificationTemplatesRepository _templateRepo; private readonly INotificationTemplatesRepository _templateRepo;
@ -264,7 +261,7 @@ namespace Ombi.Schedule.Jobs.Ombi
recentlyAddedLog.Add(new RecentlyAddedLog recentlyAddedLog.Add(new RecentlyAddedLog
{ {
AddedAt = DateTime.Now, AddedAt = DateTime.Now,
Type = p.Series.RecentlyAddedType, Type = p.Series.RecentlyAddedType,
ContentType = ContentType.Episode, ContentType = ContentType.Episode,
ContentId = StringHelper.IntParseLinq(p.Series.TvDbId), ContentId = StringHelper.IntParseLinq(p.Series.TvDbId),
EpisodeNumber = p.EpisodeNumber, EpisodeNumber = p.EpisodeNumber,
@ -311,7 +308,7 @@ namespace Ombi.Schedule.Jobs.Ombi
private HashSet<IMediaServerEpisode> GetSeriesContent<T>(IMediaServerContentRepository<T> repository, bool test) where T : class, IMediaServerContent private HashSet<IMediaServerEpisode> GetSeriesContent<T>(IMediaServerContentRepository<T> repository, bool test) where T : class, IMediaServerContent
{ {
var content = repository.GetAllEpisodes().Include(x => x.Series).OrderByDescending(x => x.Series.AddedAt).AsNoTracking(); var content = repository.GetAllEpisodes().Include(x => x.Series).OrderByDescending(x => x.Series.AddedAt).AsNoTracking();
HashSet<IMediaServerEpisode> episodesToSend; HashSet<IMediaServerEpisode> episodesToSend;
if (test) if (test)
{ {
@ -505,12 +502,14 @@ namespace Ombi.Schedule.Jobs.Ombi
int.TryParse(content.TheMovieDbId, out var movieDbId); int.TryParse(content.TheMovieDbId, out var movieDbId);
if (movieDbId <= 0) if (movieDbId <= 0)
{ {
_log.LogWarning($"{content.Title} does not have a TMDB ID, it won't be published.");
continue; continue;
} }
var info = await _movieApi.GetMovieInformationWithExtraInfo(movieDbId, defaultLanguageCode); var info = await _movieApi.GetMovieInformationWithExtraInfo(movieDbId, defaultLanguageCode);
var mediaurl = content.Url; var mediaurl = content.Url;
if (info == null) if (info == null)
{ {
_log.LogWarning($"TMDB does not know movie {content.Title}, it won't be published.");
continue; continue;
} }
try try
@ -674,6 +673,8 @@ namespace Ombi.Schedule.Jobs.Ombi
var externals = await _movieApi.GetTvExternals(movieId); var externals = await _movieApi.GetTvExternals(movieId);
if (externals == null || externals.tvdb_id <= 0) 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; continue;
} }
t.TvDbId = externals.tvdb_id.ToString(); 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 try
{ {
var banner = info.image?.original; var tvInfo = await _movieApi.GetTVInfo(t.TheMovieDbId, languageCode);
if (!string.IsNullOrEmpty(banner)) 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}"); 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/"); 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); AddPosterInsideTable(banner);
AddMediaServerUrl(t.Url, banner); AddMediaServerUrl(t.Url, banner);
AddInfoTable(); AddInfoTable();
AddTvTitle(info, tvInfo); AddTvTitle(tvInfo);
// Group by the season number // Group by the season number
var results = t.Episodes.GroupBy(p => p.SeasonNumber, 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 = ""; 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 else
{ {
title = $"{tvInfo.name}"; 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) private void AddTvEpisodesSummaryGenres(string episodes, TvInfo tvInfo)

Loading…
Cancel
Save