diff options
Diffstat (limited to 'MediaBrowser.Api')
| -rw-r--r-- | MediaBrowser.Api/Images/ImageService.cs | 58 | ||||
| -rw-r--r-- | MediaBrowser.Api/Library/LibraryStructureService.cs | 16 |
2 files changed, 52 insertions, 22 deletions
diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index dc88b2cbe..259789fd1 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -564,7 +564,14 @@ namespace MediaBrowser.Api.Images }).ToList() : new List<IImageEnhancer>(); - var format = GetOutputFormat(request, imageInfo, supportedImageEnhancers); + var cropwhitespace = request.Type == ImageType.Logo || request.Type == ImageType.Art; + + if (request.CropWhitespace.HasValue) + { + cropwhitespace = request.CropWhitespace.Value; + } + + var format = GetOutputFormat(request, imageInfo, cropwhitespace, supportedImageEnhancers); var contentType = GetMimeType(format, imageInfo.Path); var cacheGuid = new Guid(_imageProcessor.GetImageCacheTag(item, imageInfo, supportedImageEnhancers)); @@ -585,6 +592,7 @@ namespace MediaBrowser.Api.Images return GetImageResult(item, request, imageInfo, + cropwhitespace, format, supportedImageEnhancers, contentType, @@ -597,6 +605,7 @@ namespace MediaBrowser.Api.Images private async Task<object> GetImageResult(IHasImages item, ImageRequest request, ItemImageInfo image, + bool cropwhitespace, ImageFormat format, List<IImageEnhancer> enhancers, string contentType, @@ -604,13 +613,6 @@ namespace MediaBrowser.Api.Images IDictionary<string, string> headers, bool isHeadRequest) { - var cropwhitespace = request.Type == ImageType.Logo || request.Type == ImageType.Art; - - if (request.CropWhitespace.HasValue) - { - cropwhitespace = request.CropWhitespace.Value; - } - var options = new ImageProcessingOptions { CropWhiteSpace = cropwhitespace, @@ -644,7 +646,7 @@ namespace MediaBrowser.Api.Images }); } - private ImageFormat GetOutputFormat(ImageRequest request, ItemImageInfo image, List<IImageEnhancer> enhancers) + private ImageFormat GetOutputFormat(ImageRequest request, ItemImageInfo image, bool cropwhitespace, List<IImageEnhancer> enhancers) { if (!string.IsNullOrWhiteSpace(request.Format)) { @@ -655,10 +657,37 @@ namespace MediaBrowser.Api.Images } } + var extension = Path.GetExtension(image.Path); + ImageFormat? inputFormat = null; + + if (string.Equals(extension, ".jpg", StringComparison.OrdinalIgnoreCase) || + string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase)) + { + inputFormat = ImageFormat.Jpg; + } + else if (string.Equals(extension, ".png", StringComparison.OrdinalIgnoreCase)) + { + inputFormat = ImageFormat.Png; + } + + var clientSupportedFormats = GetClientSupportedFormats(); + if (inputFormat.HasValue && clientSupportedFormats.Contains(inputFormat.Value) && enhancers.Count == 0) + { + if ((request.Quality ?? 100) == 100 && !request.Height.HasValue && !request.Width.HasValue && + !request.AddPlayedIndicator && !request.PercentPlayed.HasValue && !request.UnplayedCount.HasValue && string.IsNullOrWhiteSpace(request.BackgroundColor)) + { + // TODO: Allow this when specfying max width/height if the value is in range + if (!cropwhitespace && !request.MaxHeight.HasValue && !request.MaxWidth.HasValue) + { + return inputFormat.Value; + } + } + } + var serverFormats = _imageProcessor.GetSupportedImageOutputFormats(); - if (serverFormats.Contains(ImageFormat.Webp) && - GetClientSupportedFormats().Contains(ImageFormat.Webp)) + // Client doesn't care about format, so start with webp if supported + if (serverFormats.Contains(ImageFormat.Webp) && clientSupportedFormats.Contains(ImageFormat.Webp)) { return ImageFormat.Webp; } @@ -668,10 +697,7 @@ namespace MediaBrowser.Api.Images return ImageFormat.Png; } - var extension = Path.GetExtension(image.Path); - - if (string.Equals(extension, ".jpg", StringComparison.OrdinalIgnoreCase) || - string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase)) + if (inputFormat.HasValue && inputFormat.Value == ImageFormat.Jpg) { return ImageFormat.Jpg; } @@ -682,7 +708,7 @@ namespace MediaBrowser.Api.Images private ImageFormat[] GetClientSupportedFormats() { - var supportsWebP = (Request.AcceptTypes ?? new string[] {}).Contains("image/webp", StringComparer.OrdinalIgnoreCase); + var supportsWebP = (Request.AcceptTypes ?? new string[] { }).Contains("image/webp", StringComparer.OrdinalIgnoreCase); var userAgent = Request.UserAgent ?? string.Empty; diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index 76abfb743..decd19602 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -52,7 +52,7 @@ namespace MediaBrowser.Api.Library /// Gets or sets the path. /// </summary> /// <value>The path.</value> - public string Path { get; set; } + public string[] Paths { get; set; } } [Route("/Library/VirtualFolders", "DELETE")] @@ -207,11 +207,12 @@ namespace MediaBrowser.Api.Library throw new ArgumentException("There is already a media library with the name " + name + "."); } - if (!string.IsNullOrWhiteSpace(request.Path)) + if (request.Paths != null) { - if (!_fileSystem.DirectoryExists(request.Path)) + var invalidpath = request.Paths.FirstOrDefault(i => !_fileSystem.DirectoryExists(i)); + if (invalidpath != null) { - throw new DirectoryNotFoundException("The specified folder does not exist."); + throw new ArgumentException("The specified path does not exist: " + invalidpath + "."); } } @@ -231,9 +232,12 @@ namespace MediaBrowser.Api.Library } } - if (!string.IsNullOrWhiteSpace(request.Path)) + if (request.Paths != null) { - LibraryHelpers.AddMediaPath(_fileSystem, request.Name, request.Path, _appPaths); + foreach (var path in request.Paths) + { + LibraryHelpers.AddMediaPath(_fileSystem, request.Name, path, _appPaths); + } } } finally |
