Files
flowframes/CodeLegacy/Media/GetMediaResolutionCached.cs

44 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2021-08-23 16:50:18 +02:00
using System.Drawing;
using System.IO;
2021-08-23 16:50:18 +02:00
using System.Threading.Tasks;
using Flowframes.Data;
using Flowframes.IO;
namespace Flowframes.Media
{
class GetMediaResolutionCached
{
private static Dictionary<QueryInfo, Size> cache = new Dictionary<QueryInfo, Size>();
2021-08-23 16:50:18 +02:00
public static async Task<Size> GetSizeAsync(string path)
{
long filesize = IoUtils.GetPathSize(path);
2021-09-14 18:18:41 +02:00
QueryInfo hash = new QueryInfo(path, filesize);
2021-08-23 16:50:18 +02:00
if (filesize > 0 && cache.ContainsKey(hash))
2021-08-23 16:50:18 +02:00
{
Size cachedVal = cache[hash];
Logger.Log($"Resolution of '{Path.GetFileName(path)}': {cachedVal.Width}x{cachedVal.Height} [Cached]", true);
return cachedVal;
2021-08-23 16:50:18 +02:00
}
Size size;
size = await IoUtils.GetVideoOrFramesRes(path);
if(size.Width > 0 && size.Height > 0)
{
cache.Add(hash, size);
}
2021-08-23 16:50:18 +02:00
Logger.Log($"Resolution of '{Path.GetFileName(path)}': {size.Width}x{size.Height}", true);
2021-08-23 16:50:18 +02:00
return size;
}
public static void Clear()
{
cache.Clear();
}
2021-08-23 16:50:18 +02:00
}
}