mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Looks like we were overloading emby with out api calls.
Put a bit of handling around that to wait when we get some errors. Problem about this is it can take a long time to generate the infomation when we have episode searching enabled. #1109
This commit is contained in:
parent
717b499874
commit
b9c0c20af6
3 changed files with 63 additions and 39 deletions
|
@ -185,7 +185,6 @@ namespace Ombi.Api
|
|||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
|
||||
var info = new EmbyInformation();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using Ombi.Api;
|
||||
using Ombi.Api.Interfaces;
|
||||
|
@ -116,7 +117,6 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
var filteredMovies = movie.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList();
|
||||
var filteredEp = episodes.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList();
|
||||
|
||||
|
||||
var info = new List<EmbyRecentlyAddedModel>();
|
||||
foreach (var m in filteredMovies)
|
||||
{
|
||||
|
@ -137,28 +137,41 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
{
|
||||
var i = Api.GetInformation(t.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
|
||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||
var ep = filteredEp.Where(x => x.ParentId == t.EmbyId);
|
||||
|
||||
if (ep.Any())
|
||||
var ep = filteredEp.Where(x => x.ParentId == t.EmbyId).ToList();
|
||||
var item = new EmbyRecentlyAddedModel
|
||||
{
|
||||
var episodeList = new List<EmbyEpisodeInformation>();
|
||||
foreach (var embyEpisodese in ep)
|
||||
EmbyContent = t,
|
||||
EmbyInformation = i,
|
||||
};
|
||||
if (ep.Any() && embySettings.EnableEpisodeSearching)
|
||||
{
|
||||
try
|
||||
{
|
||||
var epInfo = Api.GetInformation(embyEpisodese.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Episode,
|
||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||
episodeList.Add(epInfo.EpisodeInformation);
|
||||
var episodeList = new List<EmbyEpisodeInformation>();
|
||||
foreach (var embyEpisodese in ep)
|
||||
{
|
||||
var epInfo = Api.GetInformation(embyEpisodese.EmbyId,
|
||||
Ombi.Api.Models.Emby.EmbyMediaType.Episode,
|
||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||
episodeList.Add(epInfo.EpisodeInformation);
|
||||
Thread.Sleep(200); // Let's not try and overload the server
|
||||
}
|
||||
item.EpisodeInformation = episodeList;
|
||||
}
|
||||
info.Add(new EmbyRecentlyAddedModel
|
||||
catch (JsonReaderException)
|
||||
{
|
||||
EmbyContent = t,
|
||||
EmbyInformation = i,
|
||||
EpisodeInformation = episodeList
|
||||
});
|
||||
Log.Error(
|
||||
"Failed getting episode information, we may have overloaded Emby's api... Waiting and we will skip this one and go to the next");
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
info.Add(item);
|
||||
}
|
||||
GenerateTvHtml(info, sb);
|
||||
newsletter.TvCount = info.Count;
|
||||
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
var html = template.LoadTemplate(sb.ToString());
|
||||
Log.Debug("Loaded the template");
|
||||
|
@ -183,10 +196,12 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
newsletter.Html = escapedHtml;
|
||||
return newsletter;
|
||||
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(IEnumerable<EmbyRecentlyAddedModel> recentlyAddedMovies, StringBuilder sb)
|
||||
|
@ -276,11 +291,12 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
{
|
||||
var seriesItem = t.EmbyInformation.SeriesInformation;
|
||||
var relatedEpisodes = t.EpisodeInformation;
|
||||
|
||||
var endLoop = false;
|
||||
|
||||
try
|
||||
{
|
||||
var info = TvApi.ShowLookupByTheTvDbId(int.Parse(seriesItem.ProviderIds.Tvdb));
|
||||
if(info == null)continue;
|
||||
|
||||
var banner = info.image?.original;
|
||||
if (!string.IsNullOrEmpty(banner))
|
||||
|
@ -299,30 +315,33 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
Header(sb, 3, title);
|
||||
EndTag(sb, "a");
|
||||
|
||||
var results = relatedEpisodes.GroupBy(p => p.ParentIndexNumber,
|
||||
(key, g) => new
|
||||
{
|
||||
ParentIndexNumber = key,
|
||||
IndexNumber = g.ToList()
|
||||
}
|
||||
);
|
||||
// Group the episodes
|
||||
foreach (var embyEpisodeInformation in results.OrderBy(x => x.ParentIndexNumber))
|
||||
if (relatedEpisodes != null)
|
||||
{
|
||||
var epSb = new StringBuilder();
|
||||
for (var i = 0; i < embyEpisodeInformation.IndexNumber.Count; i++)
|
||||
var results = relatedEpisodes.GroupBy(p => p.ParentIndexNumber,
|
||||
(key, g) => new
|
||||
{
|
||||
ParentIndexNumber = key,
|
||||
IndexNumber = g.ToList()
|
||||
}
|
||||
);
|
||||
// Group the episodes
|
||||
foreach (var embyEpisodeInformation in results.OrderBy(x => x.ParentIndexNumber))
|
||||
{
|
||||
var ep = embyEpisodeInformation.IndexNumber[i];
|
||||
if (i < embyEpisodeInformation.IndexNumber.Count)
|
||||
var epSb = new StringBuilder();
|
||||
for (var i = 0; i < embyEpisodeInformation.IndexNumber.Count; i++)
|
||||
{
|
||||
epSb.Append($"{ep.IndexNumber},");
|
||||
}
|
||||
else
|
||||
{
|
||||
epSb.Append(ep);
|
||||
var ep = embyEpisodeInformation.IndexNumber[i];
|
||||
if (i < embyEpisodeInformation.IndexNumber.Count)
|
||||
{
|
||||
epSb.Append($"{ep.IndexNumber},");
|
||||
}
|
||||
else
|
||||
{
|
||||
epSb.Append(ep);
|
||||
}
|
||||
}
|
||||
AddParagraph(sb, $"Season: {embyEpisodeInformation.ParentIndexNumber}, Episode: {epSb}");
|
||||
}
|
||||
AddParagraph(sb, $"Season: {embyEpisodeInformation.ParentIndexNumber}, Episode: {epSb}");
|
||||
}
|
||||
|
||||
if (info.genres.Any())
|
||||
|
@ -331,6 +350,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
|
||||
AddParagraph(sb, string.IsNullOrEmpty(seriesItem.Overview) ? info.summary : seriesItem.Overview);
|
||||
endLoop = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -338,7 +358,8 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
if(endLoop)
|
||||
EndLoopHtml(sb);
|
||||
}
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
|
|
|
@ -32,7 +32,9 @@
|
|||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin <div id="testEmailSpinner"></div></button>
|
||||
|
||||
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin @Html.ToolTip("Note: nothing will send if there is no new content...")
|
||||
<div id="testEmailSpinner"></div></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -84,6 +86,8 @@
|
|||
|
||||
$('#recentlyAddedBtn').click(function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
generateNotify("This could take some time depending on if you have episode searching enabled and also how many new items have been added!", "info");
|
||||
var base = '@Html.GetBaseUrl()';
|
||||
var url = createBaseUrl(base, '/admin/testnewsletteradminemail');
|
||||
$('#testEmailSpinner').attr("class", "fa fa-spinner fa-spin");
|
||||
|
@ -94,11 +98,11 @@
|
|||
success: function (response) {
|
||||
if (response) {
|
||||
generateNotify(response.message, "success");
|
||||
$('#testSendMassEmailSpinner').attr("class", "fa fa-check");
|
||||
$('#testEmailSpinner').attr("class", "fa fa-check");
|
||||
} else {
|
||||
|
||||
generateNotify(response.message, "danger");
|
||||
$('#testSendMassEmailSpinner').attr("class", "fa fa-times");
|
||||
$('#testEmailSpinner').attr("class", "fa fa-times");
|
||||
}
|
||||
},
|
||||
error: function (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue