Improved the search UI and made it more consistant.

Finished the Netflix API Part #884
pull/946/head
Jamie.Rees 8 years ago
parent 18b12f1a97
commit 88c0651b1e

@ -31,6 +31,6 @@ namespace Ombi.Api.Interfaces
{ {
public interface INetflixApi public interface INetflixApi
{ {
NetflixMovieResult GetMovies(string movieName, string year = null); NetflixMovieResult CheckNetflix(string title, string year = null);
} }
} }

@ -58,5 +58,12 @@ namespace Ombi.Api.Models.Netflix
public string Mediatype { get; set; } public string Mediatype { get; set; }
[JsonProperty(PropertyName = "runtime")] [JsonProperty(PropertyName = "runtime")]
public string Runtime { get; set; } public string Runtime { get; set; }
// For errors
[JsonProperty(PropertyName = "errorcode")]
public int ErrorCode { get; set; }
[JsonProperty(PropertyName = "message")]
public string Message { get; set; }
} }
} }

@ -70,7 +70,7 @@ namespace Ombi.Api
return response.Data; return response.Data;
} }
public IRestResponse Execute(IRestRequest request, Uri baseUri) public IRestResponse Execute(IRestRequest request, Uri baseUri)
{ {
var client = new RestClient { BaseUrl = baseUri }; var client = new RestClient { BaseUrl = baseUri };

@ -26,6 +26,7 @@
#endregion #endregion
using System; using System;
using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ombi.Api.Interfaces; using Ombi.Api.Interfaces;
using Ombi.Api.Models.Netflix; using Ombi.Api.Models.Netflix;
@ -43,10 +44,10 @@ namespace Ombi.Api
private IApiRequest Api { get; } private IApiRequest Api { get; }
private Uri Endpoint => new Uri("http://netflixroulette.net/api/api.php"); 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(); var request = new RestRequest();
request.AddQueryParameter("title", movieName); request.AddQueryParameter("title", title);
if (!string.IsNullOrEmpty(year)) if (!string.IsNullOrEmpty(year))
{ {
request.AddQueryParameter("year", year); request.AddQueryParameter("year", year);

@ -304,6 +304,8 @@ $(function () {
var html = searchTemplate(context); var html = searchTemplate(context);
$("#movieList").append(html); $("#movieList").append(html);
checkNetflix(context.title, context.id);
}); });
} }
else { else {
@ -334,6 +336,9 @@ $(function () {
var context = buildTvShowContext(result); var context = buildTvShowContext(result);
var html = searchTemplate(context); var html = searchTemplate(context);
$("#tvList").append(html); $("#tvList").append(html);
checkNetflix(context.title, context.id);
}); });
} }
else { 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("<span class='label label-success'>Avaialble on Netflix</span>");
}
});
}
function resetTvShows() { function resetTvShows() {
$("#tvList").html(""); $("#tvList").html("");
} }

@ -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<PlexRequestSettings> 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<Response> 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 });
}
}
}

@ -46,6 +46,7 @@ namespace Ombi.UI.NinjectModules
Bind<ISlackApi>().To<SlackApi>(); Bind<ISlackApi>().To<SlackApi>();
Bind<IApiRequest>().To<ApiRequest>(); Bind<IApiRequest>().To<ApiRequest>();
Bind<IWatcherApi>().To<WatcherApi>(); Bind<IWatcherApi>().To<WatcherApi>();
Bind<INetflixApi>().To<NetflixRouletteApi>();
} }
} }
} }

@ -273,6 +273,7 @@
<Compile Include="Modules\IssuesModule.cs" /> <Compile Include="Modules\IssuesModule.cs" />
<Compile Include="Modules\LandingPageModule.cs" /> <Compile Include="Modules\LandingPageModule.cs" />
<Compile Include="Modules\LayoutModule.cs" /> <Compile Include="Modules\LayoutModule.cs" />
<Compile Include="Modules\SearchExtensionModule.cs" />
<Compile Include="Modules\UserWizardModule.cs" /> <Compile Include="Modules\UserWizardModule.cs" />
<Compile Include="NinjectModules\ApiModule.cs" /> <Compile Include="NinjectModules\ApiModule.cs" />
<Compile Include="NinjectModules\ConfigurationModule.cs" /> <Compile Include="NinjectModules\ConfigurationModule.cs" />

@ -107,7 +107,7 @@
} }
<!-- Movie and TV Results template --> <!-- Movie and TV Results template -->
<script id="search-template" type="text/x-handlebars-template"> <script id="search-template" type="text/x-handlebars-template">
<div class="row"> <div class="row">
<div class="col-sm-2"> <div class="col-sm-2">
@ -134,7 +134,6 @@
<h4>{{title}} ({{year}})</h4> <h4>{{title}} ({{year}})</h4>
</a> </a>
{{/if_eq}} {{/if_eq}}
{{#if_eq type "tv"}}
{{#if available}} {{#if available}}
<span class="label label-success">@UI.Search_Available_on_plex</span> <span class="label label-success">@UI.Search_Available_on_plex</span>
{{else}} {{else}}
@ -146,9 +145,11 @@
<span class="label label-danger">@UI.Search_Not_Requested_Yet</span> <span class="label label-danger">@UI.Search_Not_Requested_Yet</span>
{{/if}} {{/if}}
{{/if}} {{/if}}
<span id="{{id}}netflixTab"></span>
<br /> <br />
<br /> <br />
{{/if_eq}}
</div> </div>
<p>{{overview}}</p> <p>{{overview}}</p>
</div> </div>

Loading…
Cancel
Save