From b010faa85b59e24d7ae2e9056c8ebccc4ce2425b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 4 Jun 2013 21:19:25 -0400 Subject: [PATCH] fixes #324 - Server to return non-cropped images to clients --- MediaBrowser.Api/Images/ImageRequest.cs | 3 +++ MediaBrowser.Api/Images/ImageService.cs | 9 ++++++--- MediaBrowser.Api/Images/ImageWriter.cs | 15 +++++++++------ MediaBrowser.Controller/Entities/TV/Episode.cs | 6 ++---- MediaBrowser.Model/DTO/ImageOptions.cs | 6 ++++++ 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/MediaBrowser.Api/Images/ImageRequest.cs b/MediaBrowser.Api/Images/ImageRequest.cs index 1c11f527d6..3ea86e01cc 100644 --- a/MediaBrowser.Api/Images/ImageRequest.cs +++ b/MediaBrowser.Api/Images/ImageRequest.cs @@ -45,6 +45,9 @@ namespace MediaBrowser.Api.Images /// The tag. [ApiMember(Name = "Tag", Description = "Optional. Supply the cache tag from the item object to receive strong caching headers.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string Tag { get; set; } + + [ApiMember(Name = "CropWhitespace", Description = "Specify if whitespace should be cropped out of the image. True/False. If unspecified, whitespace will be cropped from logos and clear art.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public bool? CropWhitespace { get; set; } } /// diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index 967c449c29..24fda11fc4 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -691,11 +691,14 @@ namespace MediaBrowser.Api.Images cacheDuration = TimeSpan.FromDays(365); } + // Avoid implicitly captured closure + var currentItem = item; + var currentRequest = request; + return ToCachedResult(cacheGuid, originalFileImageDateModified, cacheDuration, () => new ImageWriter { - Item = item, - Request = request, - CropWhiteSpace = request.Type == ImageType.Logo || request.Type == ImageType.Art, + Item = currentItem, + Request = currentRequest, OriginalImageDateModified = originalFileImageDateModified, Enhancers = supportedImageEnhancers diff --git a/MediaBrowser.Api/Images/ImageWriter.cs b/MediaBrowser.Api/Images/ImageWriter.cs index e77a2f9b06..81dbb02434 100644 --- a/MediaBrowser.Api/Images/ImageWriter.cs +++ b/MediaBrowser.Api/Images/ImageWriter.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Entities; using ServiceStack.Service; using ServiceStack.ServiceHost; using System; @@ -28,11 +29,6 @@ namespace MediaBrowser.Api.Images /// The item. public BaseItem Item { get; set; } /// - /// Gets or sets a value indicating whether [crop white space]. - /// - /// true if [crop white space]; otherwise, false. - public bool CropWhiteSpace { get; set; } - /// /// The original image date modified /// public DateTime OriginalImageDateModified; @@ -68,7 +64,14 @@ namespace MediaBrowser.Api.Images /// Task. private Task WriteToAsync(Stream responseStream) { - return Kernel.Instance.ImageManager.ProcessImage(Item, Request.Type, Request.Index ?? 0, CropWhiteSpace, + var cropwhitespace = Request.Type == ImageType.Logo || Request.Type == ImageType.Art; + + if (Request.CropWhitespace.HasValue) + { + cropwhitespace = Request.CropWhitespace.Value; + } + + return Kernel.Instance.ImageManager.ProcessImage(Item, Request.Type, Request.Index ?? 0, cropwhitespace, OriginalImageDateModified, responseStream, Request.Width, Request.Height, Request.MaxWidth, Request.MaxHeight, Request.Quality, Enhancers); } diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 2f1e036e02..116997d96d 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -54,11 +54,9 @@ namespace MediaBrowser.Controller.Entities.TV /// System.String. public override string GetUserDataKey() { - if (Series != null) + if (Series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue) { - var seasonNo = Season != null ? Season.IndexNumber ?? 0 : 0; - var epNo = IndexNumber ?? 0; - return Series.GetUserDataKey() + seasonNo.ToString("000") + epNo.ToString("000"); + return Series.GetUserDataKey() + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000"); } return base.GetUserDataKey(); diff --git a/MediaBrowser.Model/DTO/ImageOptions.cs b/MediaBrowser.Model/DTO/ImageOptions.cs index 6b85cb78f4..68ca91ed00 100644 --- a/MediaBrowser.Model/DTO/ImageOptions.cs +++ b/MediaBrowser.Model/DTO/ImageOptions.cs @@ -57,5 +57,11 @@ namespace MediaBrowser.Model.Dto /// /// The hash. public Guid? Tag { get; set; } + + /// + /// Gets or sets a value indicating whether [crop whitespace]. + /// + /// null if [crop whitespace] contains no value, true if [crop whitespace]; otherwise, false. + public bool? CropWhitespace { get; set; } } }