mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 21:33:15 -07:00
cache the couchpotato wanted list, update it on an interval, and use it to determine if a movie has been queued already
This commit is contained in:
parent
e8fb28a024
commit
6ed7df2c21
13 changed files with 283 additions and 11 deletions
|
@ -85,6 +85,7 @@ namespace PlexRequests.UI
|
|||
|
||||
// Services
|
||||
container.Register<IAvailabilityChecker, PlexAvailabilityChecker>();
|
||||
container.Register<ICouchPotatoCacher, CouchPotatoCacher>();
|
||||
container.Register<IConfigurationReader, ConfigurationReader>();
|
||||
container.Register<IIntervals, UpdateInterval>();
|
||||
|
||||
|
@ -106,6 +107,7 @@ namespace PlexRequests.UI
|
|||
|
||||
TaskManager.TaskFactory = new PlexTaskFactory();
|
||||
TaskManager.Initialize(new PlexRegistry());
|
||||
TaskManager.Initialize(new MediaCacheRegistry());
|
||||
}
|
||||
|
||||
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
|
||||
|
|
41
PlexRequests.UI/Jobs/MediaCacheRegistry.cs
Normal file
41
PlexRequests.UI/Jobs/MediaCacheRegistry.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: PlexRegistry.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using FluentScheduler;
|
||||
|
||||
using PlexRequests.Services;
|
||||
|
||||
namespace PlexRequests.UI.Jobs
|
||||
{
|
||||
public class MediaCacheRegistry : Registry
|
||||
{
|
||||
public MediaCacheRegistry()
|
||||
{
|
||||
Schedule<MediaCacheService>().ToRunNow();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ namespace PlexRequests.UI.Modules
|
|||
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
|
||||
IRequestService request, ISonarrApi sonarrApi, ISettingsService<SonarrSettings> sonarrSettings,
|
||||
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
|
||||
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService<HeadphonesSettings> hpService) : base("search")
|
||||
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService<HeadphonesSettings> hpService, ICouchPotatoCacher cpCacher) : base("search")
|
||||
{
|
||||
CpService = cpSettings;
|
||||
PrService = prSettings;
|
||||
|
@ -69,6 +69,7 @@ namespace PlexRequests.UI.Modules
|
|||
TvApi = new TheTvDbApi();
|
||||
Cache = cache;
|
||||
Checker = checker;
|
||||
CpCacher = cpCacher;
|
||||
RequestService = request;
|
||||
SonarrApi = sonarrApi;
|
||||
SonarrService = sonarrSettings;
|
||||
|
@ -109,6 +110,7 @@ namespace PlexRequests.UI.Modules
|
|||
private ISettingsService<SickRageSettings> SickRageService { get; }
|
||||
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
|
||||
private IAvailabilityChecker Checker { get; }
|
||||
private ICouchPotatoCacher CpCacher { get; }
|
||||
private IMusicBrainzApi MusicBrainzApi { get; }
|
||||
private IHeadphonesApi HeadphonesApi { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
@ -150,6 +152,8 @@ namespace PlexRequests.UI.Modules
|
|||
private Response ProcessMovies(MovieSearchType searchType, string searchTerm)
|
||||
{
|
||||
List<Task> taskList = new List<Task>();
|
||||
var z = CpService.GetSettings();
|
||||
CouchPotatoApi.GetMovies(z.FullUri, z.ApiKey, new[] { "active" });
|
||||
|
||||
List<MovieResult> apiMovies = new List<MovieResult>();
|
||||
taskList.Add(Task.Factory.StartNew<List<MovieResult>>(() =>
|
||||
|
@ -198,6 +202,8 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
Task.WaitAll(taskList.ToArray());
|
||||
|
||||
int[] cpCached = CpCacher.QueuedIds();
|
||||
|
||||
List<SearchMovieViewModel> viewMovies = new List<SearchMovieViewModel>();
|
||||
foreach (MovieResult movie in apiMovies)
|
||||
{
|
||||
|
@ -219,7 +225,7 @@ namespace PlexRequests.UI.Modules
|
|||
VoteCount = movie.VoteCount
|
||||
};
|
||||
|
||||
if (dbMovies.ContainsKey(movie.Id))
|
||||
if (dbMovies.ContainsKey(movie.Id)) // compare to the requests db
|
||||
{
|
||||
var dbm = dbMovies[movie.Id];
|
||||
|
||||
|
@ -227,6 +233,10 @@ namespace PlexRequests.UI.Modules
|
|||
viewMovie.Approved = dbm.Approved;
|
||||
viewMovie.Available = dbm.Available;
|
||||
}
|
||||
else if (cpCached.Contains(movie.Id)) // compare to the couchpotato db
|
||||
{
|
||||
viewMovie.Requested = true;
|
||||
}
|
||||
|
||||
viewMovies.Add(viewMovie);
|
||||
}
|
||||
|
|
|
@ -168,6 +168,7 @@
|
|||
<Compile Include="Helpers\StringHelper.cs" />
|
||||
<Compile Include="Helpers\TvSender.cs" />
|
||||
<Compile Include="Helpers\ValidationHelper.cs" />
|
||||
<Compile Include="Jobs\MediaCacheRegistry.cs" />
|
||||
<Compile Include="Models\DatatablesModel.cs" />
|
||||
<Compile Include="Models\MovieSearchType.cs" />
|
||||
<Compile Include="Models\QualityModel.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue