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}}