|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using Emby.Drawing.Common;
|
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
@ -16,7 +17,6 @@ using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Emby.Drawing.Common;
|
|
|
|
|
|
|
|
|
|
namespace Emby.Drawing
|
|
|
|
|
{
|
|
|
|
@ -215,12 +215,12 @@ namespace Emby.Drawing
|
|
|
|
|
{
|
|
|
|
|
CheckDisposed();
|
|
|
|
|
|
|
|
|
|
if (!_fileSystem.FileExists(cacheFilePath))
|
|
|
|
|
if (!File.Exists(cacheFilePath))
|
|
|
|
|
{
|
|
|
|
|
var newWidth = Convert.ToInt32(newSize.Width);
|
|
|
|
|
var newHeight = Convert.ToInt32(newSize.Height);
|
|
|
|
|
|
|
|
|
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
|
|
|
|
|
|
|
|
|
|
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
@ -270,7 +270,7 @@ namespace Emby.Drawing
|
|
|
|
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
// Check again in case of contention
|
|
|
|
|
if (_fileSystem.FileExists(croppedImagePath))
|
|
|
|
|
if (File.Exists(croppedImagePath))
|
|
|
|
|
{
|
|
|
|
|
semaphore.Release();
|
|
|
|
|
return GetResult(croppedImagePath);
|
|
|
|
@ -280,7 +280,7 @@ namespace Emby.Drawing
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
|
|
|
|
|
|
|
|
|
|
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
imageProcessingLockTaken = true;
|
|
|
|
@ -366,7 +366,7 @@ namespace Emby.Drawing
|
|
|
|
|
/// <returns>ImageSize.</returns>
|
|
|
|
|
public ImageSize GetImageSize(string path)
|
|
|
|
|
{
|
|
|
|
|
return GetImageSize(path, _fileSystem.GetLastWriteTimeUtc(path), false);
|
|
|
|
|
return GetImageSize(path, File.GetLastWriteTimeUtc(path), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ImageSize GetImageSize(ItemImageInfo info)
|
|
|
|
@ -399,8 +399,6 @@ namespace Emby.Drawing
|
|
|
|
|
{
|
|
|
|
|
size = GetImageSizeInternal(path, allowSlowMethod);
|
|
|
|
|
|
|
|
|
|
StartSaveImageSizeTimer();
|
|
|
|
|
|
|
|
|
|
_cachedImagedSizes.AddOrUpdate(cacheHash, size, (keyName, oldValue) => size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -415,26 +413,28 @@ namespace Emby.Drawing
|
|
|
|
|
/// <returns>ImageSize.</returns>
|
|
|
|
|
private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var file = TagLib.File.Create(path))
|
|
|
|
|
{
|
|
|
|
|
var image = file as TagLib.Image.File;
|
|
|
|
|
|
|
|
|
|
var properties = image.Properties;
|
|
|
|
|
ImageSize size;
|
|
|
|
|
|
|
|
|
|
return new ImageSize
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Height = properties.PhotoHeight,
|
|
|
|
|
Width = properties.PhotoWidth
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
size = ImageHeader.GetDimensions(path, _logger, _fileSystem);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
if (!allowSlowMethod)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
//_logger.Info("Failed to read image header for {0}. Doing it the slow way.", path);
|
|
|
|
|
|
|
|
|
|
return ImageHeader.GetDimensions(path, _logger, _fileSystem);
|
|
|
|
|
CheckDisposed();
|
|
|
|
|
|
|
|
|
|
size = _imageEncoder.GetImageSize(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartSaveImageSizeTimer();
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly Timer _saveImageSizeTimer;
|
|
|
|
@ -452,7 +452,7 @@ namespace Emby.Drawing
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var path = ImageSizeFile;
|
|
|
|
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
|
|
|
|
_jsonSerializer.SerializeToFile(_cachedImagedSizes, path);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -624,7 +624,7 @@ namespace Emby.Drawing
|
|
|
|
|
await semaphore.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
// Check again in case of contention
|
|
|
|
|
if (_fileSystem.FileExists(enhancedImagePath))
|
|
|
|
|
if (File.Exists(enhancedImagePath))
|
|
|
|
|
{
|
|
|
|
|
semaphore.Release();
|
|
|
|
|
return enhancedImagePath;
|
|
|
|
@ -634,7 +634,7 @@ namespace Emby.Drawing
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
|
|
|
|
|
|
|
|
|
|
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|