mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-23 19:59:31 +01:00
Retry GetFrameCountCached up to 3x, clear cmd output caches on new file
This commit is contained in:
@@ -9,9 +9,9 @@ namespace Flowframes.Media
|
||||
{
|
||||
class GetFrameCountCached
|
||||
{
|
||||
public static Dictionary<QueryInfo, int> cache = new Dictionary<QueryInfo, int>();
|
||||
private static Dictionary<QueryInfo, int> cache = new Dictionary<QueryInfo, int>();
|
||||
|
||||
public static async Task<int> GetFrameCountAsync(string path)
|
||||
public static async Task<int> GetFrameCountAsync(string path, int retryCount = 3)
|
||||
{
|
||||
Logger.Log($"Getting frame count ({path})", true);
|
||||
|
||||
@@ -35,8 +35,23 @@ namespace Flowframes.Media
|
||||
else
|
||||
frameCount = await FfmpegCommands.GetFrameCountAsync(path);
|
||||
|
||||
Logger.Log($"Adding hash with value {frameCount} to cache.", true);
|
||||
cache.Add(hash, frameCount);
|
||||
if(frameCount > 0)
|
||||
{
|
||||
Logger.Log($"Adding hash with value {frameCount} to cache.", true);
|
||||
cache.Add(hash, frameCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (retryCount > 0)
|
||||
{
|
||||
Logger.Log($"Got {frameCount} frames, retrying ({retryCount} left)", true);
|
||||
frameCount = await GetFrameCountAsync(path, retryCount - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log($"Failed to get frames and out of retries ({frameCount} frames for {path})", true);
|
||||
}
|
||||
}
|
||||
|
||||
return frameCount;
|
||||
}
|
||||
@@ -58,5 +73,10 @@ namespace Flowframes.Media
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void Clear ()
|
||||
{
|
||||
cache.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user