Merge remote-tracking branch 'refs/remotes/origin/dev'

Conflicts:
	PlexRequests.Services/Jobs/RecentlyAdded.cs
This commit is contained in:
Jim MacKenzie 2016-10-19 21:24:47 -05:00
commit 71446f0b59
34 changed files with 761 additions and 323 deletions

View file

@ -122,8 +122,8 @@ namespace PlexRequests.UI.Helpers
var sb = new StringBuilder();
var startUrl = $"{content}/Content";
sb.AppendLine($"<link rel=\"stylesheet\" href=\"/{startUrl}/datepicker.min.css\" type=\"text/css\"/>");
sb.AppendLine($"<script src=\"/{startUrl}/bootstrap-datetimepicker.min.js\"></script>");
sb.AppendLine($"<link rel=\"stylesheet\" href=\"{startUrl}/datepicker.min.css\" type=\"text/css\"/>");
sb.AppendLine($"<script src=\"{startUrl}/bootstrap-datetimepicker.min.js\"></script>");
return helper.Raw(sb.ToString());
}

View file

@ -151,6 +151,15 @@ namespace PlexRequests.UI.Helpers
await Task.Delay(TimeSpan.FromSeconds(1));
series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
// Due to the bug above, we need to make sure all seasons are not monitored
foreach (var s in series.seasons)
{
s.monitored = false;
}
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
}
if (first ?? false)

View file

@ -66,7 +66,7 @@ namespace PlexRequests.UI.Jobs
JobBuilder.Create<StoreBackup>().WithIdentity("StoreBackup", "Database").Build(),
JobBuilder.Create<StoreCleanup>().WithIdentity("StoreCleanup", "Database").Build(),
JobBuilder.Create<UserRequestLimitResetter>().WithIdentity("UserRequestLimiter", "Request").Build(),
JobBuilder.Create<RecentlyAdded>().WithIdentity("RecentlyAdded", "Email").Build()
JobBuilder.Create<RecentlyAdded>().WithIdentity("RecentlyAddedModel", "Email").Build()
};
@ -168,7 +168,7 @@ namespace PlexRequests.UI.Jobs
var rencentlyAdded =
TriggerBuilder.Create()
.WithIdentity("RecentlyAdded", "Email")
.WithIdentity("RecentlyAddedModel", "Email")
.StartNow()
.WithSimpleSchedule(x => x.WithIntervalInHours(2).RepeatForever())
.Build();

View file

@ -25,7 +25,8 @@
// ************************************************************************/
#endregion
using System;
using System.IO;
using Mono.Data.Sqlite;
using Nancy;
using Nancy.ModelBinding;
using Nancy.Security;
@ -35,6 +36,8 @@ using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Store;
using PlexRequests.Store.Repository;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Models;
@ -59,7 +62,7 @@ namespace PlexRequests.UI.Modules
Post["/plex"] = _ => PlexTest();
Post["/sickrage"] = _ => SickRageTest();
Post["/headphones"] = _ => HeadphonesTest();
Post["/plexdb"] = _ => TestPlexDb();
}
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
@ -223,5 +226,65 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); ;
}
}
private Response TestPlexDb()
{
var settings = this.Bind<PlexSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
try
{
var location = string.Empty;
if (string.IsNullOrEmpty(settings.PlexDatabaseLocationOverride))
{
if (Type.GetType("Mono.Runtime") != null)
{
// Mono
location = Path.Combine("/var/lib/plexmediaserver/Library/Application Support/",
"Plex Media Server", "Plug-in Support", "Databases", "com.plexapp.plugins.library.db");
}
else
{
// Default Windows
location = Path.Combine(Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%"),
"Plex Media Server", "Plug-in Support", "Databases", "com.plexapp.plugins.library.db");
}
}
else
{
location = Path.Combine(settings.PlexDatabaseLocationOverride, "Plug-in Support", "Databases", "com.plexapp.plugins.library.db");
}
if (File.Exists(location))
{
return Response.AsJson(new JsonResponseModel
{
Result = true,
Message = "Found the database!"
});
}
return Response.AsJson(new JsonResponseModel
{
Result = false,
Message = $"Could not find the database at the following full location : {location}"
});
}
catch (Exception e)
{
Log.Warn("Exception thrown when attempting to find the plex database: ");
Log.Warn(e);
var message = $"Could not find Plex's DB, please check your settings. <strong>Exception Message:</strong> {e.Message}";
if (e.InnerException != null)
{
message = $"Could not find Plex's DB, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); ;
}
}
}
}

View file

@ -184,14 +184,14 @@ namespace PlexRequests.UI.Modules
private async Task<Response> ProcessMovies(MovieSearchType searchType, string searchTerm)
{
List<MovieResult> apiMovies;
List<SearchMovie> apiMovies;
switch (searchType)
{
case MovieSearchType.Search:
var movies = await MovieApi.SearchMovie(searchTerm);
var movies = await MovieApi.SearchMovie(searchTerm).ConfigureAwait(false);
apiMovies = movies.Select(x =>
new MovieResult
new SearchMovie
{
Adult = x.Adult,
BackdropPath = x.BackdropPath,
@ -217,7 +217,7 @@ namespace PlexRequests.UI.Modules
apiMovies = await MovieApi.GetUpcomingMovies();
break;
default:
apiMovies = new List<MovieResult>();
apiMovies = new List<SearchMovie>();
break;
}
@ -234,6 +234,8 @@ namespace PlexRequests.UI.Modules
var viewMovies = new List<SearchMovieViewModel>();
foreach (var movie in apiMovies)
{
var movieInfoTask = MovieApi.GetMovieInformation(movie.Id).ConfigureAwait(false); // TODO needs to be careful about this, it's adding extra time to search...
// https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2
var viewMovie = new SearchMovieViewModel
{
Adult = movie.Adult,
@ -252,7 +254,8 @@ namespace PlexRequests.UI.Modules
VoteCount = movie.VoteCount
};
var canSee = CanUserSeeThisRequest(viewMovie.Id, settings.UsersCanViewOnlyOwnRequests, dbMovies);
var plexMovie = Checker.GetMovie(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString());
var movieInfo = await movieInfoTask;
var plexMovie = Checker.GetMovie(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString(), movieInfo.ImdbId);
if (plexMovie != null)
{
viewMovie.Available = true;
@ -349,8 +352,7 @@ namespace PlexRequests.UI.Modules
providerId = viewT.Id.ToString();
}
var plexShow = Checker.GetTvShow(plexTvShows.ToArray(), t.show.name, t.show.premiered?.Substring(0, 4),
providerId);
var plexShow = Checker.GetTvShow(plexTvShows.ToArray(), t.show.name, t.show.premiered?.Substring(0, 4), providerId);
if (plexShow != null)
{
viewT.Available = true;
@ -590,7 +592,7 @@ namespace PlexRequests.UI.Modules
RequestedUsers = new List<string> { Username },
Issues = IssueState.None,
ImdbId = showInfo.externals?.imdb ?? string.Empty,
SeasonCount = showInfo.seasonCount,
SeasonCount = showInfo.Season.Count,
TvDbId = showId.ToString()
};
@ -703,7 +705,18 @@ namespace PlexRequests.UI.Modules
}
else
{
if (Checker.IsTvShowAvailable(shows.ToArray(), showInfo.name, showInfo.premiered?.Substring(0, 4), providerId, model.SeasonList))
if (plexSettings.EnableTvEpisodeSearching)
{
foreach (var s in showInfo.Season)
{
var result = Checker.IsEpisodeAvailable(showId.ToString(), s.SeasonNumber, s.EpisodeNumber);
if (result)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} {Resources.UI.Search_AlreadyInPlex}" });
}
}
}
else if (Checker.IsTvShowAvailable(shows.ToArray(), showInfo.name, showInfo.premiered?.Substring(0, 4), providerId, model.SeasonList))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} {Resources.UI.Search_AlreadyInPlex}" });
}

View file

@ -59,7 +59,9 @@ namespace PlexRequests.UI.Modules
{
return Response.AsJson(new JsonUpdateAvailableModel { UpdateAvailable = false });
}
#if DEBUG
return Response.AsJson(new JsonUpdateAvailableModel {UpdateAvailable = false});
#endif
var checker = new StatusChecker();
var release = await Cache.GetOrSetAsync(CacheKeys.LastestProductVersion, async() => await checker.GetStatus(), 30);

View file

@ -46,6 +46,7 @@ namespace PlexRequests.UI.NinjectModules
Bind<ICacheProvider>().To<MemoryCacheProvider>().InSingletonScope();
Bind<ISqliteConfiguration>().To<DbConfiguration>().WithConstructorArgument("provider", new SqliteFactory());
Bind<IPlexDatabase>().To<PlexDatabase>().WithConstructorArgument("provider", new SqliteFactory());
Bind<IPlexReadOnlyDatabase>().To<PlexReadOnlyDatabase>();
Bind<IUserMapper>().To<UserMapper>();

View file

@ -117,6 +117,7 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="Microsoft.CSharp" />
@ -196,8 +197,9 @@
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="TMDbLib, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\TMDbLib.0.9.0.0-alpha\lib\net45\TMDbLib.dll</HintPath>
<Reference Include="TMDbLib, Version=0.9.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\TMDbLib.0.9.6.0-alpha\lib\net45\TMDbLib.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>

View file

@ -32,7 +32,7 @@ using Ninject.Planning.Bindings.Resolvers;
using NLog;
using Owin;
using PlexRequests.Services.Jobs;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Jobs;
using PlexRequests.UI.NinjectModules;

View file

@ -121,6 +121,8 @@
});
$('#save').click(function (e) {
e.preventDefault();
var start = '';
var end = '';
if ($startDate.data("DateTimePicker").date()) {
@ -130,8 +132,6 @@
end = $endDate.data("DateTimePicker").date().toISOString();
}
e.preventDefault();
var $form = $("#mainForm");
var data = $form.serialize();

View file

@ -91,7 +91,15 @@
<div class="form-group">
<label for="PlexDatabaseLocationOverride" class="control-label">Plex Database Override</label>
<div>
<input type="text" class="form-control form-control-custom " id="PlexDatabaseLocationOverride" name="PlexDatabaseLocationOverride" value="@Model.PlexDatabaseLocationOverride">
<input type="text" class="form-control form-control-custom " id="PlexDatabaseLocationOverride" name="PlexDatabaseLocationOverride" placeholder="%LOCALAPPDATA%\Plex Media Server\" value="@Model.PlexDatabaseLocationOverride">
</div>
<small>
This is your Plex data directory location, if we cannot manually find it then you need to specify the location! See <a href="https://support.plex.tv/hc/en-us/articles/202915258-Where-is-the-Plex-Media-Server-data-directory-located-">Here</a>.
</small>
</div>
<div class="form-group">
<div class="">
<button id="dbTest" class="btn btn-primary-outline">Test Database Directory <i class="fa fa-database"></i> <div id="dbSpinner"></div></button>
</div>
</div>
@ -101,6 +109,8 @@
<input type="text" class="form-control-custom form-control" id="authToken" name="PlexAuthToken" placeholder="Plex Auth Token" value="@Model.PlexAuthToken">
</div>
</div>
<div class="form-group">
<label for="username" class="control-label">Username and Password</label>
@ -173,6 +183,38 @@
});
});
$('#dbTest').click(function (e) {
e.preventDefault();
var url = createBaseUrl(base, '/test/plexdb');
var $form = $("#mainForm");
$('#dbSpinner').attr("class", "fa fa-spinner fa-spin");
$.ajax({
type: $form.prop("method"),
url: url,
data: $form.serialize(),
dataType: "json",
success: function (response) {
$('#dbSpinner').attr("class", "");
console.log(response);
if (response.result === true) {
generateNotify(response.message, "success");
$('#dbSpinner').attr("class", "fa fa-check");
} else {
generateNotify(response.message, "warning");
$('#dbSpinner').attr("class", "fa fa-times");
}
},
error: function (e) {
$('#spinner').attr("class", "fa fa-times");
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
$('#requestToken').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");

View file

@ -44,11 +44,12 @@
<package id="System.Diagnostics.Debug" version="4.0.0" targetFramework="net45" />
<package id="System.Globalization" version="4.0.0" targetFramework="net45" />
<package id="System.Linq" version="4.0.0" targetFramework="net45" />
<package id="System.Net.Http" version="4.0.0" targetFramework="net45" />
<package id="System.Reflection" version="4.0.0" targetFramework="net45" />
<package id="System.Reflection.Extensions" version="4.0.0" targetFramework="net45" />
<package id="System.Resources.ResourceManager" version="4.0.0" targetFramework="net45" />
<package id="System.Runtime" version="4.0.0" targetFramework="net45" />
<package id="System.Runtime.Extensions" version="4.0.0" targetFramework="net45" />
<package id="System.Text.RegularExpressions" version="4.0.0" targetFramework="net45" />
<package id="TMDbLib" version="0.9.0.0-alpha" targetFramework="net45" />
<package id="TMDbLib" version="0.9.6.0-alpha" targetFramework="net45" />
</packages>