update image processor

This commit is contained in:
Luke Pulverenti 2017-05-12 01:00:45 -04:00
parent 6c60656dad
commit 6fd86f61cb
3 changed files with 41 additions and 20 deletions

View File

@ -198,7 +198,7 @@ namespace Emby.Drawing
return new Tuple<string, string, DateTime>(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); return new Tuple<string, string, DateTime>(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
} }
ImageSize? originalImageSize; ImageSize? originalImageSize = null;
try try
{ {
originalImageSize = GetImageSize(originalImagePath, dateModified, true); originalImageSize = GetImageSize(originalImagePath, dateModified, true);
@ -333,7 +333,7 @@ namespace Emby.Drawing
return new ImageSize(options.Width.Value, options.Height.Value); return new ImageSize(options.Width.Value, options.Height.Value);
} }
var aspect = GetEstimatedAspectRatio(options.Image.Type); var aspect = GetEstimatedAspectRatio(options.Image.Type, options.Item);
var width = options.Width ?? options.MaxWidth; var width = options.Width ?? options.MaxWidth;
@ -348,7 +348,7 @@ namespace Emby.Drawing
return new ImageSize(widthValue, height); return new ImageSize(widthValue, height);
} }
private double GetEstimatedAspectRatio(ImageType type) private double GetEstimatedAspectRatio(ImageType type, IHasImages item)
{ {
switch (type) switch (type)
{ {
@ -368,7 +368,7 @@ namespace Emby.Drawing
case ImageType.Logo: case ImageType.Logo:
return 2.58; return 2.58;
case ImageType.Primary: case ImageType.Primary:
return .667; return item.GetDefaultPrimaryImageAspectRatio() ?? .667;
default: default:
return 1; return 1;
} }
@ -499,26 +499,39 @@ namespace Emby.Drawing
/// <returns>ImageSize.</returns> /// <returns>ImageSize.</returns>
private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod) private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod)
{ {
// Can't use taglib because it keeps a lock on the file
//try
//{
// using (var file = TagLib.File.Create(new StreamFileAbstraction(Path.GetFileName(path), _fileSystem.OpenRead(path), null)))
// {
// var image = file as TagLib.Image.File;
// var properties = image.Properties;
// return new ImageSize
// {
// Height = properties.PhotoHeight,
// Width = properties.PhotoWidth
// };
// }
//}
//catch
//{
//}
try try
{ {
using (var file = TagLib.File.Create(new StreamFileAbstraction(Path.GetFileName(path), _fileSystem.OpenRead(path), null))) return ImageHeader.GetDimensions(path, _logger, _fileSystem);
{
var image = file as TagLib.Image.File;
var properties = image.Properties;
return new ImageSize
{
Height = properties.PhotoHeight,
Width = properties.PhotoWidth
};
}
} }
catch catch
{ {
} if (allowSlowMethod)
{
return _imageEncoder.GetImageSize(path);
}
return ImageHeader.GetDimensions(path, _logger, _fileSystem); throw;
}
} }
private readonly ITimer _saveImageSizeTimer; private readonly ITimer _saveImageSizeTimer;

View File

@ -537,7 +537,7 @@ namespace Emby.Server.Core.IO
} }
} }
var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger, _timerFactory, _environmentInfo); var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger, _timerFactory, _environmentInfo, LibraryManager);
newRefresher.Completed += NewRefresher_Completed; newRefresher.Completed += NewRefresher_Completed;
_activeRefreshers.Add(newRefresher); _activeRefreshers.Add(newRefresher);
} }

View File

@ -34,8 +34,9 @@ namespace Emby.Server.Implementations.IO
public event EventHandler<EventArgs> Completed; public event EventHandler<EventArgs> Completed;
private readonly IEnvironmentInfo _environmentInfo; private readonly IEnvironmentInfo _environmentInfo;
private readonly ILibraryManager _libraryManager;
public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger, ITimerFactory timerFactory, IEnvironmentInfo environmentInfo) public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger, ITimerFactory timerFactory, IEnvironmentInfo environmentInfo, ILibraryManager libraryManager1)
{ {
logger.Debug("New file refresher created for {0}", path); logger.Debug("New file refresher created for {0}", path);
Path = path; Path = path;
@ -47,6 +48,7 @@ namespace Emby.Server.Implementations.IO
Logger = logger; Logger = logger;
_timerFactory = timerFactory; _timerFactory = timerFactory;
_environmentInfo = environmentInfo; _environmentInfo = environmentInfo;
_libraryManager = libraryManager1;
AddPath(path); AddPath(path);
} }
@ -235,6 +237,12 @@ namespace Emby.Server.Implementations.IO
return false; return false;
} }
// Only try to open video files
if (!_libraryManager.IsVideoFile(path))
{
return false;
}
try try
{ {
var data = _fileSystem.GetFileSystemInfo(path); var data = _fileSystem.GetFileSystemInfo(path);