Added a new Job. Plex Recently Added, this is a slimmed down version of the Plex Sync job, this will just scan the recently added list and not the whole library. I'd reccomend running this very regulary and the full scan not as regular.

pull/2161/head
Jamie 6 years ago
parent 41d5ef5f41
commit eeaf614a29

File diff suppressed because it is too large Load Diff

@ -19,5 +19,6 @@ namespace Ombi.Api.Plex
Task<PlexContainer> GetAllEpisodes(string authToken, string host, string section, int start, int retCount);
Task<PlexFriends> GetUsers(string authToken);
Task<PlexAccount> GetAccount(string authToken);
Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId);
}
}

@ -23,8 +23,8 @@ namespace Ombi.Api.Plex.Models
public int leafCount { get; set; }
public int viewedLeafCount { get; set; }
public int childCount { get; set; }
public long addedAt { get; set; }
public int updatedAt { get; set; }
//public long addedAt { get; set; }
//public int updatedAt { get; set; }
public Genre[] Genre { get; set; }
//public Role[] Role { get; set; }
public string primaryExtraKey { get; set; }

@ -147,6 +147,15 @@ namespace Ombi.Api.Plex
return await Api.Request<PlexFriends>(request);
}
public async Task<PlexMetadata> GetRecentlyAdded(string authToken, string uri, string sectionId)
{
var request = new Request($"library/sections/{sectionId}/recentlyAdded", uri, HttpMethod.Get);
AddHeaders(request, authToken);
AddLimitHeaders(request, 0, 50);
return await Api.Request<PlexMetadata>(request);
}
/// <summary>
/// Adds the required headers and also the authorization header
/// </summary>

@ -175,6 +175,7 @@ namespace Ombi.DependencyInjection
services.AddTransient<ISickRageSync, SickRageSync>();
services.AddTransient<IRefreshMetadata, RefreshMetadata>();
services.AddTransient<INewsletterJob, NewsletterJob>();
services.AddTransient<IPlexRecentlyAddedSync, PlexRecentlyAddedSync>();
}
}
}

@ -19,7 +19,7 @@ namespace Ombi.Schedule
IOmbiAutomaticUpdater updater, IEmbyContentSync embySync, IPlexUserImporter userImporter,
IEmbyUserImporter embyUserImporter, ISonarrSync cache, ICouchPotatoSync cpCache,
ISettingsService<JobSettings> jobsettings, ISickRageSync srSync, IRefreshMetadata refresh,
INewsletterJob newsletter)
INewsletterJob newsletter, IPlexRecentlyAddedSync recentlyAddedSync)
{
_plexContentSync = plexContentSync;
_radarrSync = radarrSync;
@ -33,6 +33,7 @@ namespace Ombi.Schedule
_srSync = srSync;
_refreshMetadata = refresh;
_newsletter = newsletter;
_plexRecentlyAddedSync = recentlyAddedSync;
}
private readonly IPlexContentSync _plexContentSync;
@ -47,6 +48,7 @@ namespace Ombi.Schedule
private readonly ISettingsService<JobSettings> _jobSettings;
private readonly IRefreshMetadata _refreshMetadata;
private readonly INewsletterJob _newsletter;
private readonly IPlexRecentlyAddedSync _plexRecentlyAddedSync;
public void Setup()
{
@ -55,7 +57,8 @@ namespace Ombi.Schedule
RecurringJob.AddOrUpdate(() => _embyContentSync.Start(), JobSettingsHelper.EmbyContent(s));
RecurringJob.AddOrUpdate(() => _sonarrSync.Start(), JobSettingsHelper.Sonarr(s));
RecurringJob.AddOrUpdate(() => _radarrSync.CacheContent(), JobSettingsHelper.Radarr(s));
RecurringJob.AddOrUpdate(() => _plexContentSync.CacheContent(), JobSettingsHelper.PlexContent(s));
RecurringJob.AddOrUpdate(() => _plexContentSync.CacheContent(false), JobSettingsHelper.PlexContent(s));
RecurringJob.AddOrUpdate(() => _plexContentSync.CacheContent(true), JobSettingsHelper.PlexRecentlyAdded(s));
RecurringJob.AddOrUpdate(() => _cpCache.Start(), JobSettingsHelper.CouchPotato(s));
RecurringJob.AddOrUpdate(() => _srSync.Start(), JobSettingsHelper.SickRageSync(s));
RecurringJob.AddOrUpdate(() => _refreshMetadata.Start(), JobSettingsHelper.RefreshMetadata(s));

@ -4,6 +4,6 @@ namespace Ombi.Schedule.Jobs
{
public interface IPlexContentSync : IBaseJob
{
Task CacheContent();
Task CacheContent(bool recentlyAddedSearch = false);
}
}

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Ombi.Schedule.Jobs.Plex
{
public interface IPlexRecentlyAddedSync : IBaseJob
{
Task Start();
}
}

@ -62,7 +62,7 @@ namespace Ombi.Schedule.Jobs.Plex
private IPlexContentRepository Repo { get; }
private IPlexEpisodeSync EpisodeSync { get; }
public async Task CacheContent()
public async Task CacheContent(bool recentlyAddedSearch = false)
{
var plexSettings = await Plex.GetSettingsAsync();
if (!plexSettings.Enable)
@ -78,7 +78,7 @@ namespace Ombi.Schedule.Jobs.Plex
Logger.LogInformation("Starting Plex Content Cacher");
try
{
await StartTheCache(plexSettings);
await StartTheCache(plexSettings, recentlyAddedSearch);
}
catch (Exception e)
{
@ -89,14 +89,14 @@ namespace Ombi.Schedule.Jobs.Plex
BackgroundJob.Enqueue(() => EpisodeSync.Start());
}
private async Task StartTheCache(PlexSettings plexSettings)
private async Task StartTheCache(PlexSettings plexSettings, bool recentlyAddedSearch)
{
foreach (var servers in plexSettings.Servers ?? new List<PlexServers>())
{
try
{
Logger.LogInformation("Starting to cache the content on server {0}", servers.Name);
await ProcessServer(servers);
await ProcessServer(servers, recentlyAddedSearch);
}
catch (Exception e)
{
@ -105,10 +105,10 @@ namespace Ombi.Schedule.Jobs.Plex
}
}
private async Task ProcessServer(PlexServers servers)
private async Task ProcessServer(PlexServers servers, bool recentlyAddedSearch)
{
Logger.LogInformation("Getting all content from server {0}", servers.Name);
var allContent = await GetAllContent(servers);
var allContent = await GetAllContent(servers, recentlyAddedSearch);
Logger.LogInformation("We found {0} items", allContent.Count);
// Let's now process this.
@ -388,8 +388,9 @@ namespace Ombi.Schedule.Jobs.Plex
/// If they have not set the settings then we will monitor them all
/// </summary>
/// <param name="plexSettings">The plex settings.</param>
/// <param name="recentlyAddedSearch"></param>
/// <returns></returns>
private async Task<List<Mediacontainer>> GetAllContent(PlexServers plexSettings)
private async Task<List<Mediacontainer>> GetAllContent(PlexServers plexSettings, bool recentlyAddedSearch)
{
var sections = await PlexApi.GetLibrarySections(plexSettings.PlexAuthToken, plexSettings.FullUri);
@ -413,10 +414,23 @@ namespace Ombi.Schedule.Jobs.Plex
}
}
}
var lib = await PlexApi.GetLibrary(plexSettings.PlexAuthToken, plexSettings.FullUri, dir.key);
if (lib != null)
if (recentlyAddedSearch)
{
libs.Add(lib.MediaContainer);
var container = await PlexApi.GetRecentlyAdded(plexSettings.PlexAuthToken, plexSettings.FullUri,
dir.key);
if (container != null)
{
libs.Add(container.MediaContainer);
}
}
else
{
var lib = await PlexApi.GetLibrary(plexSettings.PlexAuthToken, plexSettings.FullUri, dir.key);
if (lib != null)
{
libs.Add(lib.MediaContainer);
}
}
}
}

@ -0,0 +1,40 @@
using System;
using System.Threading.Tasks;
using Ombi.Api.Plex;
namespace Ombi.Schedule.Jobs.Plex
{
public class PlexRecentlyAddedSync : IPlexRecentlyAddedSync
{
public PlexRecentlyAddedSync(IPlexContentSync contentSync)
{
_sync = contentSync;
}
private readonly IPlexContentSync _sync;
public async Task Start()
{
await _sync.CacheContent(true);
}
private bool _disposed;
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
_sync?.Dispose();
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

@ -6,6 +6,7 @@
public string SonarrSync { get; set; }
public string RadarrSync { get; set; }
public string PlexContentSync { get; set; }
public string PlexRecentlyAddedSync { get; set; }
public string CouchPotatoSync { get; set; }
public string AutomaticUpdater { get; set; }
public string UserImporter { get; set; }

@ -21,7 +21,11 @@ namespace Ombi.Settings.Settings.Models
}
public static string PlexContent(JobSettings s)
{
return Get(s.PlexContentSync, Cron.Hourly(20));
return Get(s.PlexContentSync, Cron.HourInterval(6));
}
public static string PlexRecentlyAdded(JobSettings s)
{
return Get(s.PlexRecentlyAddedSync, Cron.Hourly(0));
}
public static string CouchPotato(JobSettings s)
{
@ -49,7 +53,6 @@ namespace Ombi.Settings.Settings.Models
return Get(s.RefreshMetadata, Cron.Daily(3));
}
private static string Get(string settings, string defaultCron)
{
return settings.HasValue() ? settings : defaultCron;

@ -128,6 +128,7 @@ export interface IJobSettings {
sickRageSync: string;
refreshMetadata: string;
newsletter: string;
plexRecentlyAddedSync: string;
}
export interface IIssueSettings extends ISettings {

@ -35,6 +35,10 @@ export class JobService extends ServiceHelpers {
return this.http.post<boolean>(`${this.url}plexcontentcacher/`, {headers: this.headers});
}
public runPlexRecentlyAddedCacher(): Observable<boolean> {
return this.http.post<boolean>(`${this.url}plexrecentlyadded/`, {headers: this.headers});
}
public runEmbyCacher(): Observable<boolean> {
return this.http.post<boolean>(`${this.url}embycontentcacher/`, {headers: this.headers});
}

@ -57,6 +57,12 @@
<small *ngIf="form.get('plexContentSync').hasError('required')" class="error-text">The Plex Sync is required</small>
<button type="button" class="btn btn-sm btn-primary-outline" (click)="testCron(form.get('plexContentSync')?.value)">Test</button>
</div>
<div class="form-group">
<label for="plexRecentlyAddedSync" class="control-label">Plex Recently Added Sync</label>
<input type="text" class="form-control form-control-custom" [ngClass]="{'form-error': form.get('plexRecentlyAddedSync').hasError('required')}" id="plexRecentlyAddedSync" name="plexContentSync" formControlName="plexContentSync">
<small *ngIf="form.get('plexRecentlyAddedSync').hasError('required')" class="error-text">The Plex Sync is required</small>
<button type="button" class="btn btn-sm btn-primary-outline" (click)="testCron(form.get('plexRecentlyAddedSync')?.value)">Test</button>
</div>
<div class="form-group">
<label for="embyContentSync" class="control-label">Emby Sync</label>

@ -33,6 +33,7 @@ export class JobsComponent implements OnInit {
sickRageSync: [x.sickRageSync, Validators.required],
refreshMetadata: [x.refreshMetadata, Validators.required],
newsletter: [x.newsletter, Validators.required],
plexRecentlyAddedSync: [x.plexRecentlyAddedSync, Validators.required]
});
});
}

@ -171,19 +171,26 @@
</ngb-tab>
</div>
</ngb-tabset>
<div class="col-md-1">
<div class="col-md-2">
<div class="form-group">
<div>
<button (click)="save()" type="submit" id="save" class="btn btn-primary-outline">Submit</button>
</div>
</div>
</div>
<div class="col-md-1">
<div class="form-group">
<div>
<button (click)="runCacher()" type="button" id="save" class="btn btn-primary-outline">Manually Run Cacher</button>
</div>
<div class="col-md-3">
<div class="form-group">
<div>
<button (click)="runCacher()" type="button" id="save" class="btn btn-primary-outline">Manually Run Full Sync</button>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div>
<button (click)="runRecentlyAddedCacher()" type="button" id="save" class="btn btn-primary-outline">Manually Run Recently Added Sync</button>
</div>
</div>
</div>
</fieldset>
</div>

@ -121,7 +121,15 @@ export class PlexComponent implements OnInit, OnDestroy {
public runCacher(): void {
this.jobService.runPlexCacher().subscribe(x => {
if(x) {
this.notificationService.success("Triggered the Plex Content Cacher");
this.notificationService.success("Triggered the Plex Full Sync");
}
});
}
public runRecentlyAddedCacher(): void {
this.jobService.runPlexRecentlyAddedCacher().subscribe(x => {
if(x) {
this.notificationService.success("Triggered the Plex Recently Added Sync");
}
});
}

@ -117,7 +117,18 @@ namespace Ombi.Controllers
[HttpPost("plexcontentcacher")]
public bool StartPlexContentCacher()
{
BackgroundJob.Enqueue(() => _plexContentSync.CacheContent());
BackgroundJob.Enqueue(() => _plexContentSync.CacheContent(false));
return true;
}
/// <summary>
/// Runs a smaller version of the content cacher
/// </summary>
/// <returns></returns>
[HttpPost("plexrecentlyadded")]
public bool StartRecentlyAdded()
{
BackgroundJob.Enqueue(() => _plexContentSync.CacheContent(true));
return true;
}

@ -473,6 +473,7 @@ namespace Ombi.Controllers
j.UserImporter = j.UserImporter.HasValue() ? j.UserImporter : JobSettingsHelper.UserImporter(j);
j.SickRageSync = j.SickRageSync.HasValue() ? j.SickRageSync : JobSettingsHelper.SickRageSync(j);
j.RefreshMetadata = j.RefreshMetadata.HasValue() ? j.RefreshMetadata : JobSettingsHelper.RefreshMetadata(j);
j.PlexRecentlyAddedSync = j.PlexRecentlyAddedSync.HasValue() ? j.PlexRecentlyAddedSync : JobSettingsHelper.PlexRecentlyAdded(j);
return j;
}

@ -182,12 +182,15 @@ namespace Ombi
// Check if it's in the startup args
var appConfig = serviceProvider.GetService<IApplicationConfigRepository>();
var baseUrl = appConfig.Get(ConfigurationTypes.BaseUrl).Result;
if (baseUrl.Value.HasValue())
if (baseUrl != null)
{
settings.BaseUrl = baseUrl.Value;
ombiService.SaveSettings(settings);
if (baseUrl.Value.HasValue())
{
settings.BaseUrl = baseUrl.Value;
ombiService.SaveSettings(settings);
app.UsePathBase(settings.BaseUrl);
app.UsePathBase(settings.BaseUrl);
}
}
}

Loading…
Cancel
Save