From 367406901cd4a4f09b673c6f51950d04490bbe1a Mon Sep 17 00:00:00 2001 From: CodeConscious <50596087+codeconscious@users.noreply.github.com> Date: Mon, 10 Aug 2026 18:25:57 +0900 Subject: [PATCH 1/5] Rework sleep conditions --- src/CCVTAC.Main/Orchestrator.fs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/CCVTAC.Main/Orchestrator.fs b/src/CCVTAC.Main/Orchestrator.fs index 96749ba..567dd1c 100644 --- a/src/CCVTAC.Main/Orchestrator.fs +++ b/src/CCVTAC.Main/Orchestrator.fs @@ -61,16 +61,6 @@ module Orchestrator = printer.Error err Ok { NextAction = NextAction.QuitDueToErrors; UpdatedSettings = None } | Ok () -> - if urlIndex > 1 then // Don't sleep for the first URL. - settings.SleepSecondsBetweenURLs - |> String.pluralizeS "second" - |> fun secondsLabel -> - sleep - (fun seconds -> $"Sleeping for {seconds} {secondsLabel}...") - (fun seconds -> $"Slept for {seconds} {secondsLabel}.") - settings.SleepSecondsBetweenURLs - |> fun msg -> printer.Info($"{String.newLine}{msg}", appendLines = 1uy) - if batchSize > 1 then printer.Info $"Processing item %d{urlIndex} of %d{batchSize}..." @@ -225,11 +215,24 @@ module Orchestrator = let mutable nextAction = NextAction.Continue let mutable currentSettings = settings + let sleep (category: InputCategory) = + if category.IsUrl then + settings.SleepSecondsBetweenURLs + |> String.pluralizeS "second" + |> fun secondsLabel -> + sleep + (fun seconds -> $"Sleeping for {seconds} {secondsLabel}...") + (fun seconds -> $"Slept for {seconds} {secondsLabel}.") + settings.SleepSecondsBetweenURLs + |> fun msg -> printer.Info($"{String.newLine}{msg}", appendLines = 1uy) + use e = (Seq.ofList categorizedInputs).GetEnumerator() + let _ = e.MoveNext() + let mutable inputIndex = 1 let mutable stop = false - while not stop && e.MoveNext() do + while not stop do let input = e.Current let result = @@ -245,7 +248,13 @@ module Orchestrator = match result with | Error err -> printer.Error err + if e.MoveNext() + then sleep input.Category + else stop <- true | Ok result -> + if e.MoveNext() + then sleep input.Category + else stop <- true nextAction <- result.NextAction match result.UpdatedSettings with | None -> () From 5202f02e0417711dd385ee267a1c41bc02125f80 Mon Sep 17 00:00:00 2001 From: CodeConscious <50596087+codeconscious@users.noreply.github.com> Date: Mon, 10 Aug 2026 20:21:49 +0900 Subject: [PATCH 2/5] Functional refactor [AI] --- src/CCVTAC.Main/Orchestrator.fs | 117 ++++++++++++++------------------ 1 file changed, 51 insertions(+), 66 deletions(-) diff --git a/src/CCVTAC.Main/Orchestrator.fs b/src/CCVTAC.Main/Orchestrator.fs index 567dd1c..a30d77a 100644 --- a/src/CCVTAC.Main/Orchestrator.fs +++ b/src/CCVTAC.Main/Orchestrator.fs @@ -59,7 +59,7 @@ module Orchestrator = match Directories.warnIfAnyFiles 10 settings.WorkingDirectory with | Error err -> printer.Error err - Ok { NextAction = NextAction.QuitDueToErrors; UpdatedSettings = None } + Ok { NextAction = QuitDueToErrors; UpdatedSettings = None } | Ok () -> if batchSize > 1 then printer.Info $"Processing item %d{urlIndex} of %d{batchSize}..." @@ -82,10 +82,10 @@ module Orchestrator = | Error errs -> errs |> List.map (sprintf "Media download error: %s") - |> String.concat String.newLine + |> String.concat String.nl |> Error | Ok message -> - printer.Debug "Media download(s) successful!" + printer.Debug "Download successful." if String.hasText message then printer.Info message PostProcessor.run settings mediaType printer @@ -95,9 +95,7 @@ module Orchestrator = else String.Empty printer.Info $"Processed '%s{url}'%s{groupClause} in %s{jobWatch.ElapsedFriendly}." - - Ok { NextAction = NextAction.Continue - UpdatedSettings = None } + Ok { NextAction = Continue; UpdatedSettings = None } let summarizeToggle settingName setting = sprintf "%s was toggled to %s for this session." settingName (if setting then "ON" else "OFF") @@ -212,73 +210,60 @@ module Orchestrator = let inputTime = DateTime.Now let watch = Watch() let batchResults = ResultTracker printer - let mutable nextAction = NextAction.Continue - let mutable currentSettings = settings - let sleep (category: InputCategory) = + let printSleep (category: InputCategory) = if category.IsUrl then - settings.SleepSecondsBetweenURLs - |> String.pluralizeS "second" - |> fun secondsLabel -> - sleep - (fun seconds -> $"Sleeping for {seconds} {secondsLabel}...") - (fun seconds -> $"Slept for {seconds} {secondsLabel}.") - settings.SleepSecondsBetweenURLs - |> fun msg -> printer.Info($"{String.newLine}{msg}", appendLines = 1uy) - - use e = (Seq.ofList categorizedInputs).GetEnumerator() - let _ = e.MoveNext() - - let mutable inputIndex = 1 - let mutable stop = false - - while not stop do - let input = e.Current - - let result = - match input.Category with - | InputCategory.Command -> - processCommand input.Text currentSettings history printer - | InputCategory.Url -> - processUrl input.Text currentSettings resultTracker history inputTime - categoryCounts[InputCategory.Url] inputIndex printer - - batchResults.RegisterResult(input.Text, result) - - match result with - | Error err -> - printer.Error err - if e.MoveNext() - then sleep input.Category - else stop <- true - | Ok result -> - if e.MoveNext() - then sleep input.Category - else stop <- true - nextAction <- result.NextAction - match result.UpdatedSettings with - | None -> () - | Some us -> currentSettings <- us - if nextAction <> NextAction.Continue then - stop <- true - inputIndex <- inputIndex + 1 - - if categoryCounts[InputCategory.Url] > 1 then - printer.Info(sprintf "%sFinished with batch of %d URLs in %s." - String.newLine - categoryCounts[InputCategory.Url] - watch.ElapsedFriendly) + let seconds = settings.SleepSecondsBetweenURLs + let label = String.pluralizeS "second" seconds + sleep + (fun s -> $"Sleeping for {s} {label}...") + (fun s -> $"Slept for {s} {label}.") + seconds + |> fun msg -> printer.Info($"{String.nl}{msg}", appendLines = 1uy) + + let processInput category text index = + match category with + | Command -> processCommand text settings history printer + | Url -> processUrl text settings resultTracker history inputTime categoryCounts[Url] index printer + + let rec loop inputs settings' nextAction' index = + match inputs with + | [] -> (nextAction', settings', index) + | input :: rest when nextAction' = NextAction.Continue -> + let result = processInput input.Category input.Text index + batchResults.RegisterResult(input.Text, result) + + match result with + | Error err -> + printer.Error err + if List.isNotEmpty rest then + printSleep input.Category + loop rest settings' nextAction' (index + 1) + | Ok processResult -> + if List.isNotEmpty rest then + printSleep input.Category + let settings'' = processResult.UpdatedSettings |> Option.defaultValue settings' + let nextAction'' = processResult.NextAction + loop rest settings'' nextAction'' (index + 1) + | _ -> + (nextAction', settings', index) + + let (finalNextAction, finalSettings, processedCount) = + loop categorizedInputs settings Continue 1 + + if categoryCounts[Url] > 1 then + printer.Info(sprintf "%sFinished with batch of %d URLs in %s." String.nl categoryCounts[Url] watch.ElapsedFriendly) batchResults.PrintBatchFailures() - if inputIndex < categorizedInputs.Length then + if processedCount <= categorizedInputs.Length then let unprocessedInputs = - categorizedInputs[inputIndex-1..] + categorizedInputs[processedCount-1..] |> List.map (fun x -> $"• {x.Text}") - |> String.concat String.newLine - printer.Warning($"Some inputs were not yet processed: {String.newLine}{unprocessedInputs}") + |> String.concat String.nl + printer.Warning($"Some inputs were not yet processed: {String.nl}{unprocessedInputs}") - { NextAction = nextAction - UpdatedSettings = Some currentSettings } + { NextAction = finalNextAction + UpdatedSettings = Some finalSettings } /// Ensures the download environment is ready, then initiates the input and download process. let start (settings: UserSettings) (printer: Printer) : unit = From 12f74163eafb8ef077fcf189149d7ff07b939398 Mon Sep 17 00:00:00 2001 From: CodeConscious <50596087+codeconscious@users.noreply.github.com> Date: Tue, 11 Aug 2026 10:21:48 +0900 Subject: [PATCH 3/5] Rename variables --- src/CCVTAC.Main/Orchestrator.fs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/CCVTAC.Main/Orchestrator.fs b/src/CCVTAC.Main/Orchestrator.fs index a30d77a..5fa53be 100644 --- a/src/CCVTAC.Main/Orchestrator.fs +++ b/src/CCVTAC.Main/Orchestrator.fs @@ -208,7 +208,7 @@ module Orchestrator = : BatchResults = let inputTime = DateTime.Now - let watch = Watch() + let batchWatch = Watch() let batchResults = ResultTracker printer let printSleep (category: InputCategory) = @@ -228,23 +228,22 @@ module Orchestrator = let rec loop inputs settings' nextAction' index = match inputs with - | [] -> (nextAction', settings', index) - | input :: rest when nextAction' = NextAction.Continue -> + | [] -> + (nextAction', settings', index) + | input :: remainingInputs when nextAction' = Continue -> let result = processInput input.Category input.Text index batchResults.RegisterResult(input.Text, result) match result with | Error err -> printer.Error err - if List.isNotEmpty rest then - printSleep input.Category - loop rest settings' nextAction' (index + 1) + if List.isNotEmpty remainingInputs then printSleep input.Category + loop remainingInputs settings' nextAction' (index + 1) | Ok processResult -> - if List.isNotEmpty rest then - printSleep input.Category - let settings'' = processResult.UpdatedSettings |> Option.defaultValue settings' - let nextAction'' = processResult.NextAction - loop rest settings'' nextAction'' (index + 1) + if List.isNotEmpty remainingInputs then printSleep input.Category + let newSettings = processResult.UpdatedSettings |> Option.defaultValue settings' + let newNextAction = processResult.NextAction + loop remainingInputs newSettings newNextAction (index + 1) | _ -> (nextAction', settings', index) @@ -252,7 +251,7 @@ module Orchestrator = loop categorizedInputs settings Continue 1 if categoryCounts[Url] > 1 then - printer.Info(sprintf "%sFinished with batch of %d URLs in %s." String.nl categoryCounts[Url] watch.ElapsedFriendly) + printer.Info(sprintf "%sFinished with batch of %d URLs in %s." String.nl categoryCounts[Url] batchWatch.ElapsedFriendly) batchResults.PrintBatchFailures() if processedCount <= categorizedInputs.Length then @@ -260,7 +259,7 @@ module Orchestrator = categorizedInputs[processedCount-1..] |> List.map (fun x -> $"• {x.Text}") |> String.concat String.nl - printer.Warning($"Some inputs were not yet processed: {String.nl}{unprocessedInputs}") + printer.Warning $"Some inputs were not yet processed: {String.nl}{unprocessedInputs}" { NextAction = finalNextAction UpdatedSettings = Some finalSettings } From 739f95dc035f508416ae4302a81e4caba8888918 Mon Sep 17 00:00:00 2001 From: CodeConscious <50596087+codeconscious@users.noreply.github.com> Date: Wed, 12 Aug 2026 09:37:34 +0900 Subject: [PATCH 4/5] Change message's log level --- src/CCVTAC.Main/PostProcessing/Tagging/Tagger.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CCVTAC.Main/PostProcessing/Tagging/Tagger.fs b/src/CCVTAC.Main/PostProcessing/Tagging/Tagger.fs index 5a0bcfc..775a640 100644 --- a/src/CCVTAC.Main/PostProcessing/Tagging/Tagger.fs +++ b/src/CCVTAC.Main/PostProcessing/Tagging/Tagger.fs @@ -161,7 +161,7 @@ module Tagger = if settings.EmbedImages && settings.DoNotEmbedImageUploaders |> List.doesNotContain videoData.Uploader then - printer.Info "Embedding artwork..." + printer.Debug "Embedding artwork..." writeImageToFile taggedFile path printer else printer.Debug "Skipping artwork embedding." From dcf3b869d744266f682922d0c8ef9b2251eb74c4 Mon Sep 17 00:00:00 2001 From: CodeConscious <50596087+codeconscious@users.noreply.github.com> Date: Wed, 12 Aug 2026 17:16:19 +0900 Subject: [PATCH 5/5] Minor code tweaks --- src/CCVTAC.Main/Orchestrator.fs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/CCVTAC.Main/Orchestrator.fs b/src/CCVTAC.Main/Orchestrator.fs index 5fa53be..27470a9 100644 --- a/src/CCVTAC.Main/Orchestrator.fs +++ b/src/CCVTAC.Main/Orchestrator.fs @@ -221,7 +221,7 @@ module Orchestrator = seconds |> fun msg -> printer.Info($"{String.nl}{msg}", appendLines = 1uy) - let processInput category text index = + let processInput category text index : Result = match category with | Command -> processCommand text settings history printer | Url -> processUrl text settings resultTracker history inputTime categoryCounts[Url] index printer @@ -251,7 +251,12 @@ module Orchestrator = loop categorizedInputs settings Continue 1 if categoryCounts[Url] > 1 then - printer.Info(sprintf "%sFinished with batch of %d URLs in %s." String.nl categoryCounts[Url] batchWatch.ElapsedFriendly) + printer.Info( + sprintf "%sFinished with batch of %d URLs in %s." + String.nl + categoryCounts[Url] + batchWatch.ElapsedFriendly + ) batchResults.PrintBatchFailures() if processedCount <= categorizedInputs.Length then