Started to impliment the Plex checker. This will check plex every x minutes to see if there is any new content and then update the avalibility of the requests

This commit is contained in:
Jamie Rees 2016-03-06 01:25:54 +00:00
commit 3b0b0c521e
19 changed files with 329 additions and 160 deletions

View file

@ -104,7 +104,7 @@ namespace PlexRequests.UI.Modules
Log.Trace("Getting Settings:");
Log.Trace(settings.DumpJson());
return View["/Settings", settings];
return View["Settings", settings];
}
private Response SaveAdmin()
@ -166,7 +166,7 @@ namespace PlexRequests.UI.Modules
{ return Response.AsJson(string.Empty); }
var usernames = users.User.Select(x => x.Username);
return Response.AsJson(usernames); //TODO usernames are not populated.
return Response.AsJson(usernames);
}
private Negotiator CouchPotato()

View file

@ -72,31 +72,25 @@ namespace PlexRequests.UI.Modules
private Response GetMovies()
{
// TODO check plex to see the availability
var settings = AuthSettings.GetSettings();
var plexSettings = PlexSettings.GetSettings();
var plex = new PlexApi();
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
var viewModel = dbMovies.Select(tv => new RequestViewModel
var viewModel = dbMovies.Select(movie => new RequestViewModel
{
ProviderId = tv.ProviderId,
Type = tv.Type,
Status = tv.Status,
ImdbId = tv.ImdbId,
Id = tv.Id,
PosterPath = tv.PosterPath,
ReleaseDate = tv.ReleaseDate.Humanize(),
RequestedDate = tv.RequestedDate.Humanize(),
Approved = tv.Approved,
Title = tv.Title,
Overview = tv.Overview,
RequestedBy = tv.RequestedBy,
ReleaseYear = tv.ReleaseDate.Year.ToString()
ProviderId = movie.ProviderId,
Type = movie.Type,
Status = movie.Status,
ImdbId = movie.ImdbId,
Id = movie.Id,
PosterPath = movie.PosterPath,
ReleaseDate = movie.ReleaseDate.Humanize(),
RequestedDate = movie.RequestedDate.Humanize(),
Approved = movie.Approved,
Title = movie.Title,
Overview = movie.Overview,
RequestedBy = movie.RequestedBy,
ReleaseYear = movie.ReleaseDate.Year.ToString(),
Available = movie.Available
}).ToList();
//TODO check if Available in CP
return Response.AsJson(viewModel);
}
@ -117,9 +111,10 @@ namespace PlexRequests.UI.Modules
Title = tv.Title,
Overview = tv.Overview,
RequestedBy = tv.RequestedBy,
ReleaseYear = tv.ReleaseDate.Year.ToString()
ReleaseYear = tv.ReleaseDate.Year.ToString(),
Available = tv.Available
}).ToList();
//TODO check if Available in Sonarr
return Response.AsJson(viewModel);
}

View file

@ -26,7 +26,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy;
using Nancy.Responses.Negotiation;
@ -37,19 +36,24 @@ using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Store;
using PlexRequests.UI.Jobs;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
{
public class SearchModule : BaseModule
{
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings, ISettingsService<PlexRequestSettings> prSettings) : base("search")
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings,
ISettingsService<PlexRequestSettings> prSettings, IAvailabilityChecker checker,
IRequestService request) : base("search")
{
CpService = cpSettings;
PrService = prSettings;
MovieApi = new TheMovieDbApi();
TvApi = new TheTvDbApi();
Cache = cache;
Checker = checker;
RequestService = request;
Get["/"] = parameters => RequestLoad();
@ -64,9 +68,11 @@ namespace PlexRequests.UI.Modules
}
private TheMovieDbApi MovieApi { get; }
private TheTvDbApi TvApi { get; }
private IRequestService RequestService { get; }
private ICacheProvider Cache { get; }
private ISettingsService<CouchPotatoSettings> CpService { get; }
private ISettingsService<PlexRequestSettings> PrService { get; }
private IAvailabilityChecker Checker { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
@ -145,8 +151,7 @@ namespace PlexRequests.UI.Modules
private Response RequestMovie(int movieId)
{
Log.Trace("Requesting movie with id {0}", movieId);
var s = new SettingsService(Cache);
if (s.CheckRequest(movieId))
if (RequestService.CheckRequest(movieId))
{
Log.Trace("movie with id {0} exists", movieId);
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
@ -193,7 +198,7 @@ namespace PlexRequests.UI.Modules
{
model.Approved = true;
Log.Trace("Adding movie to database requests (No approval required)");
s.AddRequest(movieId, model);
RequestService.AddRequest(movieId, model);
return Response.AsJson(new { Result = true });
}
@ -203,7 +208,9 @@ namespace PlexRequests.UI.Modules
try
{
Log.Trace("Adding movie to database requests");
s.AddRequest(movieId, model);
var id = RequestService.AddRequest(movieId, model);
//BackgroundJob.Enqueue(() => Checker.CheckAndUpdate(model.Title, (int)id));
return Response.AsJson(new { Result = true });
}
catch (Exception e)
@ -223,8 +230,7 @@ namespace PlexRequests.UI.Modules
private Response RequestTvShow(int showId, bool latest)
{
// Latest send to Sonarr and no need to store in DB
var s = new SettingsService(Cache);
if (s.CheckRequest(showId))
if (RequestService.CheckRequest(showId))
{
return Response.AsJson(new { Result = false, Message = "TV Show has already been requested!" });
}
@ -251,7 +257,7 @@ namespace PlexRequests.UI.Modules
RequestedBy = Session[SessionKeys.UsernameKey].ToString()
};
s.AddRequest(showId, model);
RequestService.AddRequest(showId, model);
return Response.AsJson(new { Result = true });
}
private string GetAuthToken(TheTvDbApi api)