diff --git a/Program.cs b/Program.cs index fc96ee9..1a86ec1 100644 --- a/Program.cs +++ b/Program.cs @@ -41,19 +41,14 @@ namespace placeholdervo { foreach(var srcKey in filePickups.Keys) { - // var files = Directory.GetFiles(conf.sync_dropoff); - // Console.WriteLine($"files listed: {string.Join(", ", files)}"); - // Console.WriteLine($"hoping for: {string.Join(", ", filePickups.Keys)}"); - // Console.WriteLine($"sanity check: first listed file: {Path.GetFileName(files.FirstOrDefault())}"); - // Console.WriteLine($"sanity check: first key: {scriptFragmentVoiceFiles.Keys.FirstOrDefault()}"); - // Console.WriteLine($"sanity check: first value: {scriptFragmentVoiceFiles[scriptFragmentVoiceFiles.Keys.FirstOrDefault()]}"); + //Console.WriteLine($"hoping for {srcKey} (would move it to {filePickups[srcKey]})"); if(File.Exists(srcKey)) { Console.WriteLine($"found {srcKey}"); string dest; if (filePickups.TryRemove(srcKey, out dest)) { - File.Move(srcKey, dest); + File.Move(srcKey, dest, true); } else { @@ -64,7 +59,12 @@ namespace placeholdervo } if(scriptFileCancellationToken.IsCancellationRequested) { - return; + //Console.WriteLine($"Cancellation requested. but I'm using it in more of a \"there won't be more work, but finish what you're doing\" kind of way."); + if(filePickups.IsEmpty) + { + Console.WriteLine("and we got nothing left, so we quit."); + return; + } } System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); @@ -74,17 +74,32 @@ namespace placeholdervo private static async void FFStuff() { var cardCount = 0; + var magnitude = 1; + Console.WriteLine($"{titleCardLines.Count} title card lines"); + magnitude = (int)Math.Log10(titleCardLines.Count); + Directory.CreateDirectory(conf.titlecards_dest); foreach(var tcL in titleCardLines) { + Console.WriteLine("titlecard commanding"); await Process.Start(conf.titlecard_command, tcL).WaitForExitAsync(); - File.Move("tc.png", Path.Combine(conf.titlecards_dest, $"tc{cardCount++}.png")); + cardCount++; + File.Move("tc.png", Path.Combine(conf.titlecards_dest, $"tc{cardCount.ToString($"D{magnitude}")}.png"), true); } + Console.WriteLine("titlecards done"); - cardCount = 0; - foreach(var nL in noteLines) + if(noteLines != null) { - await Process.Start(conf.titlecard_command, nL).WaitForExitAsync(); - File.Move("n0.png", Path.Combine(conf.notes_dest, $"note{cardCount++}.png")); + cardCount = 0; + Console.WriteLine($"{noteLines?.Count} note lines"); + magnitude = (int)Math.Log10(noteLines?.Count ?? 1); + Directory.CreateDirectory(conf.notes_dest); + foreach(var nL in noteLines) + { + Console.WriteLine("note commanding"); + await Process.Start(conf.note_command, nL).WaitForExitAsync(); + cardCount++; + File.Move("note.png", Path.Combine(conf.notes_dest, $"note{cardCount.ToString($"D{magnitude}")}.png"), true); + } } } public static async Task Main(string[] args) @@ -121,10 +136,10 @@ namespace placeholdervo .Append("\n").Append("\n"); var primaryVOLines = new List(); var titlecardUnprocessed = new List(); - var titlecardLines = new List(); + var directiveLines = new List(); var altVOLines = new List(); - var noteLines = new List(); + foreach(var l in lines) { if(l.StartsWith('#')) @@ -173,7 +188,7 @@ namespace placeholdervo TitleCardText = string.Join('.', titleLevels[1..]) + ": " + TitleCardText; } Console.WriteLine($"title card: {TitleCardText}"); - titlecardLines.Add(TitleCardText); + titleCardLines.Enqueue(TitleCardText); } else { @@ -213,7 +228,7 @@ namespace placeholdervo var parameterText = thisLine[(thisLine.IndexOf(']') + 1) ..].Trim(); if(directiveName == "note") { - noteLines.Add(parameterText); + noteLines.Enqueue(parameterText); Console.WriteLine($"on screen note: {parameterText}"); } else @@ -233,6 +248,8 @@ namespace placeholdervo // execute them all taskHeap.Add(Task.Run(FFStuff)); taskHeap.Add(Task.Run(filePickup)); + Console.WriteLine("sleeping for 1 sec before requesting cancellation"); + System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); cancelSource.Cancel(); Task.WaitAll([.. taskHeap]); Console.WriteLine("kbai"); @@ -252,11 +269,11 @@ namespace placeholdervo } else { - var fname = await response.Content.ReadAsStringAsync(); + var fname = (await response.Content.ReadAsStringAsync()).Trim('[').Trim(']').Trim('"'); Console.WriteLine($"success; {fname}."); //"success" might be a strong word; it's successfully submitted. Its decided what filename it will, eventually, give it. var ext = Path.GetExtension(fname); Directory.CreateDirectory(conf.VODropoff); - awaitFile(Path.Combine(conf.sync_dropoff, fname), destPath + $".{ext}"); + awaitFile(Path.Combine(conf.sync_dropoff, fname), destPath + $"{ext}"); } } }