From 88c0651b1e0985996ab9fc88422d9b857068eb5e Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Mon, 16 Jan 2017 15:23:04 +0000 Subject: [PATCH] Improved the search UI and made it more consistant. Finished the Netflix API Part #884 --- Ombi.Api.Interfaces/INetflixApi.cs | 2 +- Ombi.Api.Models/Netflix/NetflixMovieResult.cs | 7 +++ Ombi.Api/ApiRequest.cs | 2 +- Ombi.Api/NetflixRouletteApi.cs | 5 +- Ombi.UI/Content/search.js | 18 ++++++ Ombi.UI/Modules/SearchExtensionModule.cs | 62 +++++++++++++++++++ Ombi.UI/NinjectModules/ApiModule.cs | 1 + Ombi.UI/Ombi.UI.csproj | 1 + Ombi.UI/Views/Search/Index.cshtml | 7 ++- 9 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 Ombi.UI/Modules/SearchExtensionModule.cs diff --git a/Ombi.Api.Interfaces/INetflixApi.cs b/Ombi.Api.Interfaces/INetflixApi.cs index 9e1a02b6b..2c427f6f3 100644 --- a/Ombi.Api.Interfaces/INetflixApi.cs +++ b/Ombi.Api.Interfaces/INetflixApi.cs @@ -31,6 +31,6 @@ namespace Ombi.Api.Interfaces { public interface INetflixApi { - NetflixMovieResult GetMovies(string movieName, string year = null); + NetflixMovieResult CheckNetflix(string title, string year = null); } } \ No newline at end of file diff --git a/Ombi.Api.Models/Netflix/NetflixMovieResult.cs b/Ombi.Api.Models/Netflix/NetflixMovieResult.cs index 71007d34f..0ed213cf2 100644 --- a/Ombi.Api.Models/Netflix/NetflixMovieResult.cs +++ b/Ombi.Api.Models/Netflix/NetflixMovieResult.cs @@ -58,5 +58,12 @@ namespace Ombi.Api.Models.Netflix public string Mediatype { get; set; } [JsonProperty(PropertyName = "runtime")] public string Runtime { get; set; } + + + // For errors + [JsonProperty(PropertyName = "errorcode")] + public int ErrorCode { get; set; } + [JsonProperty(PropertyName = "message")] + public string Message { get; set; } } } \ No newline at end of file diff --git a/Ombi.Api/ApiRequest.cs b/Ombi.Api/ApiRequest.cs index 67a5bbc9e..a27d4af28 100644 --- a/Ombi.Api/ApiRequest.cs +++ b/Ombi.Api/ApiRequest.cs @@ -70,7 +70,7 @@ namespace Ombi.Api return response.Data; } - + public IRestResponse Execute(IRestRequest request, Uri baseUri) { var client = new RestClient { BaseUrl = baseUri }; diff --git a/Ombi.Api/NetflixRouletteApi.cs b/Ombi.Api/NetflixRouletteApi.cs index ee556a410..dc6e6e220 100644 --- a/Ombi.Api/NetflixRouletteApi.cs +++ b/Ombi.Api/NetflixRouletteApi.cs @@ -26,6 +26,7 @@ #endregion using System; +using System.Threading.Tasks; using Newtonsoft.Json; using Ombi.Api.Interfaces; using Ombi.Api.Models.Netflix; @@ -43,10 +44,10 @@ namespace Ombi.Api private IApiRequest Api { get; } private Uri Endpoint => new Uri("http://netflixroulette.net/api/api.php"); - public NetflixMovieResult GetMovies(string movieName, string year = null) + public NetflixMovieResult CheckNetflix(string title, string year = null) { var request = new RestRequest(); - request.AddQueryParameter("title", movieName); + request.AddQueryParameter("title", title); if (!string.IsNullOrEmpty(year)) { request.AddQueryParameter("year", year); diff --git a/Ombi.UI/Content/search.js b/Ombi.UI/Content/search.js index 674660b11..8b71215fb 100644 --- a/Ombi.UI/Content/search.js +++ b/Ombi.UI/Content/search.js @@ -304,6 +304,8 @@ $(function () { var html = searchTemplate(context); $("#movieList").append(html); + + checkNetflix(context.title, context.id); }); } else { @@ -334,6 +336,9 @@ $(function () { var context = buildTvShowContext(result); var html = searchTemplate(context); $("#tvList").append(html); + + checkNetflix(context.title, context.id); + }); } else { @@ -343,6 +348,19 @@ $(function () { }); }; + function checkNetflix(title, id) { + var url = createBaseUrl(base, '/searchextension/netflix/' + title); + $.ajax(url).success(function (results) { + + if (results.result) { + // It's on Netflix + $('#' + id + 'netflixTab') + .html("Avaialble on Netflix"); + } + + }); + } + function resetTvShows() { $("#tvList").html(""); } diff --git a/Ombi.UI/Modules/SearchExtensionModule.cs b/Ombi.UI/Modules/SearchExtensionModule.cs new file mode 100644 index 000000000..05fdfe003 --- /dev/null +++ b/Ombi.UI/Modules/SearchExtensionModule.cs @@ -0,0 +1,62 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: SearchExtensionModule.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.Threading.Tasks; +using Nancy; +using Ombi.Api.Interfaces; +using Ombi.Core; +using Ombi.Core.SettingModels; + +namespace Ombi.UI.Modules +{ + public class SearchExtensionModule : BaseAuthModule + { + public SearchExtensionModule(ISettingsService pr, ISecurityExtensions security, INetflixApi netflix) : base("searchextension",pr, security) + { + NetflixApi = netflix; + + Get["/netflix/{searchTerm}", true] = async (x, ctx) => await Netflix(x.searchTerm); + } + + private INetflixApi NetflixApi { get; } + + + public async Task Netflix(string title) + { + var result = NetflixApi.CheckNetflix(title); + + if (!string.IsNullOrEmpty(result.Message)) + { + return Response.AsJson(new { Result = false }); + } + + return Response.AsJson(new { Result = true }); + } + + + } +} \ No newline at end of file diff --git a/Ombi.UI/NinjectModules/ApiModule.cs b/Ombi.UI/NinjectModules/ApiModule.cs index 4dd37a8db..9926f30e3 100644 --- a/Ombi.UI/NinjectModules/ApiModule.cs +++ b/Ombi.UI/NinjectModules/ApiModule.cs @@ -46,6 +46,7 @@ namespace Ombi.UI.NinjectModules Bind().To(); Bind().To(); Bind().To(); + Bind().To(); } } } \ No newline at end of file diff --git a/Ombi.UI/Ombi.UI.csproj b/Ombi.UI/Ombi.UI.csproj index 38a6bdf40..d984e4562 100644 --- a/Ombi.UI/Ombi.UI.csproj +++ b/Ombi.UI/Ombi.UI.csproj @@ -273,6 +273,7 @@ + diff --git a/Ombi.UI/Views/Search/Index.cshtml b/Ombi.UI/Views/Search/Index.cshtml index 1ec29775f..59fc41464 100644 --- a/Ombi.UI/Views/Search/Index.cshtml +++ b/Ombi.UI/Views/Search/Index.cshtml @@ -107,7 +107,7 @@ } -