Added a bit better error handling around the request builder when requesting TV shows

This commit is contained in:
tidusjar 2021-05-25 09:50:35 +01:00
parent 6b49e23a77
commit 1cb2431ed1

View file

@ -12,16 +12,19 @@ using Ombi.Helpers;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests; using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository.Requests; using Ombi.Store.Repository.Requests;
using Microsoft.Extensions.Logging;
namespace Ombi.Core.Helpers namespace Ombi.Core.Helpers
{ {
public class TvShowRequestBuilder public class TvShowRequestBuilder
{ {
private readonly ILogger _logger;
public TvShowRequestBuilder(ITvMazeApi tvApi, IMovieDbApi movApi) public TvShowRequestBuilder(ITvMazeApi tvApi, IMovieDbApi movApi, ILogger<TvShowRequestBuilder> logger)
{ {
TvApi = tvApi; TvApi = tvApi;
MovieDbApi = movApi; MovieDbApi = movApi;
_logger = logger;
} }
private ITvMazeApi TvApi { get; } private ITvMazeApi TvApi { get; }
@ -45,6 +48,7 @@ namespace Ombi.Core.Helpers
{ {
if (result.Name.Equals(ShowInfo.name, StringComparison.InvariantCultureIgnoreCase)) if (result.Name.Equals(ShowInfo.name, StringComparison.InvariantCultureIgnoreCase))
{ {
_logger.LogInformation($"Found matching MovieDb entry for show name {ShowInfo.name}");
TheMovieDbRecord = result; TheMovieDbRecord = result;
var showIds = await MovieDbApi.GetTvExternals(result.Id); var showIds = await MovieDbApi.GetTvExternals(result.Id);
ShowInfo.externals.imdb = showIds.imdb_id; ShowInfo.externals.imdb = showIds.imdb_id;
@ -237,18 +241,19 @@ namespace Ombi.Core.Helpers
public TvShowRequestBuilder CreateNewRequest(TvRequestViewModel tv) public TvShowRequestBuilder CreateNewRequest(TvRequestViewModel tv)
{ {
_logger.LogInformation($"Building Request for {ShowInfo.name} with Provider ID {TheMovieDbRecord?.Id ?? 0}");
NewRequest = new TvRequests NewRequest = new TvRequests
{ {
Overview = ShowInfo.summary.RemoveHtml(), Overview = ShowInfo.summary.RemoveHtml(),
PosterPath = PosterPath, PosterPath = PosterPath,
Title = ShowInfo.name, Title = ShowInfo.name,
ReleaseDate = FirstAir, ReleaseDate = FirstAir,
ExternalProviderId = TheMovieDbRecord.Id, ExternalProviderId = TheMovieDbRecord?.Id ?? 0,
Status = ShowInfo.status, Status = ShowInfo.status,
ImdbId = ShowInfo.externals?.imdb ?? string.Empty, ImdbId = ShowInfo.externals?.imdb ?? string.Empty,
TvDbId = tv.TvDbId, TvDbId = tv.TvDbId,
ChildRequests = new List<ChildRequests>(), ChildRequests = new List<ChildRequests>(),
TotalSeasons = tv.Seasons.Count(), TotalSeasons = tv.Seasons?.Count ?? 0,
Background = BackdropPath Background = BackdropPath
}; };
NewRequest.ChildRequests.Add(ChildRequest); NewRequest.ChildRequests.Add(ChildRequest);