From b1d7a3187e6f84d94cb3b83665bdd345fa46e64c Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 18 Mar 2016 17:15:13 +0000 Subject: [PATCH 1/5] Update StatusCheckerTests.cs --- PlexRequests.Core.Tests/StatusCheckerTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PlexRequests.Core.Tests/StatusCheckerTests.cs b/PlexRequests.Core.Tests/StatusCheckerTests.cs index e45b4dcab..da0dd44d7 100644 --- a/PlexRequests.Core.Tests/StatusCheckerTests.cs +++ b/PlexRequests.Core.Tests/StatusCheckerTests.cs @@ -34,6 +34,7 @@ namespace PlexRequests.Core.Tests public class StatusCheckerTests { [Test] + [Ignore("API Limit")] public void CheckStatusTest() { var checker = new StatusChecker(); @@ -42,4 +43,4 @@ namespace PlexRequests.Core.Tests Assert.That(status, Is.Not.Null); } } -} \ No newline at end of file +} From f88c7d7583b0135063503c9014d511ddb524d67b Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Fri, 18 Mar 2016 21:10:01 +0000 Subject: [PATCH 2/5] Almost fully integrated TVMaze #21 and also improved the fix for #31 --- .../PlexRequests.Api.Models.csproj | 1 + PlexRequests.Api.Models/Tv/TVMazeShow.cs | 27 ++++++++++++++++ PlexRequests.Api/TvMazeApi.cs | 13 ++++++++ PlexRequests.Api/TvMazeBase.cs | 2 +- .../Interfaces/IAvailabilityChecker.cs | 2 +- .../PlexAvailabilityChecker.cs | 7 +++-- PlexRequests.UI/Modules/RequestsModule.cs | 2 +- PlexRequests.UI/Modules/SearchModule.cs | 31 +++++++++---------- PlexRequests.UI/Views/Requests/Index.cshtml | 2 +- 9 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 PlexRequests.Api.Models/Tv/TVMazeShow.cs diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index fee0b033c..402cdd22a 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -61,6 +61,7 @@ + diff --git a/PlexRequests.Api.Models/Tv/TVMazeShow.cs b/PlexRequests.Api.Models/Tv/TVMazeShow.cs new file mode 100644 index 000000000..165658602 --- /dev/null +++ b/PlexRequests.Api.Models/Tv/TVMazeShow.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace PlexRequests.Api.Models.Tv +{ + public class TvMazeShow + { + public int id { get; set; } + public string url { get; set; } + public string name { get; set; } + public string type { get; set; } + public string language { get; set; } + public List genres { get; set; } + public string status { get; set; } + public int runtime { get; set; } + public string premiered { get; set; } + public Schedule schedule { get; set; } + public Rating rating { get; set; } + public int weight { get; set; } + public Network network { get; set; } + public object webChannel { get; set; } + public Externals externals { get; set; } + public Image image { get; set; } + public string summary { get; set; } + public int updated { get; set; } + public Links _links { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api/TvMazeApi.cs b/PlexRequests.Api/TvMazeApi.cs index 6af8c51a2..5f74ea7f2 100644 --- a/PlexRequests.Api/TvMazeApi.cs +++ b/PlexRequests.Api/TvMazeApi.cs @@ -56,5 +56,18 @@ namespace PlexRequests.Api return Api.Execute>(request, new Uri(Uri)); } + public TvMazeShow ShowLookup(int showId) + { + var request = new RestRequest + { + Method = Method.GET, + Resource = "shows/{id}" + }; + request.AddUrlSegment("id", showId.ToString()); + request.AddHeader("Content-Type", "application/json"); + + return Api.Execute(request, new Uri(Uri)); + } + } } \ No newline at end of file diff --git a/PlexRequests.Api/TvMazeBase.cs b/PlexRequests.Api/TvMazeBase.cs index 1526603bc..d4eddefee 100644 --- a/PlexRequests.Api/TvMazeBase.cs +++ b/PlexRequests.Api/TvMazeBase.cs @@ -28,6 +28,6 @@ namespace PlexRequests.Api { public class TvMazeBase { - public string Uri = "http://api.tvmaze.com"; + protected string Uri = "http://api.tvmaze.com"; } } \ No newline at end of file diff --git a/PlexRequests.Services/Interfaces/IAvailabilityChecker.cs b/PlexRequests.Services/Interfaces/IAvailabilityChecker.cs index 41185118e..02d8e8d57 100644 --- a/PlexRequests.Services/Interfaces/IAvailabilityChecker.cs +++ b/PlexRequests.Services/Interfaces/IAvailabilityChecker.cs @@ -29,6 +29,6 @@ namespace PlexRequests.Services.Interfaces public interface IAvailabilityChecker { void CheckAndUpdateAll(long check); - bool IsAvailable(string title); + bool IsAvailable(string title, string year); } } \ No newline at end of file diff --git a/PlexRequests.Services/PlexAvailabilityChecker.cs b/PlexRequests.Services/PlexAvailabilityChecker.cs index d450e364d..999c7d697 100644 --- a/PlexRequests.Services/PlexAvailabilityChecker.cs +++ b/PlexRequests.Services/PlexAvailabilityChecker.cs @@ -85,9 +85,10 @@ namespace PlexRequests.Services /// Determines whether the specified search term is available. /// /// The search term. + /// The year. /// /// The settings are not configured for Plex or Authentication - public bool IsAvailable(string title) + public bool IsAvailable(string title, string year) { var plexSettings = Plex.GetSettings(); var authSettings = Auth.GetSettings(); @@ -98,8 +99,8 @@ namespace PlexRequests.Services } var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri); - var result = results.Video?.FirstOrDefault(x => x.Title == title); - var directoryTitle = results.Directory?.Title == title; + var result = results.Video?.FirstOrDefault(x => x.Title == title && x.Year == year); + var directoryTitle = results.Directory?.Title == title && results.Directory?.Year == year; return result?.Title != null || directoryTitle; } diff --git a/PlexRequests.UI/Modules/RequestsModule.cs b/PlexRequests.UI/Modules/RequestsModule.cs index 6b06f657d..4f534e0b9 100644 --- a/PlexRequests.UI/Modules/RequestsModule.cs +++ b/PlexRequests.UI/Modules/RequestsModule.cs @@ -114,7 +114,7 @@ namespace PlexRequests.UI.Modules Status = tv.Status, ImdbId = tv.ImdbId, Id = tv.Id, - PosterPath = tv.ProviderId.ToString(), + PosterPath = tv.PosterPath, 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 e39adca21..c406daf1e 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -126,8 +126,8 @@ namespace PlexRequests.UI.Modules FirstAired = t.show.premiered, Id = t.show.id, ImdbId = t.show.externals?.imdb, - Network = t.show.network.name, - NetworkId = t.show.network.id.ToString(), + Network = t.show.network?.name, + NetworkId = t.show.network?.id.ToString(), Overview = t.show.summary, Rating = t.score.ToString(CultureInfo.CurrentUICulture), Runtime = t.show.runtime.ToString(), @@ -186,12 +186,12 @@ namespace PlexRequests.UI.Modules Log.Trace("Getting movie info from TheMovieDb"); Log.Trace(movieInfo.DumpJson); -#if !DEBUG - if (CheckIfTitleExistsInPlex(movieInfo.Title)) +//#if !DEBUG + if (CheckIfTitleExistsInPlex(movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString())) { return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{movieInfo.Title} is already in Plex!" }); } -#endif +//#endif var model = new RequestedModel { @@ -258,28 +258,27 @@ namespace PlexRequests.UI.Modules return Response.AsJson(new JsonResponseModel { Result = false, Message = "TV Show has already been requested!" }); } - var tvApi = new TheTvDbApi(); - var token = GetTvDbAuthToken(tvApi); + var tvApi = new TvMazeApi(); - var showInfo = tvApi.GetInformation(showId, token).data; + var showInfo = tvApi.ShowLookup(showId); //#if !DEBUG - if (CheckIfTitleExistsInPlex(showInfo.seriesName)) + if (CheckIfTitleExistsInPlex(showInfo.name, showInfo.premiered.Substring(0,4))) // Take only the year Format = 2014-01-01 { - return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{showInfo.seriesName} is already in Plex!" }); + return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{showInfo.name} is already in Plex!" }); } //#endif DateTime firstAir; - DateTime.TryParse(showInfo.firstAired, out firstAir); + DateTime.TryParse(showInfo.premiered, out firstAir); var model = new RequestedModel { ProviderId = showInfo.id, Type = RequestType.TvShow, - Overview = showInfo.overview, - PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo.banner, // This is incorrect - Title = showInfo.seriesName, + Overview = showInfo.summary, + PosterPath = showInfo.image?.medium, + Title = showInfo.name, ReleaseDate = firstAir, Status = showInfo.status, RequestedDate = DateTime.Now, @@ -320,9 +319,9 @@ namespace PlexRequests.UI.Modules return Cache.GetOrSet(CacheKeys.TvDbToken, api.Authenticate, 50); } - private bool CheckIfTitleExistsInPlex(string title) + private bool CheckIfTitleExistsInPlex(string title, string year) { - var result = Checker.IsAvailable(title); + var result = Checker.IsAvailable(title, year); return result; } } diff --git a/PlexRequests.UI/Views/Requests/Index.cshtml b/PlexRequests.UI/Views/Requests/Index.cshtml index 5181b38c0..c33e71b5e 100644 --- a/PlexRequests.UI/Views/Requests/Index.cshtml +++ b/PlexRequests.UI/Views/Requests/Index.cshtml @@ -62,7 +62,7 @@ {{/if_eq}} {{#if_eq type "tv"}} {{#if posterPath}} - poster + poster {{/if}} {{/if_eq}} From 87baf542c584822b63b1b01a57bb23dd4c673e2d Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Fri, 18 Mar 2016 21:12:44 +0000 Subject: [PATCH 3/5] Fixed tests --- .../PlexAvailabilityCheckerTests.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs index 0a1a157c0..117157927 100644 --- a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -55,7 +55,7 @@ namespace PlexRequests.Services.Tests var plexMock = new Mock(); Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object); - Assert.Throws(() => Checker.IsAvailable("title"), "We should be throwing an exception since we cannot talk to the services."); + Assert.Throws(() => Checker.IsAvailable("title", "2013"), "We should be throwing an exception since we cannot talk to the services."); } [Test] @@ -66,7 +66,7 @@ namespace PlexRequests.Services.Tests var requestMock = new Mock(); var plexMock = new Mock(); - var searchResult = new PlexSearch {Video = new List