From 4136116555bef6ba4332d220c10a802ad4f5279a Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 18 Mar 2016 23:45:31 +0000 Subject: [PATCH] Added the code to lookup the old requests and refresh them with new information from TVMaze --- PlexRequests.Api/TvMazeApi.cs | 13 ++++++++++ PlexRequests.Core/PlexRequests.Core.csproj | 4 +++ PlexRequests.Core/Setup.cs | 29 ++++++++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/PlexRequests.Api/TvMazeApi.cs b/PlexRequests.Api/TvMazeApi.cs index 5f74ea7f2..8b6cb9f37 100644 --- a/PlexRequests.Api/TvMazeApi.cs +++ b/PlexRequests.Api/TvMazeApi.cs @@ -69,5 +69,18 @@ namespace PlexRequests.Api return Api.Execute(request, new Uri(Uri)); } + public TvMazeShow ShowLookupByTheTvDbId(int theTvDbId) + { + var request = new RestRequest + { + Method = Method.GET, + Resource = "lookup/shows?thetvdb={id}" + }; + request.AddUrlSegment("id", theTvDbId.ToString()); + request.AddHeader("Content-Type", "application/json"); + + return Api.Execute(request, new Uri(Uri)); + } + } } \ No newline at end of file diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index b7534d1b0..e1c4ee1f3 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -94,6 +94,10 @@ + + {CB37A5F8-6DFC-4554-99D3-A42B502E4591} + PlexRequests.Api.Models + {8CB8D235-2674-442D-9C6A-35FCAEEB160D} PlexRequests.Api diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index 4486df9fb..7cab60066 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Linq; using Mono.Data.Sqlite; +using PlexRequests.Api; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers; using PlexRequests.Store; @@ -85,14 +86,38 @@ namespace PlexRequests.Core // There is no requested table so they do not have an old version of the DB return; } + if (!requestedModels.Any()) { return; } var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); - foreach (var r in requestedModels) + var api = new TvMazeApi(); + + foreach (var r in requestedModels.Where(x => x.Type == RequestType.TvShow)) { - var id = jsonRepo.AddRequest(r); + var show = api.ShowLookupByTheTvDbId(r.ProviderId); + + var model = new RequestedModel + { + Title = show.name, + PosterPath = show.image?.medium, + Type = RequestType.TvShow, + ProviderId = show.externals.thetvdb ?? 0, + ReleaseDate = r.ReleaseDate, + AdminNote = r.AdminNote, + Approved = r.Approved, + Available = r.Available, + ImdbId = show.externals.imdb, + Issues = r.Issues, + LatestTv = r.LatestTv, + OtherMessage = r.OtherMessage, + Overview = show.summary.RemoveHtml(), + RequestedBy = r.RequestedBy, + RequestedDate = r.ReleaseDate, + Status = show.status + }; + var id = jsonRepo.AddRequest(model); result.Add(id); }