diff --git a/PlexRequests.Api/Models/Tv/TvShow.cs b/PlexRequests.Api/Models/Tv/TvShow.cs index 5de2d5aa0..84cb69fb9 100644 --- a/PlexRequests.Api/Models/Tv/TvShow.cs +++ b/PlexRequests.Api/Models/Tv/TvShow.cs @@ -34,7 +34,7 @@ namespace PlexRequests.Api.Models.Tv public string seriesName { get; set; } public List aliases { get; set; } public string banner { get; set; } - public int seriesId { get; set; } + public string seriesId { get; set; } public string status { get; set; } public string firstAired { get; set; } public string network { get; set; } @@ -49,7 +49,13 @@ namespace PlexRequests.Api.Models.Tv public string imdbId { get; set; } public string zap2itId { get; set; } public string added { get; set; } + public int addedBy { get; set; } public int siteRating { get; set; } } + + public class TvShowInformation + { + public TvShow data { get; set; } + } } diff --git a/PlexRequests.Api/Models/Tv/TvShowImages.cs b/PlexRequests.Api/Models/Tv/TvShowImages.cs new file mode 100644 index 000000000..6d9d4387b --- /dev/null +++ b/PlexRequests.Api/Models/Tv/TvShowImages.cs @@ -0,0 +1,54 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: TvShowImages.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.Collections.Generic; + +namespace PlexRequests.Api.Models.Tv +{ + public class RatingsInfo + { + public double average { get; set; } + } + + public class Datum + { + public int id { get; set; } + public string keyType { get; set; } + public string subKey { get; set; } + public string fileName { get; set; } + public string resolution { get; set; } + public RatingsInfo ratingsInfo { get; set; } + public string thumbnail { get; set; } + } + + public class TvShowImages + { + public List data { get; set; } + public object errors { get; set; } + } + +} \ No newline at end of file diff --git a/PlexRequests.Api/PlexRequests.Api.csproj b/PlexRequests.Api/PlexRequests.Api.csproj index 7fbe562ae..7c3aaae4d 100644 --- a/PlexRequests.Api/PlexRequests.Api.csproj +++ b/PlexRequests.Api/PlexRequests.Api.csproj @@ -67,6 +67,7 @@ + diff --git a/PlexRequests.Api/TheTvDbApi.cs b/PlexRequests.Api/TheTvDbApi.cs index ca361c50d..50c94e7d9 100644 --- a/PlexRequests.Api/TheTvDbApi.cs +++ b/PlexRequests.Api/TheTvDbApi.cs @@ -97,6 +97,26 @@ namespace PlexRequests.Api return Api.Execute(request, Url); } + /// + /// Gets the tv images. + /// + /// The series identifier. + /// The token. + /// + public TvShowImages GetTvImages(int seriesId, string token) + { + var request = new RestRequest + { + Method = Method.GET, + Resource = "/series/{id}/images/query?keyType=poster" + }; + request.AddUrlSegment("id", seriesId.ToString()); + request.AddHeader("Authorization", $"Bearer {token}"); + request.AddHeader("Content-Type", "application/json"); + + return Api.Execute(request, Url); + } + /// /// Gets the information for a TV Series. @@ -104,18 +124,18 @@ namespace PlexRequests.Api /// The TVDB identifier. /// The token. /// - public TvShow GetInformation(int tvdbId, string token) + public TvShowInformation GetInformation(int tvdbId, string token) { var request = new RestRequest { Method = Method.GET, - Resource = "search/{id}" + Resource = "series/{id}" }; request.AddUrlSegment("id", tvdbId.ToString()); request.AddHeader("Authorization", $"Bearer {token}"); request.AddHeader("Content-Type", "application/json"); - return Api.Execute(request, Url); + return Api.Execute(request, Url); } } } diff --git a/PlexRequests.Core/SettingsService.cs b/PlexRequests.Core/SettingsService.cs index 720ced03d..c2e9ec413 100644 --- a/PlexRequests.Core/SettingsService.cs +++ b/PlexRequests.Core/SettingsService.cs @@ -37,9 +37,14 @@ namespace PlexRequests.Core { public class SettingsService { + public SettingsService(ICacheProvider cache) + { + Cache = cache; + } - public SettingsModel GetSettings(ICacheProvider cache) + public SettingsModel GetSettings() { + var db = new DbConfiguration(new SqliteFactory()); var repo = new GenericRepository(db); @@ -77,7 +82,7 @@ namespace PlexRequests.Core var tvApi = new TheTvDbApi(); var token = GetAuthToken(tvApi); - var showInfo = tvApi.GetInformation(providerId, token); + var showInfo = tvApi.GetInformation(providerId, token).data; DateTime firstAir; DateTime.TryParse(showInfo.firstAired, out firstAir); diff --git a/PlexRequests.UI/Content/search.js b/PlexRequests.UI/Content/search.js index e84af8e68..99c6f23b1 100644 --- a/PlexRequests.UI/Content/search.js +++ b/PlexRequests.UI/Content/search.js @@ -85,12 +85,14 @@ function movieSearch() { var query = $("#movieSearchContent").val(); $.ajax("/search/movie/" + query).success(function (results) { - results.forEach(function (result) { - var context = buildMovieContext(result); + if (results.length > 0) { + results.forEach(function(result) { + var context = buildMovieContext(result); - var html = searchTemplate(context); - $("#movieList").append(html); - }); + var html = searchTemplate(context); + $("#movieList").append(html); + }); + } }); }; @@ -99,12 +101,13 @@ function tvSearch() { var query = $("#tvSearchContent").val(); $.ajax("/search/tv/" + query).success(function (results) { - - results.data.forEach(function (result) { - var context = buildTvShowContext(result); - var html = searchTemplate(context); - $("#tvList").append(html); - }); + if (results.length > 0) { + results.forEach(function(result) { + var context = buildTvShowContext(result); + var html = searchTemplate(context); + $("#tvList").append(html); + }); + } }); }; diff --git a/PlexRequests.UI/Content/site.js b/PlexRequests.UI/Content/site.js index 5c0cbb340..5e363905b 100644 --- a/PlexRequests.UI/Content/site.js +++ b/PlexRequests.UI/Content/site.js @@ -30,12 +30,10 @@ function buildTvShowContext(result) { var date = new Date(result.firstAired); var year = date.getFullYear(); var context = { - posterPath: result.posterPath, + posterPath: result.banner, id: result.id, - title: result.name, + title: result.seriesName, overview: result.overview, - voteCount: result.voteCount, - voteAverage: result.voteAverage, year: year, type: "tv" }; diff --git a/PlexRequests.UI/Models/RequestViewModel.cs b/PlexRequests.UI/Models/RequestViewModel.cs index 2958ea5a5..30eb2ced4 100644 --- a/PlexRequests.UI/Models/RequestViewModel.cs +++ b/PlexRequests.UI/Models/RequestViewModel.cs @@ -31,7 +31,7 @@ namespace PlexRequests.UI.Models public class RequestViewModel { public int Id { get; set; } - public int Tmdbid { get; set; } + public int ProviderId { get; set; } public string ImdbId { get; set; } public string Overview { get; set; } public string Title { get; set; } diff --git a/PlexRequests.UI/Models/SearchTvShowViewModel.cs b/PlexRequests.UI/Models/SearchTvShowViewModel.cs new file mode 100644 index 000000000..8e31193fc --- /dev/null +++ b/PlexRequests.UI/Models/SearchTvShowViewModel.cs @@ -0,0 +1,55 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SearchTvShowViewModel.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.Collections.Generic; + +namespace PlexRequests.UI.Models +{ + public class SearchTvShowViewModel + { + public int Id { get; set; } + public string SeriesName { get; set; } + public List Aliases { get; set; } + public string Banner { get; set; } + public int SeriesId { get; set; } + public string Status { get; set; } + public string FirstAired { get; set; } + public string Network { get; set; } + public string NetworkId { get; set; } + public string Runtime { get; set; } + public List Genre { get; set; } + public string Overview { get; set; } + public int LastUpdated { get; set; } + public string AirsDayOfWeek { get; set; } + public string AirsTime { get; set; } + public string Rating { get; set; } + public string ImdbId { get; set; } + public string Zap2ItId { get; set; } + public string Added { get; set; } + public int SiteRating { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Modules/RequestsModule.cs b/PlexRequests.UI/Modules/RequestsModule.cs index 88f0c158f..bfe61b86d 100644 --- a/PlexRequests.UI/Modules/RequestsModule.cs +++ b/PlexRequests.UI/Modules/RequestsModule.cs @@ -64,7 +64,7 @@ namespace PlexRequests.UI.Modules var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie); var viewModel = dbMovies.Select(tv => new RequestViewModel { - Tmdbid = tv.ProviderId, + ProviderId = tv.ProviderId, Type = tv.Type, Status = tv.Status, ImdbId = tv.ImdbId, @@ -87,12 +87,12 @@ namespace PlexRequests.UI.Modules var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow); var viewModel = dbTv.Select(tv => new RequestViewModel { - Tmdbid = tv.ProviderId, + ProviderId = tv.ProviderId, Type = tv.Type, Status = tv.Status, ImdbId = tv.ImdbId, Id = tv.Id, - PosterPath = tv.PosterPath, + PosterPath = tv.ProviderId.ToString(), ReleaseDate = tv.ReleaseDate.Humanize(), RequestedDate = tv.RequestedDate.Humanize(), Approved = tv.Approved, diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index cc32ff19c..b8c629c99 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -24,6 +24,9 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion + +using System.Collections.Generic; +using System.Linq; using Nancy; using Nancy.Responses.Negotiation; @@ -31,6 +34,7 @@ using PlexRequests.Api; using PlexRequests.Core; using PlexRequests.Helpers; using PlexRequests.Store; +using PlexRequests.UI.Models; namespace PlexRequests.UI.Modules { @@ -73,7 +77,42 @@ namespace PlexRequests.UI.Modules private Response SearchTvShow(string searchTerm) { var tvShow = TvApi.SearchTv(searchTerm, AuthToken); - return Response.AsJson(tvShow); + + if (tvShow?.data == null) + { + return Response.AsJson(""); + } + var model = new List(); + + foreach (var t in tvShow.data) + { + model.Add(new SearchTvShowViewModel + { + Added = t.added, + AirsDayOfWeek = t.airsDayOfWeek, + AirsTime = t.airsTime, + Aliases = t.aliases, + // We are constructing the banner with the id: + // http://thetvdb.com/banners/_cache/posters/ID-1.jpg + Banner = t.id.ToString(), + FirstAired = t.firstAired, + Genre = t.genre, + Id = t.id, + ImdbId = t.imdbId, + LastUpdated = t.lastUpdated, + Network = t.network, + NetworkId = t.networkId, + Overview = t.overview, + Rating = t.rating, + Runtime = t.runtime, + SeriesId = t.id, + SeriesName = t.seriesName, + SiteRating = t.siteRating, + Status = t.status, + Zap2ItId = t.zap2itId + }); + } + return Response.AsJson(model); } private Response UpcomingMovies() @@ -92,7 +131,7 @@ namespace PlexRequests.UI.Modules private Response RequestMovie(int movieId) { - var s = new SettingsService(); + var s = new SettingsService(Cache); if (s.CheckRequest(movieId)) { return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" }); @@ -111,7 +150,7 @@ namespace PlexRequests.UI.Modules private Response RequestTvShow(int showId, bool latest) { // Latest send to Sonarr and no need to store in DB - var s = new SettingsService(); + var s = new SettingsService(Cache); if (s.CheckRequest(showId)) { return Response.AsJson(new { Result = false, Message = "TV Show has already been requested!" }); diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 8ed8771f6..a9fabc669 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -142,6 +142,7 @@ + diff --git a/PlexRequests.UI/Views/Requests/Index.cshtml b/PlexRequests.UI/Views/Requests/Index.cshtml index 558c2e8da..64c111034 100644 --- a/PlexRequests.UI/Views/Requests/Index.cshtml +++ b/PlexRequests.UI/Views/Requests/Index.cshtml @@ -37,9 +37,16 @@
+ {{#if_eq type "movie"}} {{#if posterPath}} poster {{/if}} + {{/if_eq}} + {{#if_eq type "tv"}} + {{#if posterPath}} + poster + {{/if}} + {{/if_eq}}
diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index 7014fbe66..03c8ea86d 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -48,9 +48,18 @@