incorporate file length into image cache tag
This commit is contained in:
parent
6df78dcb34
commit
e068e84ab6
|
@ -107,8 +107,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
var waitCount = isLive ? 2 : 2;
|
await WaitForMinimumSegmentCount(playlist, 3, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
await WaitForMinimumSegmentCount(playlist, waitCount, cancellationTokenSource.Token).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
@ -1519,6 +1519,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
image.Path = file.FullName;
|
image.Path = file.FullName;
|
||||||
image.DateModified = imageInfo.DateModified;
|
image.DateModified = imageInfo.DateModified;
|
||||||
|
image.Length = imageInfo.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1623,11 +1624,14 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fileInfo = new FileInfo(path);
|
||||||
|
|
||||||
return new ItemImageInfo
|
return new ItemImageInfo
|
||||||
{
|
{
|
||||||
Path = path,
|
Path = path,
|
||||||
DateModified = FileSystem.GetLastWriteTimeUtc(path),
|
DateModified = FileSystem.GetLastWriteTimeUtc(fileInfo),
|
||||||
Type = imageType
|
Type = imageType,
|
||||||
|
Length = fileInfo.Length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1686,6 +1690,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
existing.DateModified = FileSystem.GetLastWriteTimeUtc(newImage);
|
existing.DateModified = FileSystem.GetLastWriteTimeUtc(newImage);
|
||||||
|
existing.Length = ((FileInfo) newImage).Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1700,7 +1705,8 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
Path = file.FullName,
|
Path = file.FullName,
|
||||||
Type = type,
|
Type = type,
|
||||||
DateModified = FileSystem.GetLastWriteTimeUtc(file)
|
DateModified = FileSystem.GetLastWriteTimeUtc(file),
|
||||||
|
Length = ((FileInfo)file).Length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1739,9 +1745,15 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
FileSystem.SwapFiles(path1, path2);
|
FileSystem.SwapFiles(path1, path2);
|
||||||
|
|
||||||
|
var file1 = new FileInfo(info1.Path);
|
||||||
|
var file2 = new FileInfo(info2.Path);
|
||||||
|
|
||||||
// Refresh these values
|
// Refresh these values
|
||||||
info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
|
info1.DateModified = FileSystem.GetLastWriteTimeUtc(file1);
|
||||||
info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
|
info2.DateModified = FileSystem.GetLastWriteTimeUtc(file2);
|
||||||
|
|
||||||
|
info1.Length = file1.Length;
|
||||||
|
info2.Length = file2.Length;
|
||||||
|
|
||||||
return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,12 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <value>The path.</value>
|
/// <value>The path.</value>
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the length.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The length.</value>
|
||||||
|
public long Length { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the type.
|
/// Gets or sets the type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -690,8 +690,9 @@ namespace MediaBrowser.Model.ApiClient
|
||||||
/// Stops the transcoding processes.
|
/// Stops the transcoding processes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deviceId">The device identifier.</param>
|
/// <param name="deviceId">The device identifier.</param>
|
||||||
|
/// <param name="streamId">The stream identifier.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
Task StopTranscodingProcesses(string deviceId);
|
Task StopTranscodingProcesses(string deviceId, string streamId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the index of the audio stream.
|
/// Sets the index of the audio stream.
|
||||||
|
|
|
@ -386,6 +386,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentImage.DateModified = _fileSystem.GetLastWriteTimeUtc(image.FileInfo);
|
currentImage.DateModified = _fileSystem.GetLastWriteTimeUtc(image.FileInfo);
|
||||||
|
currentImage.Length = ((FileInfo) image.FileInfo).Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,21 +186,31 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
}
|
}
|
||||||
|
|
||||||
var dateModified = options.Image.DateModified;
|
var dateModified = options.Image.DateModified;
|
||||||
|
var length = options.Image.Length;
|
||||||
|
|
||||||
if (options.CropWhiteSpace)
|
if (options.CropWhiteSpace)
|
||||||
{
|
{
|
||||||
var tuple = await GetWhitespaceCroppedImage(originalImagePath, dateModified).ConfigureAwait(false);
|
var tuple = await GetWhitespaceCroppedImage(originalImagePath, dateModified, length).ConfigureAwait(false);
|
||||||
|
|
||||||
originalImagePath = tuple.Item1;
|
originalImagePath = tuple.Item1;
|
||||||
dateModified = tuple.Item2;
|
dateModified = tuple.Item2;
|
||||||
|
length = tuple.Item3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.Enhancers.Count > 0)
|
if (options.Enhancers.Count > 0)
|
||||||
{
|
{
|
||||||
var tuple = await GetEnhancedImage(options.Image, options.Item, options.ImageIndex, options.Enhancers).ConfigureAwait(false);
|
var tuple = await GetEnhancedImage(new ItemImageInfo
|
||||||
|
{
|
||||||
|
Length = length,
|
||||||
|
DateModified = dateModified,
|
||||||
|
Type = options.Image.Type,
|
||||||
|
Path = originalImagePath
|
||||||
|
|
||||||
|
}, options.Item, options.ImageIndex, options.Enhancers).ConfigureAwait(false);
|
||||||
|
|
||||||
originalImagePath = tuple.Item1;
|
originalImagePath = tuple.Item1;
|
||||||
dateModified = tuple.Item2;
|
dateModified = tuple.Item2;
|
||||||
|
length = tuple.Item3;
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalImageSize = GetImageSize(originalImagePath, dateModified);
|
var originalImageSize = GetImageSize(originalImagePath, dateModified);
|
||||||
|
@ -217,7 +227,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
var quality = options.Quality ?? 90;
|
var quality = options.Quality ?? 90;
|
||||||
|
|
||||||
var outputFormat = GetOutputFormat(options.OutputFormat);
|
var outputFormat = GetOutputFormat(options.OutputFormat);
|
||||||
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
|
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, length, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
|
||||||
|
|
||||||
var semaphore = GetLock(cacheFilePath);
|
var semaphore = GetLock(cacheFilePath);
|
||||||
|
|
||||||
|
@ -341,13 +351,11 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Crops whitespace from an image, caches the result, and returns the cached path
|
/// Crops whitespace from an image, caches the result, and returns the cached path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="originalImagePath">The original image path.</param>
|
private async Task<Tuple<string, DateTime, long>> GetWhitespaceCroppedImage(string originalImagePath, DateTime dateModified, long length)
|
||||||
/// <param name="dateModified">The date modified.</param>
|
|
||||||
/// <returns>System.String.</returns>
|
|
||||||
private async Task<Tuple<string, DateTime>> GetWhitespaceCroppedImage(string originalImagePath, DateTime dateModified)
|
|
||||||
{
|
{
|
||||||
var name = originalImagePath;
|
var name = originalImagePath;
|
||||||
name += "datemodified=" + dateModified.Ticks;
|
name += "datemodified=" + dateModified.Ticks;
|
||||||
|
name += "length=" + length;
|
||||||
|
|
||||||
var croppedImagePath = GetCachePath(CroppedWhitespaceImageCachePath, name, Path.GetExtension(originalImagePath));
|
var croppedImagePath = GetCachePath(CroppedWhitespaceImageCachePath, name, Path.GetExtension(originalImagePath));
|
||||||
|
|
||||||
|
@ -359,7 +367,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
if (File.Exists(croppedImagePath))
|
if (File.Exists(croppedImagePath))
|
||||||
{
|
{
|
||||||
semaphore.Release();
|
semaphore.Release();
|
||||||
return new Tuple<string, DateTime>(croppedImagePath, _fileSystem.GetLastWriteTimeUtc(croppedImagePath));
|
return GetResult(croppedImagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -377,14 +385,21 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
// We have to have a catch-all here because some of the .net image methods throw a plain old Exception
|
// We have to have a catch-all here because some of the .net image methods throw a plain old Exception
|
||||||
_logger.ErrorException("Error cropping image {0}", ex, originalImagePath);
|
_logger.ErrorException("Error cropping image {0}", ex, originalImagePath);
|
||||||
|
|
||||||
return new Tuple<string, DateTime>(originalImagePath, dateModified);
|
return new Tuple<string, DateTime, long>(originalImagePath, dateModified, length);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
semaphore.Release();
|
semaphore.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<string, DateTime>(croppedImagePath, _fileSystem.GetLastWriteTimeUtc(croppedImagePath));
|
return GetResult(croppedImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tuple<string, DateTime, long> GetResult(string path)
|
||||||
|
{
|
||||||
|
var file = new FileInfo(path);
|
||||||
|
|
||||||
|
return new Tuple<string, DateTime, long>(path, _fileSystem.GetLastWriteTimeUtc(file), file.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -395,7 +410,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the cache file path based on a set of parameters
|
/// Gets the cache file path based on a set of parameters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, string backgroundColor)
|
private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, long length, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, string backgroundColor)
|
||||||
{
|
{
|
||||||
var filename = originalPath;
|
var filename = originalPath;
|
||||||
|
|
||||||
|
@ -406,6 +421,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
filename += "quality=" + quality;
|
filename += "quality=" + quality;
|
||||||
|
|
||||||
filename += "datemodified=" + dateModified.Ticks;
|
filename += "datemodified=" + dateModified.Ticks;
|
||||||
|
filename += "length=" + length;
|
||||||
|
|
||||||
filename += "f=" + format;
|
filename += "f=" + format;
|
||||||
|
|
||||||
|
@ -601,16 +617,17 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
var originalImagePath = image.Path;
|
var originalImagePath = image.Path;
|
||||||
var dateModified = image.DateModified;
|
var dateModified = image.DateModified;
|
||||||
var imageType = image.Type;
|
var imageType = image.Type;
|
||||||
|
var length = image.Length;
|
||||||
|
|
||||||
// Optimization
|
// Optimization
|
||||||
if (imageEnhancers.Count == 0)
|
if (imageEnhancers.Count == 0)
|
||||||
{
|
{
|
||||||
return (originalImagePath + dateModified.Ticks).GetMD5().ToString("N");
|
return (originalImagePath + dateModified.Ticks + string.Empty + length).GetMD5().ToString("N");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache name is created with supported enhancers combined with the last config change so we pick up new config changes
|
// Cache name is created with supported enhancers combined with the last config change so we pick up new config changes
|
||||||
var cacheKeys = imageEnhancers.Select(i => i.GetConfigurationCacheKey(item, imageType)).ToList();
|
var cacheKeys = imageEnhancers.Select(i => i.GetConfigurationCacheKey(item, imageType)).ToList();
|
||||||
cacheKeys.Add(originalImagePath + dateModified.Ticks);
|
cacheKeys.Add(originalImagePath + dateModified.Ticks + string.Empty + length);
|
||||||
|
|
||||||
return string.Join("|", cacheKeys.ToArray()).GetMD5().ToString("N");
|
return string.Join("|", cacheKeys.ToArray()).GetMD5().ToString("N");
|
||||||
}
|
}
|
||||||
|
@ -633,7 +650,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
return result.Item1;
|
return result.Item1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Tuple<string, DateTime>> GetEnhancedImage(ItemImageInfo image,
|
private async Task<Tuple<string, DateTime, long>> GetEnhancedImage(ItemImageInfo image,
|
||||||
IHasImages item,
|
IHasImages item,
|
||||||
int imageIndex,
|
int imageIndex,
|
||||||
List<IImageEnhancer> enhancers)
|
List<IImageEnhancer> enhancers)
|
||||||
|
@ -641,6 +658,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
var originalImagePath = image.Path;
|
var originalImagePath = image.Path;
|
||||||
var dateModified = image.DateModified;
|
var dateModified = image.DateModified;
|
||||||
var imageType = image.Type;
|
var imageType = image.Type;
|
||||||
|
var length = image.Length;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -652,9 +670,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
// If the path changed update dateModified
|
// If the path changed update dateModified
|
||||||
if (!ehnancedImagePath.Equals(originalImagePath, StringComparison.OrdinalIgnoreCase))
|
if (!ehnancedImagePath.Equals(originalImagePath, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
dateModified = _fileSystem.GetLastWriteTimeUtc(ehnancedImagePath);
|
return GetResult(ehnancedImagePath);
|
||||||
|
|
||||||
return new Tuple<string, DateTime>(ehnancedImagePath, dateModified);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -662,7 +678,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||||
_logger.Error("Error enhancing image", ex);
|
_logger.Error("Error enhancing image", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<string, DateTime>(originalImagePath, dateModified);
|
return new Tuple<string, DateTime, long>(originalImagePath, dateModified, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -765,11 +765,14 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(chapterInfo.ImagePath))
|
if (!string.IsNullOrEmpty(chapterInfo.ImagePath))
|
||||||
{
|
{
|
||||||
|
var file = new FileInfo(chapterInfo.ImagePath);
|
||||||
|
|
||||||
dto.ImageTag = GetImageCacheTag(item, new ItemImageInfo
|
dto.ImageTag = GetImageCacheTag(item, new ItemImageInfo
|
||||||
{
|
{
|
||||||
Path = chapterInfo.ImagePath,
|
Path = chapterInfo.ImagePath,
|
||||||
Type = ImageType.Chapter,
|
Type = ImageType.Chapter,
|
||||||
DateModified = _fileSystem.GetLastWriteTimeUtc(chapterInfo.ImagePath)
|
DateModified = _fileSystem.GetLastWriteTimeUtc(file),
|
||||||
|
Length = file.Length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user