diff --git a/src/CCVTAC.Main/CCVTAC.Main.fsproj b/src/CCVTAC.Main/CCVTAC.Main.fsproj index ef0212a..a99b120 100644 --- a/src/CCVTAC.Main/CCVTAC.Main.fsproj +++ b/src/CCVTAC.Main/CCVTAC.Main.fsproj @@ -40,12 +40,12 @@ - + - + - + diff --git a/src/CCVTAC.Main/Orchestrator.fs b/src/CCVTAC.Main/Orchestrator.fs index f0969f9..60e4e00 100644 --- a/src/CCVTAC.Main/Orchestrator.fs +++ b/src/CCVTAC.Main/Orchestrator.fs @@ -29,8 +29,8 @@ module Orchestrator = : unit = if List.hasMultiple categorizedInputs then - let urlSummary = String.pluralizeWithCount "URL" "URLs" counts[InputCategory.Url] - let cmdSummary = String.pluralizeWithCount "command" "commands" counts[InputCategory.Command] + let urlSummary = String.pluralizeSWithCount "URL" counts[InputCategory.Url] + let cmdSummary = String.pluralizeSWithCount "command" counts[InputCategory.Command] printer.Info <| match counts[InputCategory.Url], counts[InputCategory.Command] with @@ -62,7 +62,7 @@ module Orchestrator = | Ok () -> if urlIndex > 1 then // Don't sleep for the first URL. settings.SleepSecondsBetweenURLs - |> String.pluralize "second" "seconds" + |> String.pluralizeS "second" |> fun secondsLabel -> sleep (fun seconds -> $"Sleeping for {seconds} {secondsLabel}...") diff --git a/src/CCVTAC.Main/PostProcessing/Tagging/TaggingSet.fs b/src/CCVTAC.Main/PostProcessing/Tagging/TaggingSet.fs index 90e4ca7..100a81b 100644 --- a/src/CCVTAC.Main/PostProcessing/Tagging/TaggingSet.fs +++ b/src/CCVTAC.Main/PostProcessing/Tagging/TaggingSet.fs @@ -30,7 +30,7 @@ module TaggingSet = JsonFile = j ImageFile = i } - let private createValidated (videoId, files) : Result = + let private createValidated (videoId, fileNames) : Result = let ensureNotEmpty xs errorMsg : Validation<'a list, string> = if List.isNotEmpty xs then Ok xs @@ -48,11 +48,11 @@ module TaggingSet = | NonNull empty when String.hasNoText empty -> false | NonNull ext -> Files.audioFileExts |> List.containsIgnoreCase ext - let audioFiles = files |> List.filter hasSupportedAudioExt - let jsonFiles = files |> Files.filterByExt Files.jsonFileExt + let audioFiles = fileNames |> List.filter hasSupportedAudioExt + let jsonFiles = fileNames |> Files.filterByExt Files.jsonFileExt let imageFiles = Files.imageFileExts - |> List.collect (fun ext -> files |> Files.filterByExt ext) + |> List.collect (fun ext -> fileNames |> Files.filterByExt ext) Validation.map3 (fun a j i -> create videoId a j i) @@ -70,25 +70,23 @@ module TaggingSet = /// Any validation errors will be accumulated and return in an Error. let createSets filePaths : Result = if Seq.isEmpty filePaths then - Error ["No filepaths to create a tagging set were provided."] + Error ["No file paths to create a tagging set were provided."] else - let isRelevantFile fileName = + let isRelevantFile fileName : Match option = // Regex group 0 is the full filename, and group 1 contains the video ID. - let fileNamesHavingVideoIdsRegex = + let fileNamesHavingVideoIdsRgx = Regex(@".+\[([\w_\-]{11})\](?:.*)?\.(\w+)", RegexOptions.Compiled) - Rgx.trySuccessMatch fileNamesHavingVideoIdsRegex fileName + fileName |> Rgx.trySuccessMatch fileNamesHavingVideoIdsRgx - let extractFileNameMatch = Rgx.fstCapture - - let extractFileNames (x, matches: Match list) : 'a * string list = - x, matches |> List.map _.Groups[0].Value + let fileName (m: Match) = m.Groups[0].Value + let videoId (m: Match) = m.Groups[1].Value filePaths |> List.ofSeq |> List.choose isRelevantFile - |> List.map extractFileNameMatch - |> List.groupBy _.Groups[1].Value // By video ID - |> List.map (extractFileNames >> createValidated) + |> List.groupBy videoId + |> List.mapSnd fileName + |> List.map createValidated |> List.sequenceResultA |! List.collect id diff --git a/src/CCVTAC.Main/ResultTracker.fs b/src/CCVTAC.Main/ResultTracker.fs index ff717b2..8a7f4b5 100644 --- a/src/CCVTAC.Main/ResultTracker.fs +++ b/src/CCVTAC.Main/ResultTracker.fs @@ -43,15 +43,15 @@ type ResultTracker<'a>(printer: Printer) = if Num.isZero failures.Count then printer.Debug "No failures in batch." else - let failureLabel = String.pluralize "failure" "failures" failures.Count + let failureLabel = String.pluralizeS "failure" failures.Count printer.Info $"%d{failures.Count} %s{failureLabel} in this batch:" for pair in failures do printer.Warning $"- %s{pair.Key}: %s{pair.Value}" /// Prints the output for the current application session. member _.PrintSessionSummary() : unit = - let successLabel = String.pluralize "success" "successes" successCount - let failureLabel = String.pluralize "failure" "failures" failures.Count + let successLabel = String.pluralizeEs "success" successCount + let failureLabel = String.pluralizeS "failure" failures.Count printer.Info $"Quitting with %d{successCount} %s{successLabel} and %d{failures.Count} %s{failureLabel}." diff --git a/src/CCVTAC.Main/Settings/Settings.fs b/src/CCVTAC.Main/Settings/Settings.fs index e0fa905..6ded58d 100644 --- a/src/CCVTAC.Main/Settings/Settings.fs +++ b/src/CCVTAC.Main/Settings/Settings.fs @@ -84,7 +84,7 @@ module Settings = | false -> "OFF" let simplePluralize label count = - String.pluralize label $"{label}s" count + String.pluralizeS label count |> sprintf "%d %s" count let tagDetectionPatternCount (patterns: TagDetectionPatterns) = @@ -129,7 +129,7 @@ module Settings = Printer.PrintTable table - module Validation = + module Validation' = open System.IO let validate settings = @@ -163,16 +163,17 @@ module Settings = Ok settings module IO = + open Validation' open System.IO open System.Text.Json open System.Text.Unicode open System.Text.Encodings.Web - open Validation let deserialize<'a> (json: string) : Result<'a, string> = let options = JsonSerializerOptions() options.AllowTrailingCommas <- true options.ReadCommentHandling <- JsonCommentHandling.Skip + options.AllowDuplicateProperties <- false try match JsonSerializer.Deserialize<'a>(json, options) with | null -> Error "Could not deserialize the settings JSON" @@ -208,7 +209,7 @@ module Settings = writeFile fileInfo defaultSettings module LiveUpdating = - open Validation + open Validation' let toggleSplitChapters settings = { settings with SplitChapters = not settings.SplitChapters } diff --git a/src/CCVTAC.Tests/CCVTAC.Tests.fsproj b/src/CCVTAC.Tests/CCVTAC.Tests.fsproj index 48b79b1..d868ec7 100644 --- a/src/CCVTAC.Tests/CCVTAC.Tests.fsproj +++ b/src/CCVTAC.Tests/CCVTAC.Tests.fsproj @@ -14,18 +14,18 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - +