aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
authorVasily <JustAMan@users.noreply.github.com>2019-03-08 00:23:00 +0300
committerGitHub <noreply@github.com>2019-03-08 00:23:00 +0300
commit028a98d2c1440ba25e50e54ae97e81c55bc4c497 (patch)
treed10e832cb29d4dce888f18e68eb8bb99c426892b /MediaBrowser.Api
parent0f70a81db3d2d94dc50a407ba39963fd5df6d01f (diff)
parentc5fce647defd2eace2d2431ccc52ffe1d027c184 (diff)
Merge pull request #1058 from Bond-009/clean
Cleanup/simplification
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/Images/ImageService.cs89
1 files changed, 49 insertions, 40 deletions
diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs
index c25204bf2..10bbc9e5d 100644
--- a/MediaBrowser.Api/Images/ImageService.cs
+++ b/MediaBrowser.Api/Images/ImageService.cs
@@ -312,35 +312,35 @@ namespace MediaBrowser.Api.Images
private ImageInfo GetImageInfo(BaseItem item, ItemImageInfo info, int? imageIndex)
{
+ int? width = null;
+ int? height = null;
+ long length = 0;
+
try
{
- int? width = null;
- int? height = null;
- long length = 0;
-
- try
+ if (info.IsLocalFile)
{
- if (info.IsLocalFile)
- {
- var fileInfo = _fileSystem.GetFileInfo(info.Path);
- length = fileInfo.Length;
+ var fileInfo = _fileSystem.GetFileInfo(info.Path);
+ length = fileInfo.Length;
- ImageDimensions size = _imageProcessor.GetImageDimensions(item, info, true);
- width = size.Width;
- height = size.Height;
-
- if (width <= 0 || height <= 0)
- {
- width = null;
- height = null;
- }
+ ImageDimensions size = _imageProcessor.GetImageDimensions(item, info, true);
+ width = size.Width;
+ height = size.Height;
+ if (width <= 0 || height <= 0)
+ {
+ width = null;
+ height = null;
}
}
- catch
- {
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error getting image information for {Item}", item.Name);
+ }
- }
+ try
+ {
return new ImageInfo
{
Path = info.Path,
@@ -354,7 +354,7 @@ namespace MediaBrowser.Api.Images
}
catch (Exception ex)
{
- Logger.LogError(ex, "Error getting image information for {path}", info.Path);
+ Logger.LogError(ex, "Error getting image information for {Path}", info.Path);
return null;
}
@@ -519,16 +519,16 @@ namespace MediaBrowser.Api.Images
request.AddPlayedIndicator = true;
}
}
+
if (request.PercentPlayed.HasValue)
{
request.UnplayedCount = null;
}
- if (request.UnplayedCount.HasValue)
+
+ if (request.UnplayedCount.HasValue
+ && request.UnplayedCount.Value <= 0)
{
- if (request.UnplayedCount.Value <= 0)
- {
- request.UnplayedCount = null;
- }
+ request.UnplayedCount = null;
}
if (item == null)
@@ -542,7 +542,6 @@ namespace MediaBrowser.Api.Images
}
var imageInfo = GetImageInfo(request, item);
-
if (imageInfo == null)
{
var displayText = item == null ? itemId.ToString() : item.Name;
@@ -550,7 +549,6 @@ namespace MediaBrowser.Api.Images
}
IImageEnhancer[] supportedImageEnhancers;
-
if (_imageProcessor.ImageEnhancers.Length > 0)
{
if (item == null)
@@ -565,13 +563,15 @@ namespace MediaBrowser.Api.Images
supportedImageEnhancers = Array.Empty<IImageEnhancer>();
}
- var cropwhitespace = request.Type == ImageType.Logo ||
- request.Type == ImageType.Art;
-
+ bool cropwhitespace;
if (request.CropWhitespace.HasValue)
{
cropwhitespace = request.CropWhitespace.Value;
}
+ else
+ {
+ cropwhitespace = request.Type == ImageType.Logo || request.Type == ImageType.Art;
+ }
var outputFormats = GetOutputFormats(request);
@@ -653,12 +653,10 @@ namespace MediaBrowser.Api.Images
private ImageFormat[] GetOutputFormats(ImageRequest request)
{
- if (!string.IsNullOrWhiteSpace(request.Format))
+ if (!string.IsNullOrWhiteSpace(request.Format)
+ && Enum.TryParse(request.Format, true, out ImageFormat format))
{
- if (Enum.TryParse(request.Format, true, out ImageFormat format))
- {
- return new ImageFormat[] { format };
- }
+ return new ImageFormat[] { format };
}
return GetClientSupportedFormats();
@@ -666,8 +664,19 @@ namespace MediaBrowser.Api.Images
private ImageFormat[] GetClientSupportedFormats()
{
- //logger.LogDebug("Request types: {0}", string.Join(",", Request.AcceptTypes ?? Array.Empty<string>()));
- var supportedFormats = (Request.AcceptTypes ?? Array.Empty<string>()).Select(i => i.Split(';')[0]).ToArray();
+ var supportedFormats = Request.AcceptTypes ?? Array.Empty<string>();
+ if (supportedFormats.Length > 0)
+ {
+ for (int i = 0; i < supportedFormats.Length; i++)
+ {
+ int index = supportedFormats[i].IndexOf(';');
+ if (index != -1)
+ {
+ supportedFormats[i] = supportedFormats[i].Substring(0, index);
+ }
+ }
+ }
+
var acceptParam = Request.QueryString["accept"];
var supportsWebP = SupportsFormat(supportedFormats, acceptParam, "webp", false);
@@ -700,7 +709,7 @@ namespace MediaBrowser.Api.Images
return formats.ToArray();
}
- private bool SupportsFormat(string[] requestAcceptTypes, string acceptParam, string format, bool acceptAll)
+ private bool SupportsFormat(IEnumerable<string> requestAcceptTypes, string acceptParam, string format, bool acceptAll)
{
var mimeType = "image/" + format;