diff --git a/src/Ombi.Api.Emby/EmbyApi.cs b/src/Ombi.Api.Emby/EmbyApi.cs index c413ecded..d911ca212 100644 --- a/src/Ombi.Api.Emby/EmbyApi.cs +++ b/src/Ombi.Api.Emby/EmbyApi.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Internal; using Newtonsoft.Json; using Ombi.Api.Emby.Models; -using Ombi.Api.Emby.Models.Media; using Ombi.Api.Emby.Models.Media.Tv; using Ombi.Api.Emby.Models.Movie; using Ombi.Helpers; @@ -124,22 +120,36 @@ namespace Ombi.Api.Emby return response; } - public async Task> GetAllMovies(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri) { return await GetAll("Movie", apiKey, userId, baseUri, true, startIndex, count, parentIdFilder); } + public async Task> RecentlyAddedMovies(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri) + { + return await RecentlyAdded("Movie", apiKey, userId, baseUri, true, startIndex, count, parentIdFilder); + } + public async Task> GetAllEpisodes(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri) { return await GetAll("Episode", apiKey, userId, baseUri, false, startIndex, count, parentIdFilder); } + public async Task> RecentlyAddedEpisodes(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri) + { + return await RecentlyAdded("Episode", apiKey, userId, baseUri, false, startIndex, count, parentIdFilder); + } + public async Task> GetAllShows(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri) { return await GetAll("Series", apiKey, userId, baseUri, false, startIndex, count, parentIdFilder); } + public async Task> RecentlyAddedShows(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri) + { + return await RecentlyAdded("Series", apiKey, userId, baseUri, false, startIndex, count, parentIdFilder); + } + public async Task GetSeriesInformation(string mediaId, string apiKey, string userId, string baseUrl) { return await GetInformation(mediaId, apiKey, userId, baseUrl); @@ -154,6 +164,31 @@ namespace Ombi.Api.Emby return await GetInformation(mediaId, apiKey, userId, baseUrl); } + private async Task> RecentlyAdded(string type, string apiKey, string userId, string baseUri, bool includeOverview, int startIndex, int count, string parentIdFilder = default) + { + var request = new Request($"emby/users/{userId}/items", baseUri, HttpMethod.Get); + + request.AddQueryString("Recursive", true.ToString()); + request.AddQueryString("IncludeItemTypes", type); + request.AddQueryString("Fields", includeOverview ? "ProviderIds,Overview" : "ProviderIds"); + request.AddQueryString("startIndex", startIndex.ToString()); + request.AddQueryString("limit", count.ToString()); + request.AddQueryString("sortBy", "DateCreated"); + request.AddQueryString("SortOrder", "Descending"); + if (!string.IsNullOrEmpty(parentIdFilder)) + { + request.AddQueryString("ParentId", parentIdFilder); + } + + request.AddQueryString("IsVirtualItem", "False"); + + AddHeaders(request, apiKey); + + + var obj = await Api.Request>(request); + return obj; + } + private async Task GetInformation(string mediaId, string apiKey, string userId, string baseUrl) { var request = new Request($"emby/users/{userId}/items/{mediaId}", baseUrl, HttpMethod.Get); diff --git a/src/Ombi.Api.Emby/IBaseEmbyApi.cs b/src/Ombi.Api.Emby/IBaseEmbyApi.cs index 4de81073d..248c0a88f 100644 --- a/src/Ombi.Api.Emby/IBaseEmbyApi.cs +++ b/src/Ombi.Api.Emby/IBaseEmbyApi.cs @@ -29,5 +29,8 @@ namespace Ombi.Api.Emby Task GetMovieInformation(string mediaId, string apiKey, string userId, string baseUrl); Task GetEpisodeInformation(string mediaId, string apiKey, string userId, string baseUrl); Task GetPublicInformation(string baseUrl); + Task> RecentlyAddedMovies(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri); + Task> RecentlyAddedEpisodes(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri); + Task> RecentlyAddedShows(string apiKey, string parentIdFilder, int startIndex, int count, string userId, string baseUri); } } \ No newline at end of file diff --git a/src/Ombi.Helpers/JobDataKeys.cs b/src/Ombi.Helpers/JobDataKeys.cs index e0e2f7451..277834431 100644 --- a/src/Ombi.Helpers/JobDataKeys.cs +++ b/src/Ombi.Helpers/JobDataKeys.cs @@ -3,6 +3,7 @@ public class JobDataKeys { public const string RecentlyAddedSearch = "recentlyAddedSearch"; + public const string EmbyRecentlyAddedSearch = nameof(EmbyRecentlyAddedSearch); public const string NotificationOptions = nameof(NotificationOptions); } } \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 0630c0b28..e605f21e2 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -5,6 +5,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; +using Ombi.Api.Emby.Models; +using Ombi.Api.Emby.Models.Media.Tv; using Ombi.Api.Emby.Models.Movie; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; @@ -36,24 +38,33 @@ namespace Ombi.Schedule.Jobs.Emby private readonly IEmbyContentRepository _repo; private readonly IHubContext _notification; + private const int AmountToTake = 100; + private IEmbyApi Api { get; set; } - public async Task Execute(IJobExecutionContext job) + public async Task Execute(IJobExecutionContext context) { + JobDataMap dataMap = context.JobDetail.JobDataMap; + var recentlyAddedSearch = false; + if (dataMap.TryGetValue(JobDataKeys.EmbyRecentlyAddedSearch, out var recentlyAddedObj)) + { + recentlyAddedSearch = Convert.ToBoolean(recentlyAddedObj); + } + var embySettings = await _settings.GetSettingsAsync(); if (!embySettings.Enable) return; - + Api = _apiFactory.CreateClient(embySettings); await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) - .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Started"); + .SendAsync(NotificationHub.NotificationEvent, recentlyAddedSearch ? "Emby Recently Added Started" : "Emby Content Sync Started"); foreach (var server in embySettings.Servers) { try { - await StartServerCache(server, embySettings); + await StartServerCache(server, recentlyAddedSearch); } catch (Exception e) { @@ -67,11 +78,12 @@ namespace Ombi.Schedule.Jobs.Emby .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Finished"); // Episodes - await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync), "Emby"); + + await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IEmbyEpisodeSync), "Emby"), new JobDataMap(new Dictionary { { JobDataKeys.EmbyRecentlyAddedSearch, "true" } })); } - private async Task StartServerCache(EmbyServers server, EmbySettings settings) + private async Task StartServerCache(EmbyServers server, bool recentlyAdded) { if (!ValidateSettings(server)) return; @@ -86,14 +98,14 @@ namespace Ombi.Schedule.Jobs.Emby foreach (var movieParentIdFilder in movieLibsToFilter) { _logger.LogInformation($"Scanning Lib '{movieParentIdFilder.Title}'"); - await ProcessMovies(server, movieParentIdFilder.Key); + await ProcessMovies(server, recentlyAdded, movieParentIdFilder.Key); } var tvLibsToFilter = server.EmbySelectedLibraries.Where(x => x.Enabled && x.CollectionType == "tvshows"); foreach (var tvParentIdFilter in tvLibsToFilter) { _logger.LogInformation($"Scanning Lib '{tvParentIdFilter.Title}'"); - await ProcessTv(server, tvParentIdFilter.Key); + await ProcessTv(server, recentlyAdded, tvParentIdFilter.Key); } @@ -101,68 +113,74 @@ namespace Ombi.Schedule.Jobs.Emby foreach (var m in mixedLibs) { _logger.LogInformation($"Scanning Lib '{m.Title}'"); - await ProcessTv(server, m.Key); - await ProcessMovies(server, m.Key); + await ProcessTv(server, recentlyAdded, m.Key); + await ProcessMovies(server, recentlyAdded, m.Key); } } else { - await ProcessMovies(server); - await ProcessTv(server); + await ProcessMovies(server, recentlyAdded); + await ProcessTv(server, recentlyAdded); } } - private async Task ProcessTv(EmbyServers server, string parentId = default) + private async Task ProcessTv(EmbyServers server, bool recentlyAdded, string parentId = default) { // TV Time var mediaToAdd = new HashSet(); - var tv = await Api.GetAllShows(server.ApiKey, parentId, 0, 200, server.AdministratorId, server.FullUri); + EmbyItemContainer tv; + if (recentlyAdded) + { + var recentlyAddedAmountToTake = AmountToTake / 2; + tv = await Api.RecentlyAddedShows(server.ApiKey, parentId, 0, recentlyAddedAmountToTake, server.AdministratorId, server.FullUri); + if (tv.TotalRecordCount > recentlyAddedAmountToTake) + { + tv.TotalRecordCount = recentlyAddedAmountToTake; + } + } + else + { + tv = await Api.GetAllShows(server.ApiKey, parentId, 0, AmountToTake, server.AdministratorId, server.FullUri); + } var totalTv = tv.TotalRecordCount; var processed = 1; while (processed < totalTv) { foreach (var tvShow in tv.Items) { - try + processed++; + if (string.IsNullOrEmpty(tvShow.ProviderIds?.Tvdb)) { + _logger.LogInformation("Provider Id on tv {0} is null", tvShow.Name); + continue; + } - processed++; - if (string.IsNullOrEmpty(tvShow.ProviderIds?.Tvdb)) - { - _logger.LogInformation("Provider Id on tv {0} is null", tvShow.Name); - continue; - } - - var existingTv = await _repo.GetByEmbyId(tvShow.Id); - if (existingTv == null) - { - _logger.LogDebug("Adding new TV Show {0}", tvShow.Name); - mediaToAdd.Add(new EmbyContent - { - TvDbId = tvShow.ProviderIds?.Tvdb, - ImdbId = tvShow.ProviderIds?.Imdb, - TheMovieDbId = tvShow.ProviderIds?.Tmdb, - Title = tvShow.Name, - Type = EmbyMediaType.Series, - EmbyId = tvShow.Id, - Url = EmbyHelper.GetEmbyMediaUrl(tvShow.Id, server?.ServerId, server.ServerHostname), - AddedAt = DateTime.UtcNow - }); - } - else + var existingTv = await _repo.GetByEmbyId(tvShow.Id); + if (existingTv == null) + { + _logger.LogDebug("Adding new TV Show {0}", tvShow.Name); + mediaToAdd.Add(new EmbyContent { - _logger.LogDebug("We already have TV Show {0}", tvShow.Name); - } - + TvDbId = tvShow.ProviderIds?.Tvdb, + ImdbId = tvShow.ProviderIds?.Imdb, + TheMovieDbId = tvShow.ProviderIds?.Tmdb, + Title = tvShow.Name, + Type = EmbyMediaType.Series, + EmbyId = tvShow.Id, + Url = EmbyHelper.GetEmbyMediaUrl(tvShow.Id, server?.ServerId, server.ServerHostname), + AddedAt = DateTime.UtcNow + }); } - catch (Exception) + else { - - throw; + _logger.LogDebug("We already have TV Show {0}", tvShow.Name); } } // Get the next batch - tv = await Api.GetAllShows(server.ApiKey, parentId, processed, 200, server.AdministratorId, server.FullUri); + if (!recentlyAdded) + { + tv = await Api.GetAllShows(server.ApiKey, parentId, processed, AmountToTake, server.AdministratorId, server.FullUri); + } await _repo.AddRange(mediaToAdd); mediaToAdd.Clear(); } @@ -171,9 +189,23 @@ namespace Ombi.Schedule.Jobs.Emby await _repo.AddRange(mediaToAdd); } - private async Task ProcessMovies(EmbyServers server, string parentId = default) + private async Task ProcessMovies(EmbyServers server, bool recentlyAdded, string parentId = default) { - var movies = await Api.GetAllMovies(server.ApiKey, parentId, 0, 200, server.AdministratorId, server.FullUri); + EmbyItemContainer movies; + if (recentlyAdded) + { + var recentlyAddedAmountToTake = AmountToTake / 2; + movies = await Api.RecentlyAddedMovies(server.ApiKey, parentId, 0, recentlyAddedAmountToTake, server.AdministratorId, server.FullUri); + // Setting this so we don't attempt to grab more than we need + if (movies.TotalRecordCount > recentlyAddedAmountToTake) + { + movies.TotalRecordCount = recentlyAddedAmountToTake; + } + } + else + { + movies = await Api.GetAllMovies(server.ApiKey, parentId, 0, AmountToTake, server.AdministratorId, server.FullUri); + } var totalCount = movies.TotalRecordCount; var processed = 1; var mediaToAdd = new HashSet(); @@ -189,22 +221,25 @@ namespace Ombi.Schedule.Jobs.Emby { await ProcessMovies(item, mediaToAdd, server); } - - processed++; } else { - processed++; // Regular movie await ProcessMovies(movie, mediaToAdd, server); } + + processed++; } // Get the next batch - movies = await Api.GetAllMovies(server.ApiKey, parentId, processed, 200, server.AdministratorId, server.FullUri); + // Recently Added should never be checked as the TotalRecords should equal the amount to take + if (!recentlyAdded) + { + movies = await Api.GetAllMovies(server.ApiKey, parentId, processed, AmountToTake, server.AdministratorId, server.FullUri); + } + else await _repo.AddRange(mediaToAdd); mediaToAdd.Clear(); - } } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index 1a55da6c9..5b2bbd892 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -40,6 +40,8 @@ using Ombi.Store.Entities; using Ombi.Store.Repository; using Quartz; using Ombi.Schedule.Jobs.Ombi; +using Ombi.Api.Emby.Models; +using Ombi.Api.Emby.Models.Media.Tv; namespace Ombi.Schedule.Jobs.Emby { @@ -61,13 +63,22 @@ namespace Ombi.Schedule.Jobs.Emby private readonly IEmbyContentRepository _repo; private readonly IHubContext _notification; + private const int AmountToTake = 100; + private IEmbyApi Api { get; set; } - public async Task Execute(IJobExecutionContext job) + public async Task Execute(IJobExecutionContext context) { + JobDataMap dataMap = context.MergedJobDataMap; + var recentlyAddedSearch = false; + if (dataMap.TryGetValue(JobDataKeys.EmbyRecentlyAddedSearch, out var recentlyAddedObj)) + { + recentlyAddedSearch = Convert.ToBoolean(recentlyAddedObj); + } + var settings = await _settings.GetSettingsAsync(); - + Api = _apiFactory.CreateClient(settings); await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Started"); @@ -79,12 +90,12 @@ namespace Ombi.Schedule.Jobs.Emby foreach (var tvParentIdFilter in tvLibsToFilter) { _logger.LogInformation($"Scanning Lib for episodes '{tvParentIdFilter.Title}'"); - await CacheEpisodes(server, tvParentIdFilter.Key); + await CacheEpisodes(server, recentlyAddedSearch, tvParentIdFilter.Key); } } else { - await CacheEpisodes(server, string.Empty); + await CacheEpisodes(server, recentlyAddedSearch, string.Empty); } } @@ -94,9 +105,22 @@ namespace Ombi.Schedule.Jobs.Emby await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); } - private async Task CacheEpisodes(EmbyServers server, string parentIdFilter) + private async Task CacheEpisodes(EmbyServers server, bool recentlyAdded, string parentIdFilter) { - var allEpisodes = await Api.GetAllEpisodes(server.ApiKey, parentIdFilter, 0, 200, server.AdministratorId, server.FullUri); + EmbyItemContainer allEpisodes; + if (recentlyAdded) + { + var recentlyAddedAmountToTake = AmountToTake; + allEpisodes = await Api.RecentlyAddedEpisodes(server.ApiKey, parentIdFilter, 0, recentlyAddedAmountToTake, server.AdministratorId, server.FullUri); + if (allEpisodes.TotalRecordCount > recentlyAddedAmountToTake) + { + allEpisodes.TotalRecordCount = recentlyAddedAmountToTake; + } + } + else + { + allEpisodes = await Api.GetAllEpisodes(server.ApiKey, parentIdFilter, 0, AmountToTake, server.AdministratorId, server.FullUri); + } var total = allEpisodes.TotalRecordCount; var processed = 1; var epToAdd = new HashSet(); @@ -163,7 +187,10 @@ namespace Ombi.Schedule.Jobs.Emby await _repo.AddRange(epToAdd); epToAdd.Clear(); - allEpisodes = await Api.GetAllEpisodes(server.ApiKey, parentIdFilter, processed, 200, server.AdministratorId, server.FullUri); + if (!recentlyAdded) + { + allEpisodes = await Api.GetAllEpisodes(server.ApiKey, parentIdFilter, processed, AmountToTake, server.AdministratorId, server.FullUri); + } } if (epToAdd.Any()) diff --git a/src/Ombi.Schedule/OmbiScheduler.cs b/src/Ombi.Schedule/OmbiScheduler.cs index 6c54895d6..8e45be57c 100644 --- a/src/Ombi.Schedule/OmbiScheduler.cs +++ b/src/Ombi.Schedule/OmbiScheduler.cs @@ -96,6 +96,7 @@ namespace Ombi.Schedule private static async Task AddEmby(JobSettings s) { await OmbiQuartz.Instance.AddJob(nameof(IEmbyContentSync), "Emby", JobSettingsHelper.EmbyContent(s)); + await OmbiQuartz.Instance.AddJob(nameof(IEmbyContentSync) + "RecentlyAdded", "Emby", JobSettingsHelper.EmbyRecentlyAddedSync(s), new Dictionary { { JobDataKeys.EmbyRecentlyAddedSearch, "true" } }); await OmbiQuartz.Instance.AddJob(nameof(IEmbyEpisodeSync), "Emby", null); await OmbiQuartz.Instance.AddJob(nameof(IEmbyAvaliabilityChecker), "Emby", null); await OmbiQuartz.Instance.AddJob(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s)); diff --git a/src/Ombi.Settings/Settings/Models/JobSettings.cs b/src/Ombi.Settings/Settings/Models/JobSettings.cs index 18bde6774..ac7ab3bdc 100644 --- a/src/Ombi.Settings/Settings/Models/JobSettings.cs +++ b/src/Ombi.Settings/Settings/Models/JobSettings.cs @@ -3,6 +3,7 @@ public class JobSettings : Settings { public string EmbyContentSync { get; set; } + public string EmbyRecentlyAddedSync { get; set; } public string JellyfinContentSync { get; set; } public string SonarrSync { get; set; } public string RadarrSync { get; set; } diff --git a/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs b/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs index fef0792d3..e580e1977 100644 --- a/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs +++ b/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs @@ -1,5 +1,4 @@ -using System; -using Ombi.Helpers; +using Ombi.Helpers; using Quartz; namespace Ombi.Settings.Settings.Models @@ -18,7 +17,12 @@ namespace Ombi.Settings.Settings.Models public static string EmbyContent(JobSettings s) { - return ValidateCron(Get(s.EmbyContentSync, Cron.Hourly(5))); + return ValidateCron(Get(s.EmbyContentSync, Cron.Daily(2))); + } + + public static string EmbyRecentlyAddedSync(JobSettings s) + { + return ValidateCron(Get(s.EmbyRecentlyAddedSync, Cron.Hourly(30))); } public static string JellyfinContent(JobSettings s) diff --git a/src/Ombi/.vscode/settings.json b/src/Ombi/.vscode/settings.json index 0fc7fae1e..5862f9a19 100644 --- a/src/Ombi/.vscode/settings.json +++ b/src/Ombi/.vscode/settings.json @@ -18,6 +18,7 @@ "user-management", "newsletter", "mass-email", - "issues" + "issues", + "emby" ] } diff --git a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts index 919e6a271..c5dcaffc6 100644 --- a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts @@ -212,6 +212,7 @@ export interface IJobSettings { retryRequests: string; mediaDatabaseRefresh: string; autoDeleteRequests: string; + embyRecentlyAddedSync: string; } export interface IIssueSettings extends ISettings { diff --git a/src/Ombi/ClientApp/src/app/services/job.service.ts b/src/Ombi/ClientApp/src/app/services/job.service.ts index 24b5e9a52..8bd08c4f5 100644 --- a/src/Ombi/ClientApp/src/app/services/job.service.ts +++ b/src/Ombi/ClientApp/src/app/services/job.service.ts @@ -43,6 +43,10 @@ export class JobService extends ServiceHelpers { return this.http.post(`${this.url}plexrecentlyadded/`, {headers: this.headers}); } + public runEmbyRecentlyAddedCacher(): Observable { + return this.http.post(`${this.url}embyrecentlyadded/`, {headers: this.headers}); + } + public clearMediaserverData(): Observable { return this.http.post(`${this.url}clearmediaserverdata/`, {headers: this.headers}); } diff --git a/src/Ombi/ClientApp/src/app/settings/emby/emby.component.html b/src/Ombi/ClientApp/src/app/settings/emby/emby.component.html index 14aaada64..6787fb4c9 100644 --- a/src/Ombi/ClientApp/src/app/settings/emby/emby.component.html +++ b/src/Ombi/ClientApp/src/app/settings/emby/emby.component.html @@ -105,12 +105,29 @@ +
+
+ +
+
+
+ +
+
+ +
+
@@ -118,19 +135,8 @@
-
-
-
- -
-
-
- -
-
+ +
diff --git a/src/Ombi/ClientApp/src/app/settings/emby/emby.component.ts b/src/Ombi/ClientApp/src/app/settings/emby/emby.component.ts index b50175f61..69e31741d 100644 --- a/src/Ombi/ClientApp/src/app/settings/emby/emby.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/emby/emby.component.ts @@ -93,6 +93,14 @@ export class EmbyComponent implements OnInit { }); } + public runRecentlyAddedCacher(): void { + this.jobService.runEmbyRecentlyAddedCacher().subscribe(x => { + if (x) { + this.notificationService.success("Triggered the Emby Recently Added Sync"); + } + }); + } + public clearDataAndResync(): void { this.jobService.clearMediaserverData().subscribe(x => { if (x) { diff --git a/src/Ombi/ClientApp/src/app/settings/jobs/jobs.component.ts b/src/Ombi/ClientApp/src/app/settings/jobs/jobs.component.ts index 83508e752..1e00d4e29 100644 --- a/src/Ombi/ClientApp/src/app/settings/jobs/jobs.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/jobs/jobs.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit } from "@angular/core"; - import { FormBuilder, FormGroup, Validators } from "@angular/forms"; -import { NotificationService, SettingsService, JobService } from "../../services"; +import { JobService, NotificationService, SettingsService } from "../../services"; @Component({ templateUrl: "./jobs.component.html", @@ -36,7 +35,8 @@ export class JobsComponent implements OnInit { issuesPurge: [x.issuesPurge, Validators.required], retryRequests: [x.retryRequests, Validators.required], mediaDatabaseRefresh: [x.mediaDatabaseRefresh, Validators.required], - autoDeleteRequests: [x.autoDeleteRequests, Validators.required] + autoDeleteRequests: [x.autoDeleteRequests, Validators.required], + EmbyRecentlyAddedSync: [x.embyRecentlyAddedSync, Validators.required], }); }); } diff --git a/src/Ombi/Controllers/V1/JobController.cs b/src/Ombi/Controllers/V1/JobController.cs index 2dd694619..442866762 100644 --- a/src/Ombi/Controllers/V1/JobController.cs +++ b/src/Ombi/Controllers/V1/JobController.cs @@ -118,9 +118,9 @@ namespace Ombi.Controllers.V1 /// /// [HttpPost("plexcontentcacher")] - public bool StartPlexContentCacher() + public async Task StartPlexContentCacher() { - OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync), "Plex"), new JobDataMap(new Dictionary { { "recentlyAddedSearch", "false" } })); + await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync), "Plex"), new JobDataMap(new Dictionary { { "recentlyAddedSearch", "false" } })); return true; } @@ -129,9 +129,9 @@ namespace Ombi.Controllers.V1 /// /// [HttpPost("clearmediaserverdata")] - public bool ClearMediaServerData() + public async Task ClearMediaServerData() { - OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IMediaDatabaseRefresh), "System")); + await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IMediaDatabaseRefresh), "System")); return true; } @@ -140,9 +140,9 @@ namespace Ombi.Controllers.V1 /// /// [HttpPost("plexrecentlyadded")] - public bool StartRecentlyAdded() + public async Task StartRecentlyAdded() { - OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync) + "RecentlyAdded", "Plex"), new JobDataMap(new Dictionary { { "recentlyAddedSearch", "true" } })); + await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync) + "RecentlyAdded", "Plex"), new JobDataMap(new Dictionary { { "recentlyAddedSearch", "true" } })); return true; } @@ -153,7 +153,18 @@ namespace Ombi.Controllers.V1 [HttpPost("embycontentcacher")] public async Task StartEmbyContentCacher() { - await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync), "Emby"); + await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IEmbyContentSync), "Emby"), new JobDataMap(new Dictionary { { JobDataKeys.EmbyRecentlyAddedSearch, "false" } })); + return true; + } + + /// + /// Runs a smaller version of the content cacher + /// + /// + [HttpPost("embyrecentlyadded")] + public async Task StartEmbyRecentlyAdded() + { + await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IEmbyContentSync) + "RecentlyAdded", "Emby"), new JobDataMap(new Dictionary { { JobDataKeys.EmbyRecentlyAddedSearch, "true" } })); return true; } diff --git a/src/Ombi/Controllers/V1/SettingsController.cs b/src/Ombi/Controllers/V1/SettingsController.cs index 9e7343472..abf1e86b7 100644 --- a/src/Ombi/Controllers/V1/SettingsController.cs +++ b/src/Ombi/Controllers/V1/SettingsController.cs @@ -618,6 +618,7 @@ namespace Ombi.Controllers.V1 j.RetryRequests = j.RetryRequests.HasValue() ? j.RetryRequests : JobSettingsHelper.ResendFailedRequests(j); j.MediaDatabaseRefresh = j.MediaDatabaseRefresh.HasValue() ? j.MediaDatabaseRefresh : JobSettingsHelper.MediaDatabaseRefresh(j); j.AutoDeleteRequests = j.AutoDeleteRequests.HasValue() ? j.AutoDeleteRequests : JobSettingsHelper.AutoDeleteRequests(j); + j.EmbyRecentlyAddedSync = j.EmbyRecentlyAddedSync.HasValue() ? j.EmbyRecentlyAddedSync : JobSettingsHelper.EmbyRecentlyAddedSync(j); return j; }