Added the code to lookup the old requests and refresh them with new information from TVMaze

pull/42/head
tidusjar 9 years ago
parent a2d2121afe
commit 4136116555

@ -69,5 +69,18 @@ namespace PlexRequests.Api
return Api.Execute<TvMazeShow>(request, new Uri(Uri)); return Api.Execute<TvMazeShow>(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<TvMazeShow>(request, new Uri(Uri));
}
} }
} }

@ -94,6 +94,10 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PlexRequests.Api.Models\PlexRequests.Api.Models.csproj">
<Project>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</Project>
<Name>PlexRequests.Api.Models</Name>
</ProjectReference>
<ProjectReference Include="..\PlexRequests.Api\PlexRequests.Api.csproj"> <ProjectReference Include="..\PlexRequests.Api\PlexRequests.Api.csproj">
<Project>{8CB8D235-2674-442D-9C6A-35FCAEEB160D}</Project> <Project>{8CB8D235-2674-442D-9C6A-35FCAEEB160D}</Project>
<Name>PlexRequests.Api</Name> <Name>PlexRequests.Api</Name>

@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Mono.Data.Sqlite; using Mono.Data.Sqlite;
using PlexRequests.Api;
using PlexRequests.Core.SettingModels; using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers; using PlexRequests.Helpers;
using PlexRequests.Store; 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 // There is no requested table so they do not have an old version of the DB
return; return;
} }
if (!requestedModels.Any()) if (!requestedModels.Any())
{ return; } { return; }
var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); 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); result.Add(id);
} }

Loading…
Cancel
Save