limit disk use and keep cover art aspect ratio (#502)

* use temp file pool to limit disk use

* keep aspect ratio and crop when scaling cover art for blurred background

* fix typo
This commit is contained in:
Jason Dove
2021-11-25 18:47:22 -06:00
committed by GitHub
parent 21b90a1b6c
commit 0edfb71f8d
16 changed files with 96 additions and 7 deletions
+35
View File
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.IO;
using ErsatzTV.Core.Interfaces.FFmpeg;
namespace ErsatzTV.Core.FFmpeg
{
public class TempFilePool : ITempFilePool
{
private const int ItemLimit = 10;
private readonly Dictionary<TempFileCategory, int> _state = new();
private readonly object _lock = new();
public string GetNextTempFile(TempFileCategory category)
{
lock (_lock)
{
var index = 0;
if (_state.TryGetValue(category, out int current))
{
index = (current + 1) % ItemLimit;
}
_state[category] = index;
return GetFileName(category, index);
}
}
private static string GetFileName(TempFileCategory category, int index)
{
return Path.Combine(FileSystemLayout.TempFilePoolFolder, $"{category}_{index}".ToLowerInvariant());
}
}
}