mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-25 12:49:26 +01:00
Write dupes into json instead of simple txt
This commit is contained in:
@@ -10,6 +10,7 @@ using Flowframes.Os;
|
||||
using Flowframes.Data;
|
||||
using System.Drawing;
|
||||
using Paths = Flowframes.IO.Paths;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Flowframes.Magick
|
||||
{
|
||||
@@ -196,14 +197,14 @@ namespace Flowframes.Magick
|
||||
public static async Task CreateDupesFile (string framesPath, int lastFrameNum, string ext)
|
||||
{
|
||||
bool debug = Config.GetBool("dupeScanDebug", false);
|
||||
string infoFile = Path.Combine(framesPath.GetParentDir(), "dupes.ini");
|
||||
string fileContent = "";
|
||||
|
||||
FileInfo[] frameFiles = IoUtils.GetFileInfosSorted(framesPath, false, "*" + ext);
|
||||
|
||||
if (debug)
|
||||
Logger.Log($"Running CreateDupesFile for '{framesPath}' ({frameFiles.Length} files), lastFrameNum = {lastFrameNum}, ext = {ext}.", true, false, "dupes");
|
||||
|
||||
Dictionary<string, List<string>> frames = new Dictionary<string, List<string>>();
|
||||
|
||||
for(int i = 0; i < frameFiles.Length; i++)
|
||||
{
|
||||
bool isLastItem = (i + 1) == frameFiles.Length;
|
||||
@@ -217,10 +218,22 @@ namespace Flowframes.Magick
|
||||
if(debug)
|
||||
Logger.Log($"{(isLastItem ? "[isLastItem] " : "")}frameNum1 (frameFiles[{i}]) = {frameNum1}, frameNum2 (frameFiles[{i+1}]) = {frameNum2} => dupes = {dupes}", true, false, "dupes");
|
||||
|
||||
fileContent += $"{Path.GetFileNameWithoutExtension(frameFiles[i].Name)}:{dupes}\n";
|
||||
try
|
||||
{
|
||||
frames[Path.GetFileNameWithoutExtension(frameFiles[i].Name)] = new List<string>();
|
||||
|
||||
for (int dupe = 1; dupe <= dupes; dupe++)
|
||||
frames[Path.GetFileNameWithoutExtension(frameFiles[i].Name)].Add(Path.GetFileNameWithoutExtension(frameFiles[i + dupe].Name));
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
File.WriteAllText(infoFile, fileContent);
|
||||
File.WriteAllText(Path.Combine(framesPath.GetParentDir(), "dupes.json"), JsonConvert.SerializeObject(frames, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,18 +41,11 @@ namespace Flowframes.Main
|
||||
}
|
||||
}
|
||||
|
||||
static Dictionary<string, int> dupesDict = new Dictionary<string, int>();
|
||||
static Dictionary<string, List<string>> dupesDict = new Dictionary<string, List<string>>();
|
||||
|
||||
static void LoadDupesFile(string path)
|
||||
{
|
||||
dupesDict.Clear();
|
||||
if (!File.Exists(path)) return;
|
||||
string[] dupesFileLines = IoUtils.ReadLines(path);
|
||||
foreach (string line in dupesFileLines)
|
||||
{
|
||||
string[] values = line.Split(':');
|
||||
dupesDict.Add(values[0], values[1].GetInt());
|
||||
}
|
||||
dupesDict = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(File.ReadAllText(path));
|
||||
}
|
||||
|
||||
public static async Task CreateEncFile(string framesPath, bool loopEnabled, float interpFactor)
|
||||
@@ -72,7 +65,7 @@ namespace Flowframes.Main
|
||||
Array.Resize(ref frameFilesWithoutLast, frameFilesWithoutLast.Length - 1);
|
||||
string framesFile = Path.Combine(framesPath.GetParentDir(), Paths.GetFrameOrderFilename(interpFactor));
|
||||
string fileContent = "";
|
||||
string dupesFile = Path.Combine(framesPath.GetParentDir(), "dupes.ini");
|
||||
string dupesFile = Path.Combine(framesPath.GetParentDir(), "dupes.json");
|
||||
LoadDupesFile(dupesFile);
|
||||
|
||||
string scnFramesPath = Path.Combine(framesPath.GetParentDir(), Paths.scenesDir);
|
||||
@@ -118,18 +111,9 @@ namespace Flowframes.Main
|
||||
fileContent += fileContent.SplitIntoLines().Where(x => x.StartsWith("'file ")).Last();
|
||||
}
|
||||
|
||||
//int lastFrameTimes = Config.GetBool(Config.Key.fixOutputDuration) ? (int)interpFactor : 1;
|
||||
//
|
||||
//for (int i = 0; i < lastFrameTimes; i++)
|
||||
//{
|
||||
// fileContent += $"{(i > 0 ? "\n" : "")}file '{Paths.interpDir}/{lastOutFileCount.ToString().PadLeft(Padding.interpFrames, '0')}{ext}'"; // Last frame (source)
|
||||
// inputFilenames.Add(frameFiles.Last().Name);
|
||||
//}
|
||||
|
||||
if (loop)
|
||||
{
|
||||
fileContent = fileContent.Remove(fileContent.LastIndexOf("\n"));
|
||||
//inputFilenames.Remove(inputFilenames.Last());
|
||||
}
|
||||
|
||||
File.WriteAllText(framesFile, fileContent);
|
||||
@@ -248,7 +232,7 @@ namespace Flowframes.Main
|
||||
|
||||
string frameName = GetNameNoExt(frameFilesWithoutLast[i].Name);
|
||||
string frameNameImport = GetNameNoExt(FrameRename.importFilenames[i]);
|
||||
int dupesAmount = dupesDict.ContainsKey(frameNameImport) ? dupesDict[frameNameImport] : 0;
|
||||
int dupesAmount = dupesDict.ContainsKey(frameNameImport) ? dupesDict[frameNameImport].Count : 0;
|
||||
bool discardThisFrame = (sceneDetection && i < frameFilesWithoutLast.Length && sceneFrames.Contains(GetNameNoExt(FrameRename.importFilenames[i + 1]))); // i+2 is in scene detection folder, means i+1 is ugly interp frame
|
||||
|
||||
for (int frm = 0; frm < interpFramesAmount; frm++) // Generate frames file lines
|
||||
|
||||
Reference in New Issue
Block a user