filepickup tasks (untested)

This commit is contained in:
Adam R Grey 2024-09-22 17:46:17 -04:00
parent 90f50b9e2b
commit b49516451f

View File

@ -24,6 +24,7 @@ namespace placeholdervo
private static ConcurrentQueue<string> scriptFragmentFiles = new ConcurrentQueue<string>(); private static ConcurrentQueue<string> scriptFragmentFiles = new ConcurrentQueue<string>();
private static ConcurrentQueue<string> titleCardLines = new ConcurrentQueue<string>(); private static ConcurrentQueue<string> titleCardLines = new ConcurrentQueue<string>();
private static ConcurrentDictionary<string, string> filePickups = new ConcurrentDictionary<string, string>();
private static CancellationToken scriptFileCancellationToken; private static CancellationToken scriptFileCancellationToken;
//from when I cut it up into separate files //from when I cut it up into separate files
@ -71,50 +72,48 @@ namespace placeholdervo
// } // }
// } // }
// private static async void filePickup() ///<summary>mostly just to give myself the reminder about paths</summary>
// { ///<param name="src">the *complete path* of the awaited file. you might want conf.sync_dropoff</param>
// while(true) ///<param name="dest">the *complete path* to move the file to.</param>
// { private static async void awaitFile(string src, string dest)
// while(!scriptFragmentVoiceFiles.IsEmpty) {
// { filePickups[src] = dest;
// var files = Directory.GetFiles(conf.sync_dropoff); }
// Console.WriteLine($"files listed: {string.Join(", ", files)}"); private static async void filePickup()
// Console.WriteLine($"hoping for: {string.Join(", ", scriptFragmentVoiceFiles.Keys)}"); {
// // Console.WriteLine($"sanity check: first listed file: {Path.GetFileName(files.FirstOrDefault())}"); while(true)
// // Console.WriteLine($"sanity check: first key: {scriptFragmentVoiceFiles.Keys.FirstOrDefault()}"); {
// // Console.WriteLine($"sanity check: first value: {scriptFragmentVoiceFiles[scriptFragmentVoiceFiles.Keys.FirstOrDefault()]}"); foreach(var srcKey in filePickups.Keys)
// var audioFile = files.FirstOrDefault(f => scriptFragmentVoiceFiles.ContainsKey(Path.GetFileName(f))); {
// if(!string.IsNullOrWhiteSpace(audioFile)) // var files = Directory.GetFiles(conf.sync_dropoff);
// { // Console.WriteLine($"files listed: {string.Join(", ", files)}");
// Console.WriteLine($"found {audioFile}"); // Console.WriteLine($"hoping for: {string.Join(", ", filePickups.Keys)}");
// try // Console.WriteLine($"sanity check: first listed file: {Path.GetFileName(files.FirstOrDefault())}");
// { // Console.WriteLine($"sanity check: first key: {scriptFragmentVoiceFiles.Keys.FirstOrDefault()}");
// var bareAudioFile = Path.GetFileName(audioFile); // Console.WriteLine($"sanity check: first value: {scriptFragmentVoiceFiles[scriptFragmentVoiceFiles.Keys.FirstOrDefault()]}");
// var destFile = scriptFragmentVoiceFiles[bareAudioFile]; if(File.Exists(srcKey))
// destFile = Path.GetFileNameWithoutExtension(destFile) + ".wav"; {
// destFile = Path.Combine(workingDir, destFile); Console.WriteLine($"found {srcKey}");
// File.Move(audioFile, destFile); string dest;
if (filePickups.TryRemove(srcKey, out dest))
{
File.Move(srcKey, dest);
}
else
{
Console.Error.WriteLine($"Failed to remove {srcKey} from filepickups. Unrecoverable, I think.");
Environment.Exit(-1);
}
}
}
if(scriptFileCancellationToken.IsCancellationRequested)
{
return;
}
// if(!scriptFragmentVoiceFiles.Remove(bareAudioFile, out string throwaway)) System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
// { }
// Console.WriteLine($"failed to remove {bareAudioFile}"); }
// }
// }
// catch(Exception e)
// {
// Console.Error.WriteLine(e.Message);
// }
// }
// System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
// }
// if(scriptFileCancellationToken.IsCancellationRequested)
// {
// return;
// }
// System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
// }
// }
public static async Task Main(string[] args) public static async Task Main(string[] args)
{ {
@ -264,9 +263,9 @@ namespace placeholdervo
} }
// execute them all // execute them all
// Task.Run(OfflineStuff); //e.g., generate title cards and credits //Task.Run(OfflineStuff);
// Task.Run(ApiCalls); //e.g. generate voice //Task.Run(ApiCalls);
// await Task.Run(FilePickups); var fpTask = Task.Run(filePickup);
// cancelSource.Cancel(); // cancelSource.Cancel();
// Console.WriteLine("http client \"cancelled\"."); // Console.WriteLine("http client \"cancelled\".");