|
|
@ -43,13 +43,14 @@ namespace PlexRequests.UI.Modules
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class SearchModule : BaseModule
|
|
|
|
public class SearchModule : BaseModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings) : base("search")
|
|
|
|
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings, ISettingsService<PlexRequestSettings> prSettings) : base("search")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CpService = cpSettings;
|
|
|
|
CpService = cpSettings;
|
|
|
|
|
|
|
|
PrService = prSettings;
|
|
|
|
MovieApi = new TheMovieDbApi();
|
|
|
|
MovieApi = new TheMovieDbApi();
|
|
|
|
TvApi = new TheTvDbApi();
|
|
|
|
TvApi = new TheTvDbApi();
|
|
|
|
Cache = cache;
|
|
|
|
Cache = cache;
|
|
|
|
|
|
|
|
|
|
|
|
Get["/"] = parameters => RequestLoad();
|
|
|
|
Get["/"] = parameters => RequestLoad();
|
|
|
|
|
|
|
|
|
|
|
|
Get["movie/{searchTerm}"] = parameters => SearchMovie((string)parameters.searchTerm);
|
|
|
|
Get["movie/{searchTerm}"] = parameters => SearchMovie((string)parameters.searchTerm);
|
|
|
@ -64,14 +65,17 @@ namespace PlexRequests.UI.Modules
|
|
|
|
private TheMovieDbApi MovieApi { get; }
|
|
|
|
private TheMovieDbApi MovieApi { get; }
|
|
|
|
private TheTvDbApi TvApi { get; }
|
|
|
|
private TheTvDbApi TvApi { get; }
|
|
|
|
private ICacheProvider Cache { get; }
|
|
|
|
private ICacheProvider Cache { get; }
|
|
|
|
private ISettingsService<CouchPotatoSettings> CpService { get; set; }
|
|
|
|
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
|
|
|
|
|
|
|
private ISettingsService<PlexRequestSettings> PrService { get; }
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
|
|
|
|
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
|
|
|
|
|
|
|
|
|
|
|
|
private Negotiator RequestLoad()
|
|
|
|
private Negotiator RequestLoad()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var settings = PrService.GetSettings();
|
|
|
|
|
|
|
|
|
|
|
|
Log.Trace("Loading Index");
|
|
|
|
Log.Trace("Loading Index");
|
|
|
|
return View["Search/Index"];
|
|
|
|
return View["Search/Index", settings];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Response SearchMovie(string searchTerm)
|
|
|
|
private Response SearchMovie(string searchTerm)
|
|
|
@ -103,7 +107,7 @@ namespace PlexRequests.UI.Modules
|
|
|
|
Aliases = t.aliases,
|
|
|
|
Aliases = t.aliases,
|
|
|
|
// We are constructing the banner with the id:
|
|
|
|
// We are constructing the banner with the id:
|
|
|
|
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg
|
|
|
|
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg
|
|
|
|
Banner = t.id.ToString(),
|
|
|
|
Banner = t.id.ToString(),
|
|
|
|
FirstAired = t.firstAired,
|
|
|
|
FirstAired = t.firstAired,
|
|
|
|
Genre = t.genre,
|
|
|
|
Genre = t.genre,
|
|
|
|
Id = t.id,
|
|
|
|
Id = t.id,
|
|
|
@ -148,14 +152,14 @@ namespace PlexRequests.UI.Modules
|
|
|
|
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
|
|
|
|
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.Trace("movie with id {0} doesnt exists", movieId);
|
|
|
|
Log.Trace("movie with id {0} doesnt exists", movieId);
|
|
|
|
var settings = CpService.GetSettings();
|
|
|
|
var cpSettings = CpService.GetSettings();
|
|
|
|
if (settings.ApiKey == null)
|
|
|
|
if (cpSettings.ApiKey == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Warn("CP apiKey is null");
|
|
|
|
Log.Warn("CP apiKey is null");
|
|
|
|
return Response.AsJson(new { Result = false, Message = "CouchPotato is not yet configured, If you are the Admin, please log in." });
|
|
|
|
return Response.AsJson(new { Result = false, Message = "CouchPotato is not yet configured, If you are the Admin, please log in." });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.Trace("Settings: ");
|
|
|
|
Log.Trace("Settings: ");
|
|
|
|
Log.Trace(settings.DumpJson);
|
|
|
|
Log.Trace(cpSettings.DumpJson);
|
|
|
|
|
|
|
|
|
|
|
|
var movieApi = new TheMovieDbApi();
|
|
|
|
var movieApi = new TheMovieDbApi();
|
|
|
|
var movieInfo = movieApi.GetMovieInformation(movieId).Result;
|
|
|
|
var movieInfo = movieApi.GetMovieInformation(movieId).Result;
|
|
|
@ -173,21 +177,41 @@ namespace PlexRequests.UI.Modules
|
|
|
|
ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue,
|
|
|
|
ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue,
|
|
|
|
Status = movieInfo.Status,
|
|
|
|
Status = movieInfo.Status,
|
|
|
|
RequestedDate = DateTime.Now,
|
|
|
|
RequestedDate = DateTime.Now,
|
|
|
|
Approved = false
|
|
|
|
Approved = false,
|
|
|
|
|
|
|
|
RequestedBy = Session[SessionKeys.UsernameKey].ToString()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var cp = new CouchPotatoApi();
|
|
|
|
|
|
|
|
Log.Trace("Adding movie to CP");
|
|
|
|
var settings = PrService.GetSettings();
|
|
|
|
var result = cp.AddMovie(model.ImdbId, settings.ApiKey, model.Title, settings.FullUri);
|
|
|
|
if (!settings.RequireApproval)
|
|
|
|
Log.Trace("Adding movie to CP result {0}", result);
|
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
var cp = new CouchPotatoApi();
|
|
|
|
|
|
|
|
Log.Trace("Adding movie to CP (No approval required)");
|
|
|
|
|
|
|
|
var result = cp.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri);
|
|
|
|
|
|
|
|
Log.Trace("Adding movie to CP result {0}", result);
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
model.Approved = true;
|
|
|
|
|
|
|
|
Log.Trace("Adding movie to database requests (No approval required)");
|
|
|
|
|
|
|
|
s.AddRequest(movieId, model);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Response.AsJson(new { Result = true });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.AsJson(new { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Trace("Adding movie to database requests");
|
|
|
|
Log.Trace("Adding movie to database requests");
|
|
|
|
s.AddRequest(movieId, model);
|
|
|
|
s.AddRequest(movieId, model);
|
|
|
|
|
|
|
|
|
|
|
|
return Response.AsJson(new { Result = true });
|
|
|
|
return Response.AsJson(new { Result = true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.AsJson(new { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Log.Fatal(e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Response.AsJson(new { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -213,7 +237,7 @@ namespace PlexRequests.UI.Modules
|
|
|
|
DateTime firstAir;
|
|
|
|
DateTime firstAir;
|
|
|
|
DateTime.TryParse(showInfo.firstAired, out firstAir);
|
|
|
|
DateTime.TryParse(showInfo.firstAired, out firstAir);
|
|
|
|
|
|
|
|
|
|
|
|
var model = new RequestedModel
|
|
|
|
var model = new RequestedModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ProviderId = showInfo.id,
|
|
|
|
ProviderId = showInfo.id,
|
|
|
|
Type = RequestType.TvShow,
|
|
|
|
Type = RequestType.TvShow,
|
|
|
@ -223,11 +247,12 @@ namespace PlexRequests.UI.Modules
|
|
|
|
ReleaseDate = firstAir,
|
|
|
|
ReleaseDate = firstAir,
|
|
|
|
Status = showInfo.status,
|
|
|
|
Status = showInfo.status,
|
|
|
|
RequestedDate = DateTime.Now,
|
|
|
|
RequestedDate = DateTime.Now,
|
|
|
|
Approved = false
|
|
|
|
Approved = false,
|
|
|
|
|
|
|
|
RequestedBy = Session[SessionKeys.UsernameKey].ToString()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
s.AddRequest(showId, model);
|
|
|
|
s.AddRequest(showId, model);
|
|
|
|
return Response.AsJson(new {Result = true });
|
|
|
|
return Response.AsJson(new { Result = true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private string GetAuthToken(TheTvDbApi api)
|
|
|
|
private string GetAuthToken(TheTvDbApi api)
|
|
|
|
{
|
|
|
|
{
|
|
|
|