This commit is contained in:
tidusjar 2016-11-16 22:14:21 +00:00
parent c2fe46f741
commit 39888a4b94
16 changed files with 312 additions and 275 deletions

View file

@ -43,5 +43,6 @@ namespace PlexRequests.Core.SettingModels
public int RecentlyAdded { get; set; }
public string RecentlyAddedCron { get; set; }
public int FaultQueueHandler { get; set; }
public int PlexContentCacher { get; set; }
}
}

View file

@ -29,22 +29,23 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using PlexRequests.Store.Models;
using PlexRequests.Store.Models.Plex;
namespace PlexRequests.Services.Interfaces
{
public interface IAvailabilityChecker
{
void CheckAndUpdateAll();
List<PlexMovie> GetPlexMovies();
bool IsMovieAvailable(PlexMovie[] plexMovies, string title, string year, string providerId = null);
List<PlexTvShow> GetPlexTvShows();
bool IsTvShowAvailable(PlexTvShow[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
List<PlexAlbum> GetPlexAlbums();
bool IsAlbumAvailable(PlexAlbum[] plexAlbums, string title, string year, string artist);
IEnumerable<PlexContent> GetPlexMovies(IEnumerable<PlexContent> content);
bool IsMovieAvailable(PlexContent[] plexMovies, string title, string year, string providerId = null);
IEnumerable<PlexContent> GetPlexTvShows(IEnumerable<PlexContent> content);
bool IsTvShowAvailable(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
IEnumerable<PlexContent> GetPlexAlbums(IEnumerable<PlexContent> content);
bool IsAlbumAvailable(PlexContent[] plexAlbums, string title, string year, string artist);
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
PlexAlbum GetAlbum(PlexAlbum[] plexAlbums, string title, string year, string artist);
PlexMovie GetMovie(PlexMovie[] plexMovies, string title, string year, string providerId = null);
PlexTvShow GetTvShow(PlexTvShow[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
PlexContent GetAlbum(PlexContent[] plexAlbums, string title, string year, string artist);
PlexContent GetMovie(PlexContent[] plexMovies, string title, string year, string providerId = null);
PlexContent GetTvShow(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null);
/// <summary>
/// Gets the episode's stored in the cache.
/// </summary>

View file

@ -0,0 +1,10 @@
using Quartz;
namespace PlexRequests.Services.Jobs
{
public interface IPlexContentCacher
{
void CacheContent();
void Execute(IJobExecutionContext context);
}
}

View file

@ -30,7 +30,7 @@ using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Newtonsoft.Json;
using NLog;
using PlexRequests.Api.Interfaces;
@ -89,17 +89,17 @@ namespace PlexRequests.Services.Jobs
Log.Debug("Validation of the plex settings failed.");
return;
}
var libraries = CachedLibraries(plexSettings, true); //force setting the cache (10 min intervals via scheduler)
//var libraries = CachedLibraries(plexSettings, true); //force setting the cache (10 min intervals via scheduler)
if (libraries == null || !libraries.Any())
{
Log.Debug("Did not find any libraries in Plex.");
return;
}
var movies = GetPlexMovies().ToArray();
var shows = GetPlexTvShows().ToArray();
var albums = GetPlexAlbums().ToArray();
//if (libraries == null || !libraries.Any())
//{
// Log.Debug("Did not find any libraries in Plex.");
// return;
//}
var content = PlexContent.GetAll().ToList();
var movies = GetPlexMovies(content).ToArray();
var shows = GetPlexTvShows(content).ToArray();
var albums = GetPlexAlbums(content).ToArray();
var requests = RequestService.GetAll();
var requestedModels = requests as RequestedModel[] ?? requests.Where(x => !x.Available).ToArray();
@ -159,7 +159,7 @@ namespace PlexRequests.Services.Jobs
}
}
public List<PlexMovie> GetPlexMovies()
public List<PlexMovie> GetPlexMoviesOld()
{
var settings = Plex.GetSettings();
var movies = new List<PlexMovie>();
@ -186,13 +186,18 @@ namespace PlexRequests.Services.Jobs
return movies;
}
public bool IsMovieAvailable(PlexMovie[] plexMovies, string title, string year, string providerId = null)
public IEnumerable<PlexContent> GetPlexMovies(IEnumerable<PlexContent> content)
{
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Movie);
}
public bool IsMovieAvailable(PlexContent[] plexMovies, string title, string year, string providerId = null)
{
var movie = GetMovie(plexMovies, title, year, providerId);
return movie != null;
}
public PlexMovie GetMovie(PlexMovie[] plexMovies, string title, string year, string providerId = null)
public PlexContent GetMovie(PlexContent[] plexMovies, string title, string year, string providerId = null)
{
if (plexMovies.Length == 0)
{
@ -223,45 +228,19 @@ namespace PlexRequests.Services.Jobs
return null;
}
public List<PlexTvShow> GetPlexTvShows()
public IEnumerable<PlexContent> GetPlexTvShows(IEnumerable<PlexContent> content)
{
var settings = Plex.GetSettings();
var shows = new List<PlexTvShow>();
var libs = Cache.Get<List<PlexSearch>>(CacheKeys.PlexLibaries);
if (libs != null)
{
var withDir = libs.Where(x => x.Directory != null);
var tvLibs = withDir.Where(x =>
x.Directory.Any(y =>
y.Type.Equals(PlexMediaType.Show.ToString(), StringComparison.CurrentCultureIgnoreCase)
)
).ToArray();
foreach (var lib in tvLibs)
{
shows.AddRange(lib.Directory.Select(x => new PlexTvShow // shows are in the directory list
{
Title = x.Title,
ReleaseYear = x.Year,
ProviderId = x.ProviderId,
Seasons = x.Seasons?.Select(d => PlexHelper.GetSeasonNumberFromTitle(d.Title)).ToArray(),
Url = PlexHelper.GetPlexMediaUrl(settings.MachineIdentifier, x.RatingKey)
}));
}
}
return shows;
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Show);
}
public bool IsTvShowAvailable(PlexTvShow[] plexShows, string title, string year, string providerId = null, int[] seasons = null)
public bool IsTvShowAvailable(PlexContent[] plexShows, string title, string year, string providerId = null, int[] seasons = null)
{
var show = GetTvShow(plexShows, title, year, providerId, seasons);
return show != null;
}
public PlexTvShow GetTvShow(PlexTvShow[] plexShows, string title, string year, string providerId = null,
public PlexContent GetTvShow(PlexContent[] plexShows, string title, string year, string providerId = null,
int[] seasons = null)
{
var advanced = !string.IsNullOrEmpty(providerId);
@ -271,7 +250,8 @@ namespace PlexRequests.Services.Jobs
{
if (show.ProviderId == providerId && seasons != null)
{
if (seasons.Any(season => show.Seasons.Contains(season)))
var showSeasons = ByteConverterHelper.ReturnObject<int[]>(show.Seasons);
if (seasons.Any(season => showSeasons.Contains(season)))
{
return show;
}
@ -357,41 +337,19 @@ namespace PlexRequests.Services.Jobs
return plexEpisodeses;
}
public List<PlexAlbum> GetPlexAlbums()
public IEnumerable<PlexContent> GetPlexAlbums(IEnumerable<PlexContent> content)
{
var settings = Plex.GetSettings();
var albums = new List<PlexAlbum>();
var libs = Cache.Get<List<PlexSearch>>(CacheKeys.PlexLibaries);
if (libs != null)
{
var albumLibs = libs.Where(x =>
x.Directory.Any(y =>
y.Type.Equals(PlexMediaType.Artist.ToString(), StringComparison.CurrentCultureIgnoreCase)
)
).ToArray();
foreach (var lib in albumLibs)
{
albums.AddRange(lib.Directory.Select(x => new PlexAlbum()
{
Title = x.Title,
ReleaseYear = x.Year,
Artist = x.ParentTitle,
Url = PlexHelper.GetPlexMediaUrl(settings.MachineIdentifier, x.RatingKey)
}));
}
}
return albums;
return content.Where(x => x.Type == Store.Models.Plex.PlexMediaType.Artist);
}
public bool IsAlbumAvailable(PlexAlbum[] plexAlbums, string title, string year, string artist)
public bool IsAlbumAvailable(PlexContent[] plexAlbums, string title, string year, string artist)
{
return plexAlbums.Any(x =>
x.Title.Contains(title) &&
x.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase));
}
public PlexAlbum GetAlbum(PlexAlbum[] plexAlbums, string title, string year, string artist)
public PlexContent GetAlbum(PlexContent[] plexAlbums, string title, string year, string artist)
{
return plexAlbums.FirstOrDefault(x =>
x.Title.Contains(title) &&

View file

@ -30,7 +30,7 @@ using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Newtonsoft.Json;
using NLog;
using Org.BouncyCastle.Crypto.Modes.Gcm;
using PlexRequests.Api.Interfaces;
@ -51,7 +51,7 @@ using Quartz;
namespace PlexRequests.Services.Jobs
{
public class PlexContentCacher : IJob
public class PlexContentCacher : IJob, IPlexContentCacher
{
public PlexContentCacher(ISettingsService<PlexSettings> plexSettings, IRequestService request, IPlexApi plex, ICacheProvider cache,
INotificationService notify, IJobRecord rec, IRepository<UsersToNotify> users, IRepository<PlexEpisodes> repo, INotificationEngine e, IRepository<PlexContent> content)
@ -115,7 +115,6 @@ namespace PlexRequests.Services.Jobs
{
movies.AddRange(lib.Video.Select(video => new PlexMovie
{
Id = video.Guid,
ReleaseYear = video.Year,
Title = video.Title,
ProviderId = video.ProviderId,
@ -149,7 +148,6 @@ namespace PlexRequests.Services.Jobs
ProviderId = x.ProviderId,
Seasons = x.Seasons?.Select(d => PlexHelper.GetSeasonNumberFromTitle(d.Title)).ToArray(),
Url = PlexHelper.GetPlexMediaUrl(settings.MachineIdentifier, x.RatingKey),
Id = x.Guid
}));
}
@ -177,7 +175,6 @@ namespace PlexRequests.Services.Jobs
albums.AddRange(lib.Directory.Select(x => new PlexAlbum()
{
Title = x.Title,
Id = x.Guid,
ProviderId = x.ProviderId,
ReleaseYear = x.Year,
Artist = x.ParentTitle,
@ -240,47 +237,66 @@ namespace PlexRequests.Services.Jobs
}
if (results != null)
{
var movies = GetPlexMovies(results);
// Time to destroy the plex movies from the DB
PlexContent.Custom(connection =>
{
connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 0 });
return new List<PlexContent>();
});
foreach (var m in movies)
{
PlexContent.Insert(new PlexContent
{
ProviderId = m.ProviderId,
ReleaseYear = m.ReleaseYear,
ReleaseYear = m.ReleaseYear ?? string.Empty,
Title = m.Title,
Type = Store.Models.Plex.PlexMediaType.Movie,
Url = m.Url,
PlexId = m.Id
Url = m.Url
});
}
var tv = GetPlexTvShows(results);
// Time to destroy the plex tv from the DB
PlexContent.Custom(connection =>
{
connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 1 });
return new List<PlexContent>();
});
foreach (var t in tv)
{
PlexContent.Insert(new PlexContent
{
ProviderId = t.ProviderId,
ReleaseYear = t.ReleaseYear,
ReleaseYear = t.ReleaseYear ?? string.Empty,
Title = t.Title,
Type = Store.Models.Plex.PlexMediaType.Show,
Url = t.Url,
Seasons = t.Seasons,
PlexId = t.Id
Seasons = ByteConverterHelper.ReturnBytes(t.Seasons)
});
}
var albums = GetPlexAlbums(results);
// Time to destroy the plex movies from the DB
PlexContent.Custom(connection =>
{
connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 2 });
return new List<PlexContent>();
});
foreach (var a in albums)
{
PlexContent.Insert(new PlexContent
{
ProviderId = a.ProviderId,
ReleaseYear = a.ReleaseYear,
ReleaseYear = a.ReleaseYear ?? string.Empty,
Title = a.Title,
Type = Store.Models.Plex.PlexMediaType.Artist,
Url = a.Url,
PlexId = a.Id
Url = a.Url
});
}
}

View file

@ -36,6 +36,10 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
@ -81,6 +85,7 @@
<Compile Include="Interfaces\IJobRecord.cs" />
<Compile Include="Interfaces\INotificationEngine.cs" />
<Compile Include="Jobs\HtmlTemplateGenerator.cs" />
<Compile Include="Jobs\IPlexContentCacher.cs" />
<Compile Include="Jobs\IRecentlyAdded.cs" />
<Compile Include="Jobs\JobRecord.cs" />
<Compile Include="Jobs\JobNames.cs" />

View file

@ -38,12 +38,11 @@ namespace PlexRequests.Store.Models.Plex
public string ProviderId { get; set; }
public PlexMediaType Type { get; set; }
public string Url { get; set; }
public string PlexId { get; set; }
/// <summary>
/// Only used for TV Shows
/// </summary>
public int[] Seasons { get; set; }
public byte[] Seasons { get; set; }
/// <summary>
/// Only used for Albums

View file

@ -28,8 +28,8 @@ namespace PlexRequests.Store.Models.Plex
{
public enum PlexMediaType
{
Movie,
Show,
Artist
Movie = 0,
Show = 1,
Artist = 2
}
}

View file

@ -154,7 +154,6 @@ CREATE TABLE IF NOT EXISTS PlexContent
ReleaseYear VARCHAR(100) NOT NULL,
ProviderId VARCHAR(100) NOT NULL,
Url VARCHAR(100) NOT NULL,
PlexId VARCHAR(100) NOT NULL,
Artist VARCHAR(100),
Seasons BLOB,
Type INTEGER NOT NULL

View file

@ -1,167 +1,167 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SearchModuleTests.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
//#region Copyright
//// /************************************************************************
//// Copyright (c) 2016 Jamie Rees
//// File: SearchModuleTests.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 System;
using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Plex;
using PlexRequests.Core;
using PlexRequests.Core.Queue;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Analytics;
using PlexRequests.Services.Interfaces;
using PlexRequests.Services.Jobs;
using PlexRequests.Store;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;
using PlexRequests.UI.Modules;
using Ploeh.AutoFixture;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using Moq;
//using NUnit.Framework;
//using PlexRequests.Api.Interfaces;
//using PlexRequests.Api.Models.Plex;
//using PlexRequests.Core;
//using PlexRequests.Core.Queue;
//using PlexRequests.Core.SettingModels;
//using PlexRequests.Helpers;
//using PlexRequests.Helpers.Analytics;
//using PlexRequests.Services.Interfaces;
//using PlexRequests.Services.Jobs;
//using PlexRequests.Store;
//using PlexRequests.Store.Models;
//using PlexRequests.Store.Repository;
//using PlexRequests.UI.Modules;
//using Ploeh.AutoFixture;
namespace PlexRequests.UI.Tests
{
[TestFixture]
public class SearchModuleTests
{
private Mock<ISettingsService<HeadphonesSettings>> _headphonesSettings;
private Mock<INotificationService> _notificationService;
private Mock<ISettingsService<SickRageSettings>> _sickRageSettingsMock;
private Mock<ICouchPotatoApi> _cpApi;
private Mock<ISettingsService<SonarrSettings>> _sonarrSettingsMock;
private Mock<ISonarrApi> _sonarrApiMock;
private Mock<ISettingsService<PlexSettings>> _plexSettingsMock;
private Mock<ISettingsService<CouchPotatoSettings>> _cpMock;
private Mock<ISettingsService<PlexRequestSettings>> _plexRequestMock;
private Mock<ISettingsService<AuthenticationSettings>> _authMock;
private Mock<IAnalytics> _analytics;
private Mock<IAvailabilityChecker> _availabilityMock;
private Mock<IRequestService> _rServiceMock;
private Mock<ISickRageApi> _srApi;
private Mock<IMusicBrainzApi> _music;
private Mock<IHeadphonesApi> _hpAPi;
private Mock<ICouchPotatoCacher> _cpCache;
private Mock<ISonarrCacher> _sonarrCache;
private Mock<ISickRageCacher> _srCache;
private Mock<IPlexApi> _plexApi;
private Mock<IRepository<UsersToNotify>> _userRepo;
private Mock<ISettingsService<EmailNotificationSettings>> _emailSettings;
private Mock<IIssueService> _issueService;
private Mock<ICacheProvider> _cache;
private Mock<ITransientFaultQueue> _faultQueue;
private Mock<IRepository<RequestLimit>> RequestLimitRepo { get; set; }
private SearchModule Search { get; set; }
private readonly Fixture F = new Fixture();
//namespace PlexRequests.UI.Tests
//{
// [TestFixture]
// public class SearchModuleTests
// {
// private Mock<ISettingsService<HeadphonesSettings>> _headphonesSettings;
// private Mock<INotificationService> _notificationService;
// private Mock<ISettingsService<SickRageSettings>> _sickRageSettingsMock;
// private Mock<ICouchPotatoApi> _cpApi;
// private Mock<ISettingsService<SonarrSettings>> _sonarrSettingsMock;
// private Mock<ISonarrApi> _sonarrApiMock;
// private Mock<ISettingsService<PlexSettings>> _plexSettingsMock;
// private Mock<ISettingsService<CouchPotatoSettings>> _cpMock;
// private Mock<ISettingsService<PlexRequestSettings>> _plexRequestMock;
// private Mock<ISettingsService<AuthenticationSettings>> _authMock;
// private Mock<IAnalytics> _analytics;
// private Mock<IAvailabilityChecker> _availabilityMock;
// private Mock<IRequestService> _rServiceMock;
// private Mock<ISickRageApi> _srApi;
// private Mock<IMusicBrainzApi> _music;
// private Mock<IHeadphonesApi> _hpAPi;
// private Mock<ICouchPotatoCacher> _cpCache;
// private Mock<ISonarrCacher> _sonarrCache;
// private Mock<ISickRageCacher> _srCache;
// private Mock<IPlexApi> _plexApi;
// private Mock<IRepository<UsersToNotify>> _userRepo;
// private Mock<ISettingsService<EmailNotificationSettings>> _emailSettings;
// private Mock<IIssueService> _issueService;
// private Mock<ICacheProvider> _cache;
// private Mock<ITransientFaultQueue> _faultQueue;
// private Mock<IRepository<RequestLimit>> RequestLimitRepo { get; set; }
// private SearchModule Search { get; set; }
// private readonly Fixture F = new Fixture();
[Test]
public void CheckNoRequestLimitTest()
{
var settings = new PlexRequestSettings { AlbumWeeklyRequestLimit = 0, MovieWeeklyRequestLimit = 2, TvWeeklyRequestLimit = 0 };
var result = Search.CheckRequestLimit(settings, RequestType.Movie).Result;
// [Test]
// public void CheckNoRequestLimitTest()
// {
// var settings = new PlexRequestSettings { AlbumWeeklyRequestLimit = 0, MovieWeeklyRequestLimit = 2, TvWeeklyRequestLimit = 0 };
// var result = Search.CheckRequestLimit(settings, RequestType.Movie).Result;
Assert.That(result, Is.True);
RequestLimitRepo.Verify(x => x.GetAllAsync(), Times.Once);
}
// Assert.That(result, Is.True);
// RequestLimitRepo.Verify(x => x.GetAllAsync(), Times.Once);
// }
[TestCaseSource(nameof(MovieLimitData))]
public bool CheckMovieLimitTest(int requestCount)
{
var users = F.CreateMany<RequestLimit>().ToList();
users.Add(new RequestLimit { Username = "", RequestCount = requestCount, RequestType = RequestType.Movie});
RequestLimitRepo.Setup(x => x.GetAllAsync()).ReturnsAsync(users);
var settings = new PlexRequestSettings { AlbumWeeklyRequestLimit = 0, MovieWeeklyRequestLimit = 5, TvWeeklyRequestLimit = 0 };
var result = Search.CheckRequestLimit(settings, RequestType.Movie).Result;
// [TestCaseSource(nameof(MovieLimitData))]
// public bool CheckMovieLimitTest(int requestCount)
// {
// var users = F.CreateMany<RequestLimit>().ToList();
// users.Add(new RequestLimit { Username = "", RequestCount = requestCount, RequestType = RequestType.Movie});
// RequestLimitRepo.Setup(x => x.GetAllAsync()).ReturnsAsync(users);
// var settings = new PlexRequestSettings { AlbumWeeklyRequestLimit = 0, MovieWeeklyRequestLimit = 5, TvWeeklyRequestLimit = 0 };
// var result = Search.CheckRequestLimit(settings, RequestType.Movie).Result;
RequestLimitRepo.Verify(x => x.GetAllAsync(), Times.Once);
// RequestLimitRepo.Verify(x => x.GetAllAsync(), Times.Once);
return result;
}
// return result;
// }
private static IEnumerable<TestCaseData> MovieLimitData
{
get
{
yield return new TestCaseData(1).Returns(true).SetName("1 Request of 5");
yield return new TestCaseData(2).Returns(true).SetName("2 Request of 5");
yield return new TestCaseData(3).Returns(true).SetName("3 Request of 5");
yield return new TestCaseData(4).Returns(true).SetName("4 Request of 5");
yield return new TestCaseData(5).Returns(false).SetName("5 Request of 5");
yield return new TestCaseData(6).Returns(false).SetName("6 Request of 5");
yield return new TestCaseData(0).Returns(true).SetName("0 Request of 5");
}
}
// private static IEnumerable<TestCaseData> MovieLimitData
// {
// get
// {
// yield return new TestCaseData(1).Returns(true).SetName("1 Request of 5");
// yield return new TestCaseData(2).Returns(true).SetName("2 Request of 5");
// yield return new TestCaseData(3).Returns(true).SetName("3 Request of 5");
// yield return new TestCaseData(4).Returns(true).SetName("4 Request of 5");
// yield return new TestCaseData(5).Returns(false).SetName("5 Request of 5");
// yield return new TestCaseData(6).Returns(false).SetName("6 Request of 5");
// yield return new TestCaseData(0).Returns(true).SetName("0 Request of 5");
// }
// }
[SetUp]
public void Setup()
{
_authMock = new Mock<Core.ISettingsService<AuthenticationSettings>>();
_plexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
_plexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
_cpMock = new Mock<Core.ISettingsService<CouchPotatoSettings>>();
_plexSettingsMock = new Mock<Core.ISettingsService<PlexSettings>>();
_sonarrApiMock = new Mock<ISonarrApi>();
_sonarrSettingsMock = new Mock<Core.ISettingsService<SonarrSettings>>();
_cpApi = new Mock<ICouchPotatoApi>();
_sickRageSettingsMock = new Mock<Core.ISettingsService<SickRageSettings>>();
_notificationService = new Mock<INotificationService>();
_headphonesSettings = new Mock<Core.ISettingsService<HeadphonesSettings>>();
_cache = new Mock<ICacheProvider>();
// [SetUp]
// public void Setup()
// {
// _authMock = new Mock<Core.ISettingsService<AuthenticationSettings>>();
// _plexRequestMock = new Mock<ISettingsService<PlexRequestSettings>>();
// _plexRequestMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings());
// _cpMock = new Mock<Core.ISettingsService<CouchPotatoSettings>>();
// _plexSettingsMock = new Mock<Core.ISettingsService<PlexSettings>>();
// _sonarrApiMock = new Mock<ISonarrApi>();
// _sonarrSettingsMock = new Mock<Core.ISettingsService<SonarrSettings>>();
// _cpApi = new Mock<ICouchPotatoApi>();
// _sickRageSettingsMock = new Mock<Core.ISettingsService<SickRageSettings>>();
// _notificationService = new Mock<INotificationService>();
// _headphonesSettings = new Mock<Core.ISettingsService<HeadphonesSettings>>();
// _cache = new Mock<ICacheProvider>();
_analytics = new Mock<IAnalytics>();
_availabilityMock = new Mock<IAvailabilityChecker>();
_rServiceMock = new Mock<IRequestService>();
_srApi = new Mock<ISickRageApi>();
_music = new Mock<IMusicBrainzApi>();
_hpAPi = new Mock<IHeadphonesApi>();
_cpCache = new Mock<ICouchPotatoCacher>();
_sonarrCache = new Mock<ISonarrCacher>();
_srCache = new Mock<ISickRageCacher>();
_plexApi = new Mock<IPlexApi>();
_userRepo = new Mock<IRepository<UsersToNotify>>();
RequestLimitRepo = new Mock<IRepository<RequestLimit>>();
_emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>();
_issueService = new Mock<IIssueService>();
_faultQueue = new Mock<ITransientFaultQueue>();
CreateModule();
}
// _analytics = new Mock<IAnalytics>();
// _availabilityMock = new Mock<IAvailabilityChecker>();
// _rServiceMock = new Mock<IRequestService>();
// _srApi = new Mock<ISickRageApi>();
// _music = new Mock<IMusicBrainzApi>();
// _hpAPi = new Mock<IHeadphonesApi>();
// _cpCache = new Mock<ICouchPotatoCacher>();
// _sonarrCache = new Mock<ISonarrCacher>();
// _srCache = new Mock<ISickRageCacher>();
// _plexApi = new Mock<IPlexApi>();
// _userRepo = new Mock<IRepository<UsersToNotify>>();
// RequestLimitRepo = new Mock<IRepository<RequestLimit>>();
// _emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>();
// _issueService = new Mock<IIssueService>();
// _faultQueue = new Mock<ITransientFaultQueue>();
// CreateModule();
// }
private void CreateModule()
{
Search = new SearchModule(_cache.Object, _cpMock.Object, _plexRequestMock.Object, _availabilityMock.Object,
_rServiceMock.Object, _sonarrApiMock.Object, _sonarrSettingsMock.Object,
_sickRageSettingsMock.Object, _cpApi.Object, _srApi.Object, _notificationService.Object,
_music.Object, _hpAPi.Object, _headphonesSettings.Object, _cpCache.Object, _sonarrCache.Object,
_srCache.Object, _plexApi.Object, _plexSettingsMock.Object, _authMock.Object,
_userRepo.Object, _emailSettings.Object, _issueService.Object, _analytics.Object, RequestLimitRepo.Object, _faultQueue.Object);
}
// private void CreateModule()
// {
// Search = new SearchModule(_cache.Object, _cpMock.Object, _plexRequestMock.Object, _availabilityMock.Object,
// _rServiceMock.Object, _sonarrApiMock.Object, _sonarrSettingsMock.Object,
// _sickRageSettingsMock.Object, _cpApi.Object, _srApi.Object, _notificationService.Object,
// _music.Object, _hpAPi.Object, _headphonesSettings.Object, _cpCache.Object, _sonarrCache.Object,
// _srCache.Object, _plexApi.Object, _plexSettingsMock.Object, _authMock.Object,
// _userRepo.Object, _emailSettings.Object, _issueService.Object, _analytics.Object, RequestLimitRepo.Object, _faultQueue.Object);
// }
}
}
// }
//}

View file

@ -147,10 +147,6 @@
});
}
function getBaseUrl() {
return $('#baseUrl').val();
}
$scope.formatDate = function (utcDate) {
return moment.utc(utcDate).local().format('lll');
}

View file

@ -4,8 +4,11 @@
$http.defaults.headers.common['Content-Type'] = 'application/json'; // Set default headers
var getUsers = function () {
return $http.get('/usermanagement/users');
var url = createBaseUrl(getBaseUrl(), '/usermanagement/users');
return $http.get(url);
};
var addUser = function (user, permissions, features) {
@ -13,32 +16,41 @@
return null;
}
var url = createBaseUrl(getBaseUrl(), '/usermanagement/createuser');
return $http({
url: '/usermanagement/createuser',
url: url,
method: "POST",
data: { username: user.username, password: user.password, permissions: permissions, features : features, email: user.email }
});
}
var getFeatures = function () {
return $http.get('/usermanagement/features');
var url = createBaseUrl(getBaseUrl(), '/usermanagement/features');
return $http.get(url);
}
var getPermissions = function () {
return $http.get('/usermanagement/permissions');
var url = createBaseUrl(getBaseUrl(), '/usermanagement/permissions');
return $http.get(url);
}
var updateUser = function (id, permissions, features, alias, email) {
var url = createBaseUrl(getBaseUrl(), '/usermanagement/updateUser');
return $http({
url: '/usermanagement/updateUser',
url: url,
method: "POST",
data: { id: id, permissions: permissions, features: features, alias: alias, emailAddress: email },
});
}
var deleteUser = function (id) {
var url = createBaseUrl(getBaseUrl(), '/usermanagement/deleteUser');
return $http({
url: '/usermanagement/deleteUser',
url: url,
method: "POST",
data: { id: id }
});
@ -53,6 +65,9 @@
deleteUser: deleteUser
};
}
function getBaseUrl() {
return $('#baseUrl').text();
}
angular.module('PlexRequests').factory('userManagementService', ["$http", userManagementService]);

View file

@ -62,6 +62,7 @@ namespace PlexRequests.UI.Jobs
var jobList = new List<IJobDetail>
{
JobBuilder.Create<PlexAvailabilityChecker>().WithIdentity("PlexAvailabilityChecker", "Plex").Build(),
JobBuilder.Create<PlexContentCacher>().WithIdentity("PlexContentCacher", "Plex").Build(),
JobBuilder.Create<PlexEpisodeCacher>().WithIdentity("PlexEpisodeCacher", "Cache").Build(),
JobBuilder.Create<SickRageCacher>().WithIdentity("SickRageCacher", "Cache").Build(),
JobBuilder.Create<SonarrCacher>().WithIdentity("SonarrCacher", "Cache").Build(),
@ -154,15 +155,25 @@ namespace PlexRequests.UI.Jobs
{
s.FaultQueueHandler = 6;
}
if (s.PlexContentCacher == 0)
{
s.PlexContentCacher = 60;
}
var triggers = new List<ITrigger>();
var plexAvailabilityChecker =
TriggerBuilder.Create()
.WithIdentity("PlexAvailabilityChecker", "Plex")
.StartNow()
.StartAt(DateBuilder.FutureDate(5, IntervalUnit.Minute))
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.PlexAvailabilityChecker).RepeatForever())
.Build();
var plexCacher =
TriggerBuilder.Create()
.WithIdentity("PlexContentCacher", "Plex")
.StartNow()
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.PlexContentCacher).RepeatForever())
.Build();
var srCacher =
TriggerBuilder.Create()
@ -241,6 +252,7 @@ namespace PlexRequests.UI.Jobs
triggers.Add(userRequestLimiter);
triggers.Add(plexEpCacher);
triggers.Add(fault);
triggers.Add(plexCacher);
return triggers;
}

View file

@ -61,6 +61,7 @@ using PlexRequests.Core.Queue;
using PlexRequests.Helpers.Analytics;
using PlexRequests.Helpers.Permissions;
using PlexRequests.Store.Models;
using PlexRequests.Store.Models.Plex;
using PlexRequests.Store.Repository;
using TMDbLib.Objects.General;
@ -81,7 +82,7 @@ namespace PlexRequests.UI.Modules
ICouchPotatoCacher cpCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher, IPlexApi plexApi,
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth,
IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email,
IIssueService issue, IAnalytics a, IRepository<RequestLimit> rl, ITransientFaultQueue tfQueue)
IIssueService issue, IAnalytics a, IRepository<RequestLimit> rl, ITransientFaultQueue tfQueue, IRepository<PlexContent> content)
: base("search", prSettings)
{
Auth = auth;
@ -112,6 +113,7 @@ namespace PlexRequests.UI.Modules
RequestLimitRepo = rl;
FaultQueue = tfQueue;
TvApi = new TvMazeApi();
PlexContentRepository = content;
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
@ -137,6 +139,7 @@ namespace PlexRequests.UI.Modules
Get["/episodes", true] = async (x, ct) => await GetEpisodes();
}
private IRepository<PlexContent> PlexContentRepository { get; }
private TvMazeApi TvApi { get; }
private IPlexApi PlexApi { get; }
private TheMovieDbApi MovieApi { get; }
@ -243,7 +246,8 @@ namespace PlexRequests.UI.Modules
var cpCached = CpCacher.QueuedIds();
var plexMovies = Checker.GetPlexMovies();
var content = PlexContentRepository.GetAll();
var plexMovies = Checker.GetPlexMovies(content);
var settings = await PrService.GetSettingsAsync();
var viewMovies = new List<SearchMovieViewModel>();
var counter = 0;
@ -342,7 +346,8 @@ namespace PlexRequests.UI.Modules
var sonarrCached = SonarrCacher.QueuedIds();
var sickRageCache = SickRageCacher.QueuedIds(); // consider just merging sonarr/sickrage arrays
var plexTvShows = Checker.GetPlexTvShows();
var content = PlexContentRepository.GetAll();
var plexTvShows = Checker.GetPlexTvShows(content);
var viewTv = new List<SearchTvShowViewModel>();
foreach (var t in apiTv)
@ -423,7 +428,8 @@ namespace PlexRequests.UI.Modules
var dbAlbum = allResults.ToDictionary(x => x.MusicBrainzId);
var plexAlbums = Checker.GetPlexAlbums();
var content = PlexContentRepository.GetAll();
var plexAlbums = Checker.GetPlexAlbums(content);
var viewAlbum = new List<SearchMusicViewModel>();
foreach (var a in apiAlbums)
@ -514,7 +520,9 @@ namespace PlexRequests.UI.Modules
try
{
var movies = Checker.GetPlexMovies();
var content = PlexContentRepository.GetAll();
var movies = Checker.GetPlexMovies(content);
if (Checker.IsMovieAvailable(movies.ToArray(), movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString()))
{
return
@ -784,7 +792,9 @@ namespace PlexRequests.UI.Modules
try
{
var shows = Checker.GetPlexTvShows();
var content = PlexContentRepository.GetAll();
var shows = Checker.GetPlexTvShows(content);
var providerId = string.Empty;
var plexSettings = await PlexService.GetSettingsAsync();
if (plexSettings.AdvancedSearch)
@ -1046,7 +1056,9 @@ namespace PlexRequests.UI.Modules
});
}
var albums = Checker.GetPlexAlbums();
var content = PlexContentRepository.GetAll();
var albums = Checker.GetPlexAlbums(content);
var alreadyInPlex = Checker.IsAlbumAvailable(albums.ToArray(), albumInfo.title, release.ToString("yyyy"),
artist.name);

View file

@ -46,6 +46,7 @@ namespace PlexRequests.UI.NinjectModules
Bind<ISonarrCacher>().To<SonarrCacher>();
Bind<ISickRageCacher>().To<SickRageCacher>();
Bind<IRecentlyAdded>().To<RecentlyAdded>();
Bind<IPlexContentCacher>().To<PlexContentCacher>();
Bind<IJobFactory>().To<CustomJobFactory>();
Bind<IAnalytics>().To<Analytics>();

View file

@ -32,7 +32,11 @@ using Ninject.Planning.Bindings.Resolvers;
using NLog;
using Owin;
using PlexRequests.Core;
using PlexRequests.Core.Migration;
using PlexRequests.Services.Jobs;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Jobs;
using PlexRequests.UI.NinjectModules;
@ -74,10 +78,18 @@ namespace PlexRequests.UI
Debug.WriteLine("Settings up Scheduler");
var scheduler = new Scheduler();
// Reset any jobs running
var jobSettings = kernel.Get<IRepository<ScheduledJobs>>();
var all = jobSettings.GetAll();
foreach (var scheduledJobse in all)
{
scheduledJobse.Running = false;
jobSettings.Update(scheduledJobse);
}
scheduler.StartScheduler();
//var c = kernel.Get<IRecentlyAdded>();
//c.Test();