mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Merge branch 'develop' into feature/embynewsletterfixes
This commit is contained in:
commit
76381509e9
4 changed files with 118 additions and 89 deletions
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||||
using MailKit;
|
using MailKit;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Ombi.Api.TheMovieDb;
|
using Ombi.Api.TheMovieDb;
|
||||||
using Ombi.Api.TheMovieDb.Models;
|
using Ombi.Api.TheMovieDb.Models;
|
||||||
using Ombi.Api.TvMaze;
|
using Ombi.Api.TvMaze;
|
||||||
|
@ -28,7 +29,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, IRepository<RecentlyAddedLog> addedLog,
|
public NewsletterJob(IPlexContentRepository plex, IEmbyContentRepository emby, IRepository<RecentlyAddedLog> addedLog,
|
||||||
IMovieDbApi movieApi, ITvMazeApi tvApi, IEmailProvider email, ISettingsService<CustomizationSettings> custom,
|
IMovieDbApi movieApi, ITvMazeApi tvApi, IEmailProvider email, ISettingsService<CustomizationSettings> custom,
|
||||||
ISettingsService<EmailNotificationSettings> emailSettings, INotificationTemplatesRepository templateRepo,
|
ISettingsService<EmailNotificationSettings> emailSettings, INotificationTemplatesRepository templateRepo,
|
||||||
UserManager<OmbiUser> um, ISettingsService<NewsletterSettings> newsletter)
|
UserManager<OmbiUser> um, ISettingsService<NewsletterSettings> newsletter, ILogger<NewsletterJob> log)
|
||||||
{
|
{
|
||||||
_plex = plex;
|
_plex = plex;
|
||||||
_emby = emby;
|
_emby = emby;
|
||||||
|
@ -44,6 +45,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
_emailSettings.ClearCache();
|
_emailSettings.ClearCache();
|
||||||
_customizationSettings.ClearCache();
|
_customizationSettings.ClearCache();
|
||||||
_newsletterSettings.ClearCache();
|
_newsletterSettings.ClearCache();
|
||||||
|
_log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IPlexContentRepository _plex;
|
private readonly IPlexContentRepository _plex;
|
||||||
|
@ -57,6 +59,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
private readonly ISettingsService<EmailNotificationSettings> _emailSettings;
|
private readonly ISettingsService<EmailNotificationSettings> _emailSettings;
|
||||||
private readonly ISettingsService<NewsletterSettings> _newsletterSettings;
|
private readonly ISettingsService<NewsletterSettings> _newsletterSettings;
|
||||||
private readonly UserManager<OmbiUser> _userManager;
|
private readonly UserManager<OmbiUser> _userManager;
|
||||||
|
private readonly ILogger _log;
|
||||||
|
|
||||||
public async Task Start(NewsletterSettings settings, bool test)
|
public async Task Start(NewsletterSettings settings, bool test)
|
||||||
{
|
{
|
||||||
|
@ -76,15 +79,11 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var customization = await _customizationSettings.GetSettingsAsync();
|
try
|
||||||
|
{
|
||||||
|
|
||||||
// Get the Content
|
|
||||||
var plexContent = _plex.GetAll().Include(x => x.Episodes).AsNoTracking();
|
|
||||||
var embyContent = _emby.GetAll().Include(x => x.Episodes).AsNoTracking();
|
|
||||||
|
|
||||||
var addedLog = _recentlyAddedLog.GetAll();
|
var customization = await _customizationSettings.GetSettingsAsync();
|
||||||
var addedPlexMovieLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Plex && x.ContentType == ContentType.Parent).Select(x => x.ContentId);
|
|
||||||
var addedEmbyMoviesLogIds = addedLog.Where(x => x.Type == RecentlyAddedType.Emby && x.ContentType == ContentType.Parent).Select(x => x.ContentId);
|
|
||||||
|
|
||||||
var addedPlexEpisodesLogIds =
|
var addedPlexEpisodesLogIds =
|
||||||
addedLog.Where(x => x.Type == RecentlyAddedType.Plex && x.ContentType == ContentType.Episode);
|
addedLog.Where(x => x.Type == RecentlyAddedType.Plex && x.ContentType == ContentType.Episode);
|
||||||
|
@ -94,13 +93,16 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
// Filter out the ones that we haven't sent yet
|
// Filter out the ones that we haven't sent yet
|
||||||
var plexContentMoviesToSend = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Movie && !addedPlexMovieLogIds.Contains(int.Parse(x.TheMovieDbId)));
|
var plexContentMoviesToSend = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Movie && !addedPlexMovieLogIds.Contains(int.Parse(x.TheMovieDbId)));
|
||||||
var embyContentMoviesToSend = embyContent.Where(x => x.Type == EmbyMediaType.Movie && !addedEmbyMoviesLogIds.Contains(int.Parse(x.TheMovieDbId)));
|
var embyContentMoviesToSend = embyContent.Where(x => x.Type == EmbyMediaType.Movie && !addedEmbyMoviesLogIds.Contains(int.Parse(x.TheMovieDbId)));
|
||||||
|
_log.LogInformation("Plex Movies to send: {0}", plexContentMoviesToSend.Count());
|
||||||
|
_log.LogInformation("Emby Movies to send: {0}", embyContentMoviesToSend.Count());
|
||||||
|
|
||||||
var plexEpisodesToSend =
|
var plexEpisodesToSend =
|
||||||
FilterPlexEpisodes(_plex.GetAllEpisodes().Include(x => x.Series).AsNoTracking(), addedPlexEpisodesLogIds);
|
FilterPlexEpisodes(_plex.GetAllEpisodes().Include(x => x.Series).AsNoTracking(), addedPlexEpisodesLogIds);
|
||||||
var embyEpisodesToSend = FilterEmbyEpisodes(_emby.GetAllEpisodes().Include(x => x.Series).AsNoTracking(),
|
var embyEpisodesToSend = FilterEmbyEpisodes(_emby.GetAllEpisodes().Include(x => x.Series).AsNoTracking(),
|
||||||
addedEmbyEpisodesLogIds);
|
addedEmbyEpisodesLogIds);
|
||||||
|
|
||||||
|
_log.LogInformation("Plex Episodes to send: {0}", plexEpisodesToSend.Count());
|
||||||
|
_log.LogInformation("Emby Episodes to send: {0}", embyEpisodesToSend.Count());
|
||||||
var body = string.Empty;
|
var body = string.Empty;
|
||||||
if (test)
|
if (test)
|
||||||
{
|
{
|
||||||
|
@ -128,50 +130,68 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//foreach (var emails in settings.ExternalEmails)
|
foreach (var emails in settings.ExternalEmails)
|
||||||
//{
|
{
|
||||||
// users.Add(new OmbiUser
|
users.Add(new OmbiUser
|
||||||
// {
|
{
|
||||||
// UserName = emails,
|
UserName = emails,
|
||||||
// Email = emails
|
Email = emails
|
||||||
// });
|
});
|
||||||
//}
|
}
|
||||||
var emailTasks = new List<Task>();
|
var emailTasks = new List<Task>();
|
||||||
foreach (var user in users)
|
foreach (var user in users)
|
||||||
{
|
{
|
||||||
if (user.Email.IsNullOrEmpty())
|
// Get the users to send it to
|
||||||
|
var users = await _userManager.GetUsersInRoleAsync(OmbiRoles.RecievesNewsletter);
|
||||||
|
if (!users.Any())
|
||||||
{
|
{
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var messageContent = ParseTemplate(template, customization, user);
|
foreach (var emails in settings.ExternalEmails)
|
||||||
var email = new NewsletterTemplate();
|
|
||||||
|
|
||||||
var html = email.LoadTemplate(messageContent.Subject, messageContent.Message, body, customization.Logo);
|
|
||||||
|
|
||||||
emailTasks.Add(_email.Send(
|
|
||||||
new NotificationMessage { Message = html, Subject = messageContent.Subject, To = user.Email },
|
|
||||||
emailSettings));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now add all of this to the Recently Added log
|
|
||||||
var recentlyAddedLog = new HashSet<RecentlyAddedLog>();
|
|
||||||
foreach (var p in plexContentMoviesToSend)
|
|
||||||
{
|
|
||||||
recentlyAddedLog.Add(new RecentlyAddedLog
|
|
||||||
{
|
{
|
||||||
|
users.Add(new OmbiUser
|
||||||
|
{
|
||||||
|
UserName = emails,
|
||||||
|
Email = emails
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var emailTasks = new List<Task>();
|
||||||
|
foreach (var user in users)
|
||||||
|
{
|
||||||
|
if (user.Email.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var messageContent = ParseTemplate(template, customization, user);
|
||||||
|
var email = new NewsletterTemplate();
|
||||||
|
|
||||||
|
var html = email.LoadTemplate(messageContent.Subject, messageContent.Message, body, customization.Logo);
|
||||||
|
|
||||||
|
emailTasks.Add(_email.Send(
|
||||||
|
new NotificationMessage { Message = html, Subject = messageContent.Subject, To = user.Email },
|
||||||
|
emailSettings));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now add all of this to the Recently Added log
|
||||||
|
var recentlyAddedLog = new HashSet<RecentlyAddedLog>();
|
||||||
|
foreach (var p in plexContentMoviesToSend)
|
||||||
|
{
|
||||||
|
recentlyAddedLog.Add(new RecentlyAddedLog
|
||||||
|
{
|
||||||
AddedAt = DateTime.Now,
|
AddedAt = DateTime.Now,
|
||||||
Type = RecentlyAddedType.Plex,
|
Type = RecentlyAddedType.Plex,
|
||||||
ContentType = ContentType.Parent,
|
ContentType = ContentType.Parent,
|
||||||
ContentId = int.Parse(p.TheMovieDbId),
|
ContentId = int.Parse(p.TheMovieDbId),
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var p in plexEpisodesToSend)
|
foreach (var p in plexEpisodesToSend)
|
||||||
{
|
{
|
||||||
recentlyAddedLog.Add(new RecentlyAddedLog
|
recentlyAddedLog.Add(new RecentlyAddedLog
|
||||||
{
|
{
|
||||||
AddedAt = DateTime.Now,
|
AddedAt = DateTime.Now,
|
||||||
Type = RecentlyAddedType.Plex,
|
Type = RecentlyAddedType.Plex,
|
||||||
ContentType = ContentType.Episode,
|
ContentType = ContentType.Episode,
|
||||||
|
@ -180,56 +200,61 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
SeasonNumber = p.SeasonNumber
|
SeasonNumber = p.SeasonNumber
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
foreach (var e in embyContentMoviesToSend)
|
||||||
|
{
|
||||||
|
if (e.Type == EmbyMediaType.Movie)
|
||||||
|
{
|
||||||
|
recentlyAddedLog.Add(new RecentlyAddedLog
|
||||||
|
{
|
||||||
|
AddedAt = DateTime.Now,
|
||||||
|
Type = RecentlyAddedType.Emby,
|
||||||
|
ContentType = ContentType.Parent,
|
||||||
|
ContentId = int.Parse(e.TheMovieDbId),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var e in embyContentMoviesToSend)
|
foreach (var p in embyEpisodesToSend)
|
||||||
{
|
|
||||||
if (e.Type == EmbyMediaType.Movie)
|
|
||||||
{
|
{
|
||||||
recentlyAddedLog.Add(new RecentlyAddedLog
|
recentlyAddedLog.Add(new RecentlyAddedLog
|
||||||
{
|
{
|
||||||
AddedAt = DateTime.Now,
|
AddedAt = DateTime.Now,
|
||||||
Type = RecentlyAddedType.Emby,
|
Type = RecentlyAddedType.Emby,
|
||||||
ContentType = ContentType.Parent,
|
ContentType = ContentType.Episode,
|
||||||
ContentId = int.Parse(e.TheMovieDbId),
|
ContentId = int.Parse(p.Series.TvDbId),
|
||||||
|
EpisodeNumber = p.EpisodeNumber,
|
||||||
|
SeasonNumber = p.SeasonNumber
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
await _recentlyAddedLog.AddRange(recentlyAddedLog);
|
||||||
|
await Task.WhenAll(emailTasks.ToArray());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
foreach (var p in embyEpisodesToSend)
|
|
||||||
{
|
{
|
||||||
recentlyAddedLog.Add(new RecentlyAddedLog
|
var admins = await _userManager.GetUsersInRoleAsync(OmbiRoles.Admin);
|
||||||
|
foreach (var a in admins)
|
||||||
{
|
{
|
||||||
AddedAt = DateTime.Now,
|
if (a.Email.IsNullOrEmpty())
|
||||||
Type = RecentlyAddedType.Emby,
|
{
|
||||||
ContentType = ContentType.Episode,
|
continue;
|
||||||
ContentId = int.Parse(p.Series.TvDbId),
|
}
|
||||||
EpisodeNumber = p.EpisodeNumber,
|
var messageContent = ParseTemplate(template, customization, a);
|
||||||
SeasonNumber = p.SeasonNumber
|
|
||||||
});
|
|
||||||
}
|
|
||||||
await _recentlyAddedLog.AddRange(recentlyAddedLog);
|
|
||||||
|
|
||||||
await Task.WhenAll(emailTasks.ToArray());
|
var email = new NewsletterTemplate();
|
||||||
}
|
|
||||||
else
|
var html = email.LoadTemplate(messageContent.Subject, messageContent.Message, body, customization.Logo);
|
||||||
{
|
|
||||||
var admins = await _userManager.GetUsersInRoleAsync(OmbiRoles.Admin);
|
await _email.Send(
|
||||||
foreach (var a in admins)
|
new NotificationMessage { Message = html, Subject = messageContent.Subject, To = a.Email },
|
||||||
{
|
emailSettings);
|
||||||
if (a.Email.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
var messageContent = ParseTemplate(template, customization, a);
|
|
||||||
|
|
||||||
var email = new NewsletterTemplate();
|
|
||||||
|
|
||||||
var html = email.LoadTemplate(messageContent.Subject, messageContent.Message, body, customization.Logo);
|
|
||||||
|
|
||||||
await _email.Send(
|
|
||||||
new NotificationMessage { Message = html, Subject = messageContent.Subject, To = a.Email },
|
|
||||||
emailSettings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.LogError(e, "Error when attempting to create newsletter");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,8 +354,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
_log.LogError(e, "Error when Processing Plex Movies {0}", info.Title);
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -359,7 +383,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
|
|
||||||
theMovieDbId = result.id.ToString();
|
theMovieDbId = result.id.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
var info = await _movieApi.GetMovieInformationWithExtraInfo(int.Parse(theMovieDbId));
|
var info = await _movieApi.GetMovieInformationWithExtraInfo(int.Parse(theMovieDbId));
|
||||||
if (info == null)
|
if (info == null)
|
||||||
{
|
{
|
||||||
|
@ -371,8 +395,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
_log.LogError(e, "Error when processing Emby Movies {0}", info.Title);
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -481,7 +504,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
sb.Append("<tr>");
|
sb.Append("<tr>");
|
||||||
sb.Append(
|
sb.Append(
|
||||||
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
"<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");
|
||||||
|
|
||||||
var title = $"{t.Title} ({t.ReleaseYear})";
|
var title = $"{t.Title} ({t.ReleaseYear})";
|
||||||
|
|
||||||
Href(sb, $"https://www.imdb.com/title/{info.externals.imdb}/");
|
Href(sb, $"https://www.imdb.com/title/{info.externals.imdb}/");
|
||||||
|
@ -527,7 +550,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
//Log.Error(e);
|
_log.LogError(e, "Error when processing Plex TV {0}", t.Title);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -628,7 +651,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
//Log.Error(e);
|
_log.LogError(e, "Error when processing Emby TV {0}", t.Title);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,6 @@ namespace Ombi.Settings.Settings.Models.Notifications
|
||||||
public bool DisableTv { get; set; }
|
public bool DisableTv { get; set; }
|
||||||
public bool DisableMovies { get; set; }
|
public bool DisableMovies { get; set; }
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public List<string> ExternalEmails { get; set; }
|
public List<string> ExternalEmails { get; set; } = new List<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,11 +43,11 @@ include the remember me checkbox
|
||||||
<!-- Main OAuth Flow -->
|
<!-- Main OAuth Flow -->
|
||||||
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi">
|
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi">
|
||||||
<button class="btn btn-success" type="button" (click)="loginWithOmbi = true">
|
<button class="btn btn-success" type="button" (click)="loginWithOmbi = true">
|
||||||
Login With {{appName}}</button>
|
Sign In With {{appName}}</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi">
|
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi">
|
||||||
<button class="btn btn-primary" type="button" (click)="oauth()">
|
<button class="btn btn-primary" type="button" (click)="oauth()">
|
||||||
Continue With Plex</button>
|
Sign In With Plex</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,4 +55,4 @@ include the remember me checkbox
|
||||||
<!-- /card-container -->
|
<!-- /card-container -->
|
||||||
</div>
|
</div>
|
||||||
<!-- /container -->
|
<!-- /container -->
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -87,8 +87,14 @@ O:::::::OOO:::::::Om::::m m::::m m::::mb:::::bbbbbb::::::bi::::::i
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@{
|
@{
|
||||||
if (customization.HasPresetTheme)
|
if (customization.HasPresetTheme)
|
||||||
{
|
{
|
||||||
|
if (!string.IsNullOrEmpty(baseUrl))
|
||||||
|
{
|
||||||
|
var index = customization.PresetThemeContent.IndexOf("/api/");
|
||||||
|
customization.PresetThemeContent = customization.PresetThemeContent.Insert(index, "/" + baseUrl);
|
||||||
|
}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@Html.Raw(customization.PresetThemeContent)
|
@Html.Raw(customization.PresetThemeContent)
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue