1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Optionally include season images when fetching series from API

Closes #464
This commit is contained in:
Mark McDowall 2018-01-13 15:00:40 -08:00
parent ee673cd152
commit 245bf6c7d6
5 changed files with 48 additions and 28 deletions

View File

@ -1,4 +1,4 @@
using System;
using System;
using Nancy;
namespace NzbDrone.Api.Extensions
@ -42,5 +42,17 @@ public static bool IsSharedContentRequest(this Request request)
return request.Path.StartsWith("/MediaCover/", StringComparison.InvariantCultureIgnoreCase) ||
request.Path.StartsWith("/Content/Images/", StringComparison.InvariantCultureIgnoreCase);
}
public static bool GetBooleanQueryParameter(this Request request, string parameter, bool defaultValue = false)
{
var parameterValue = request.Query[parameter];
if (parameterValue.HasValue)
{
return bool.Parse(parameterValue.Value);
}
return defaultValue;
}
}
}

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.Tv;
namespace NzbDrone.Api.Series
{
@ -8,18 +9,20 @@ public class SeasonResource
public int SeasonNumber { get; set; }
public bool Monitored { get; set; }
public SeasonStatisticsResource Statistics { get; set; }
public List<MediaCover> Images { get; set; }
}
public static class SeasonResourceMapper
{
public static SeasonResource ToResource(this Season model)
public static SeasonResource ToResource(this Season model, bool includeImages = false)
{
if (model == null) return null;
return new SeasonResource
{
SeasonNumber = model.SeasonNumber,
Monitored = model.Monitored
Monitored = model.Monitored,
Images = includeImages ? model.Images : null
};
}
@ -30,13 +33,14 @@ public static Season ToModel(this SeasonResource resource)
return new Season
{
SeasonNumber = resource.SeasonNumber,
Monitored = resource.Monitored
Monitored = resource.Monitored,
Images = resource.Images
};
}
public static List<SeasonResource> ToResource(this IEnumerable<Season> models)
public static List<SeasonResource> ToResource(this IEnumerable<Season> models, bool includeImages = false)
{
return models.Select(ToResource).ToList();
return models.Select(s => ToResource(s, includeImages)).ToList();
}
public static List<Season> ToModel(this IEnumerable<SeasonResource> resources)

View File

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Nancy;
using NzbDrone.Api.Extensions;
@ -24,7 +24,7 @@ private Response SaveAll()
var series = resources.Select(seriesResource => seriesResource.ToModel(_seriesService.GetSeries(seriesResource.Id))).ToList();
return _seriesService.UpdateSeries(series)
.ToResource()
.ToResource(false)
.AsResponse(HttpStatusCode.Accepted);
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using NzbDrone.Api.Extensions;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaCover;
@ -86,26 +87,17 @@ ProfileExistsValidator profileExistsValidator
private SeriesResource GetSeries(int id)
{
var includeSeasonImages = Request.GetBooleanQueryParameter("includeSeasonImages");
var series = _seriesService.GetSeries(id);
return MapToResource(series);
}
private SeriesResource MapToResource(Core.Tv.Series series)
{
if (series == null) return null;
var resource = series.ToResource();
MapCoversToLocal(resource);
FetchAndLinkSeriesStatistics(resource);
PopulateAlternateTitles(resource);
return resource;
return MapToResource(series, includeSeasonImages);
}
private List<SeriesResource> AllSeries()
{
var includeSeasonImages = Request.GetBooleanQueryParameter("includeSeasonImages");
var seriesStats = _seriesStatisticsService.SeriesStatistics();
var seriesResources = _seriesService.GetAllSeries().ToResource();
var seriesResources = _seriesService.GetAllSeries().Select(s => s.ToResource(includeSeasonImages)).ToList();
MapCoversToLocal(seriesResources.ToArray());
LinkSeriesStatistics(seriesResources, seriesStats);
@ -143,6 +135,18 @@ private void DeleteSeries(int id)
_seriesService.DeleteSeries(id, deleteFiles);
}
private SeriesResource MapToResource(Core.Tv.Series series, bool includeSeasonImages)
{
if (series == null) return null;
var resource = series.ToResource(includeSeasonImages);
MapCoversToLocal(resource);
FetchAndLinkSeriesStatistics(resource);
PopulateAlternateTitles(resource);
return resource;
}
private void MapCoversToLocal(params SeriesResource[] series)
{
foreach (var seriesResource in series)

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Api.REST;
@ -97,7 +97,7 @@ public int QualityProfileId
public static class SeriesResourceMapper
{
public static SeriesResource ToResource(this Core.Tv.Series model)
public static SeriesResource ToResource(this Core.Tv.Series model, bool includeSeasonImages = false)
{
if (model == null) return null;
@ -121,7 +121,7 @@ public static SeriesResource ToResource(this Core.Tv.Series model)
AirTime = model.AirTime,
Images = model.Images,
Seasons = model.Seasons.ToResource(),
Seasons = model.Seasons.ToResource(includeSeasonImages),
Year = model.Year,
Path = model.Path,
@ -214,9 +214,9 @@ public static Core.Tv.Series ToModel(this SeriesResource resource, Core.Tv.Serie
return series;
}
public static List<SeriesResource> ToResource(this IEnumerable<Core.Tv.Series> series)
public static List<SeriesResource> ToResource(this IEnumerable<Core.Tv.Series> series, bool includeSeasonImages)
{
return series.Select(ToResource).ToList();
return series.Select(s => ToResource(s, includeSeasonImages)).ToList();
}
}
}