Merge pull request #2308 from tidusjar/develop

Develop
pull/2357/head v3.0.3383
Jamie 7 years ago committed by GitHub
commit a913f7b7cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,16 @@
# Changelog # Changelog
## v3.0.3368 (2018-06-03)
### **Fixes**
- Run the availability checker on finish of the recentlty added sync. [Jamie]
- Fixed the issue with the Recently Added Sync sometimes not working as expected. [Jamie]
- The UI looks at the local time to see if the JWT token has expired. Use local time to generate the token. [Jamie Rees]
## v3.0.3368 (2018-06-03) ## v3.0.3368 (2018-06-03)
### **New Features** ### **New Features**
@ -8,6 +19,8 @@
- Added the subscribe button to the search page if we have an existing request. [Jamie Rees] - Added the subscribe button to the search page if we have an existing request. [Jamie Rees]
- Update CHANGELOG.md. [Jamie]
### **Fixes** ### **Fixes**
- Use selected episodes in submitRequest. [Calvin] - Use selected episodes in submitRequest. [Calvin]

@ -178,6 +178,7 @@ namespace Ombi.Core.Engine
.Include(x => x.ChildRequests) .Include(x => x.ChildRequests)
.ThenInclude(x => x.SeasonRequests) .ThenInclude(x => x.SeasonRequests)
.ThenInclude(x => x.Episodes) .ThenInclude(x => x.Episodes)
.Where(x => x.ChildRequests.Any())
.OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate)) .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
.Skip(position).Take(count).ToListAsync(); .Skip(position).Take(count).ToListAsync();
@ -189,6 +190,7 @@ namespace Ombi.Core.Engine
.Include(x => x.ChildRequests) .Include(x => x.ChildRequests)
.ThenInclude(x => x.SeasonRequests) .ThenInclude(x => x.SeasonRequests)
.ThenInclude(x => x.Episodes) .ThenInclude(x => x.Episodes)
.Where(x => x.ChildRequests.Any())
.OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate)) .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
.Skip(position).Take(count).ToListAsync(); .Skip(position).Take(count).ToListAsync();
} }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Hangfire;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models; using Ombi.Api.TheMovieDb.Models;
@ -9,6 +10,8 @@ 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;
using Ombi.Schedule.Jobs.Emby;
using Ombi.Schedule.Jobs.Plex;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using Ombi.Store.Repository; using Ombi.Store.Repository;
@ -18,7 +21,7 @@ namespace Ombi.Schedule.Jobs.Ombi
{ {
public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo, public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo,
ILogger<RefreshMetadata> log, ITvMazeApi tvApi, ISettingsService<PlexSettings> plexSettings, ILogger<RefreshMetadata> log, ITvMazeApi tvApi, ISettingsService<PlexSettings> plexSettings,
IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings) IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings, IPlexAvailabilityChecker plexAvailability, IEmbyAvaliabilityChecker embyAvaliability)
{ {
_plexRepo = plexRepo; _plexRepo = plexRepo;
_embyRepo = embyRepo; _embyRepo = embyRepo;
@ -27,10 +30,14 @@ namespace Ombi.Schedule.Jobs.Ombi
_tvApi = tvApi; _tvApi = tvApi;
_plexSettings = plexSettings; _plexSettings = plexSettings;
_embySettings = embySettings; _embySettings = embySettings;
_plexAvailabilityChecker = plexAvailability;
_embyAvaliabilityChecker = embyAvaliability;
} }
private readonly IPlexContentRepository _plexRepo; private readonly IPlexContentRepository _plexRepo;
private readonly IEmbyContentRepository _embyRepo; private readonly IEmbyContentRepository _embyRepo;
private readonly IPlexAvailabilityChecker _plexAvailabilityChecker;
private readonly IEmbyAvaliabilityChecker _embyAvaliabilityChecker;
private readonly ILogger _log; private readonly ILogger _log;
private readonly IMovieDbApi _movieApi; private readonly IMovieDbApi _movieApi;
private readonly ITvMazeApi _tvApi; private readonly ITvMazeApi _tvApi;
@ -64,10 +71,11 @@ namespace Ombi.Schedule.Jobs.Ombi
public async Task ProcessPlexServerContent(IEnumerable<int> contentIds) public async Task ProcessPlexServerContent(IEnumerable<int> contentIds)
{ {
_log.LogInformation("Starting the Metadata refresh from RecentlyAddedSync"); _log.LogInformation("Starting the Metadata refresh from RecentlyAddedSync");
var plexSettings = await _plexSettings.GetSettingsAsync();
var embySettings = await _embySettings.GetSettingsAsync();
try try
{ {
var settings = await _plexSettings.GetSettingsAsync(); if (plexSettings.Enable)
if (settings.Enable)
{ {
await StartPlexWithKnownContent(contentIds); await StartPlexWithKnownContent(contentIds);
} }
@ -77,6 +85,19 @@ namespace Ombi.Schedule.Jobs.Ombi
_log.LogError(e, "Exception when refreshing the Plex Metadata"); _log.LogError(e, "Exception when refreshing the Plex Metadata");
throw; throw;
} }
finally
{
if (plexSettings.Enable)
{
BackgroundJob.Enqueue(() => _plexAvailabilityChecker.Start());
}
if (embySettings.Enable)
{
BackgroundJob.Enqueue(() => _embyAvaliabilityChecker.Start());
}
}
} }
private async Task StartPlexWithKnownContent(IEnumerable<int> contentids) private async Task StartPlexWithKnownContent(IEnumerable<int> contentids)

@ -147,7 +147,7 @@ namespace Ombi.Schedule.Jobs.Plex
private async Task<IEnumerable<int>> ProcessServer(PlexServers servers, bool recentlyAddedSearch) private async Task<IEnumerable<int>> ProcessServer(PlexServers servers, bool recentlyAddedSearch)
{ {
var processedContent = new HashSet<int>(); var processedContent = new Dictionary<int,int>();
Logger.LogInformation("Getting all content from server {0}", servers.Name); Logger.LogInformation("Getting all content from server {0}", servers.Name);
var allContent = await GetAllContent(servers, recentlyAddedSearch); var allContent = await GetAllContent(servers, recentlyAddedSearch);
Logger.LogInformation("We found {0} items", allContent.Count); Logger.LogInformation("We found {0} items", allContent.Count);
@ -175,7 +175,7 @@ namespace Ombi.Schedule.Jobs.Plex
continue; continue;
} }
await ProcessTvShow(servers, show, contentToAdd, recentlyAddedSearch, processedContent); await ProcessTvShow(servers, show, contentToAdd, processedContent);
if (contentToAdd.Any()) if (contentToAdd.Any())
{ {
await Repo.AddRange(contentToAdd, false); await Repo.AddRange(contentToAdd, false);
@ -183,7 +183,7 @@ namespace Ombi.Schedule.Jobs.Plex
{ {
foreach (var plexServerContent in contentToAdd) foreach (var plexServerContent in contentToAdd)
{ {
processedContent.Add(plexServerContent.Id); processedContent.Add(plexServerContent.Id, plexServerContent.Key);
} }
} }
contentToAdd.Clear(); contentToAdd.Clear();
@ -208,7 +208,7 @@ namespace Ombi.Schedule.Jobs.Plex
foreach (var show in content.Metadata ?? new Metadata[] { }) foreach (var show in content.Metadata ?? new Metadata[] { })
{ {
count++; count++;
await ProcessTvShow(servers, show, contentToAdd, recentlyAddedSearch, processedContent); await ProcessTvShow(servers, show, contentToAdd, processedContent);
if (contentToAdd.Any()) if (contentToAdd.Any())
{ {
@ -217,7 +217,7 @@ namespace Ombi.Schedule.Jobs.Plex
{ {
foreach (var plexServerContent in contentToAdd) foreach (var plexServerContent in contentToAdd)
{ {
processedContent.Add(plexServerContent.Id); processedContent.Add(plexServerContent.Id, plexServerContent.Key);
} }
} }
contentToAdd.Clear(); contentToAdd.Clear();
@ -299,7 +299,7 @@ namespace Ombi.Schedule.Jobs.Plex
await Repo.AddRange(contentToAdd); await Repo.AddRange(contentToAdd);
foreach (var c in contentToAdd) foreach (var c in contentToAdd)
{ {
processedContent.Add(c.Id); processedContent.Add(c.Id, c.Key);
} }
contentToAdd.Clear(); contentToAdd.Clear();
} }
@ -310,7 +310,7 @@ namespace Ombi.Schedule.Jobs.Plex
await Repo.AddRange(contentToAdd); await Repo.AddRange(contentToAdd);
foreach (var c in contentToAdd) foreach (var c in contentToAdd)
{ {
processedContent.Add(c.Id); processedContent.Add(c.Id, c.Key);
} }
contentToAdd.Clear(); contentToAdd.Clear();
} }
@ -321,14 +321,14 @@ namespace Ombi.Schedule.Jobs.Plex
await Repo.AddRange(contentToAdd); await Repo.AddRange(contentToAdd);
foreach (var c in contentToAdd) foreach (var c in contentToAdd)
{ {
processedContent.Add(c.Id); processedContent.Add(c.Id, c.Key);
} }
} }
return processedContent; return processedContent.Values;
} }
private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet<PlexServerContent> contentToAdd, bool recentlyAdded, HashSet<int> contentProcessed) private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet<PlexServerContent> contentToAdd, Dictionary<int,int> contentProcessed)
{ {
var seasonList = await PlexApi.GetSeasons(servers.PlexAuthToken, servers.FullUri, var seasonList = await PlexApi.GetSeasons(servers.PlexAuthToken, servers.FullUri,
show.ratingKey); show.ratingKey);
@ -349,7 +349,7 @@ namespace Ombi.Schedule.Jobs.Plex
var existingContent = await Repo.GetFirstContentByCustom(x => x.Title == show.title var existingContent = await Repo.GetFirstContentByCustom(x => x.Title == show.title
&& x.ReleaseYear == show.year.ToString() && x.ReleaseYear == show.year.ToString()
&& x.Type == PlexMediaTypeEntity.Show); && x.Type == PlexMediaTypeEntity.Show);
// Just double check the rating key, since this is our unique constraint // Just double check the rating key, since this is our unique constraint
var existingKey = await Repo.GetByKey(show.ratingKey); var existingKey = await Repo.GetByKey(show.ratingKey);
@ -397,6 +397,13 @@ namespace Ombi.Schedule.Jobs.Plex
} }
} }
// Also make sure it's not already being processed...
var alreadyProcessed = contentProcessed.Select(x => x.Value).Any(x => x == show.ratingKey);
if (alreadyProcessed)
{
return;
}
// The ratingKey keeps changing... // The ratingKey keeps changing...
//var existingContent = await Repo.GetByKey(show.ratingKey); //var existingContent = await Repo.GetByKey(show.ratingKey);
if (existingContent != null) if (existingContent != null)

@ -126,7 +126,7 @@ namespace Ombi.Controllers
var token = new JwtSecurityToken( var token = new JwtSecurityToken(
claims: claims, claims: claims,
expires: rememberMe ? DateTime.UtcNow.AddDays(7) : DateTime.UtcNow.AddHours(5), expires: rememberMe ? DateTime.Now.AddDays(7) : DateTime.Now.AddDays(1),
signingCredentials: creds, signingCredentials: creds,
audience: "Ombi", issuer: "Ombi" audience: "Ombi", issuer: "Ombi"
); );

Loading…
Cancel
Save