|
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|
|
|
|
using MailKit;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Ombi.Api.TheMovieDb;
|
|
|
|
|
using Ombi.Api.TheMovieDb.Models;
|
|
|
|
|
using Ombi.Api.TvMaze;
|
|
|
|
@ -26,7 +27,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, IRepository<RecentlyAddedLog> addedLog,
|
|
|
|
|
IMovieDbApi movieApi, ITvMazeApi tvApi, IEmailProvider email, ISettingsService<CustomizationSettings> custom,
|
|
|
|
|
ISettingsService<EmailNotificationSettings> emailSettings, INotificationTemplatesRepository templateRepo,
|
|
|
|
|
UserManager<OmbiUser> um, ISettingsService<NewsletterSettings> newsletter)
|
|
|
|
|
UserManager<OmbiUser> um, ISettingsService<NewsletterSettings> newsletter, ILogger<NewsletterJob> log)
|
|
|
|
|
{
|
|
|
|
|
_plex = plex;
|
|
|
|
|
_emby = emby;
|
|
|
|
@ -42,6 +43,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
_emailSettings.ClearCache();
|
|
|
|
|
_customizationSettings.ClearCache();
|
|
|
|
|
_newsletterSettings.ClearCache();
|
|
|
|
|
_log = log;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly IPlexContentRepository _plex;
|
|
|
|
@ -55,6 +57,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
private readonly ISettingsService<EmailNotificationSettings> _emailSettings;
|
|
|
|
|
private readonly ISettingsService<NewsletterSettings> _newsletterSettings;
|
|
|
|
|
private readonly UserManager<OmbiUser> _userManager;
|
|
|
|
|
private readonly ILogger _log;
|
|
|
|
|
|
|
|
|
|
public async Task Start(NewsletterSettings settings, bool test)
|
|
|
|
|
{
|
|
|
|
@ -74,6 +77,10 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var customization = await _customizationSettings.GetSettingsAsync();
|
|
|
|
|
|
|
|
|
|
// Get the Content
|
|
|
|
@ -90,10 +97,15 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
// Filter out the ones that we haven't sent yet
|
|
|
|
|
var plexContentMoviesToSend = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Movie && !addedPlexMovieLogIds.Contains(x.Id));
|
|
|
|
|
var embyContentMoviesToSend = embyContent.Where(x => x.Type == EmbyMediaType.Movie && !addedEmbyMoviesLogIds.Contains(x.Id));
|
|
|
|
|
_log.LogInformation("Plex Movies to send: {0}", plexContentMoviesToSend.Count());
|
|
|
|
|
_log.LogInformation("Emby Movies to send: {0}", embyContentMoviesToSend.Count());
|
|
|
|
|
|
|
|
|
|
var plexEpisodesToSend = _plex.GetAllEpisodes().Include(x => x.Series).Where(x => !addedPlexEpisodesLogIds.Contains(x.Id)).AsNoTracking();
|
|
|
|
|
var embyEpisodesToSend = _emby.GetAllEpisodes().Include(x => x.Series).Where(x => !addedEmbyEpisodesLogIds.Contains(x.Id)).AsNoTracking();
|
|
|
|
|
|
|
|
|
|
_log.LogInformation("Plex Episodes to send: {0}", plexEpisodesToSend.Count());
|
|
|
|
|
_log.LogInformation("Emby Episodes to send: {0}", embyEpisodesToSend.Count());
|
|
|
|
|
|
|
|
|
|
var body = string.Empty;
|
|
|
|
|
if (test)
|
|
|
|
|
{
|
|
|
|
@ -110,7 +122,6 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!test)
|
|
|
|
@ -221,6 +232,13 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
emailSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_log.LogError(e, "Error when attempting to create newsletter");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Start()
|
|
|
|
@ -285,8 +303,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
throw;
|
|
|
|
|
_log.LogError(e, "Error when Processing Plex Movies {0}", info.Title);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
@ -327,8 +344,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
throw;
|
|
|
|
|
_log.LogError(e, "Error when processing Emby Movies {0}", info.Title);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
@ -483,7 +499,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
//Log.Error(e);
|
|
|
|
|
_log.LogError(e, "Error when processing Plex TV {0}", t.Title);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
@ -584,7 +600,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
//Log.Error(e);
|
|
|
|
|
_log.LogError(e, "Error when processing Emby TV {0}", t.Title);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|