Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CCVTAC.Main/CCVTAC.Main.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CCFSharpUtils" Version="0.1.19" />
<PackageReference Include="CCFSharpUtils" Version="0.1.41" />
<PackageReference Include="CodeConscious.Startwatch" Version="1.0.0" />
<PackageReference Include="FSharpPlus" Version="1.9.1" />
<PackageReference Include="FsToolkit.ErrorHandling" Version="5.1.0" />
<PackageReference Include="FsToolkit.ErrorHandling" Version="5.2.0" />
<PackageReference Include="Spectre.Console" Version="0.54.0" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Update="FSharp.Core" Version="10.0.102" />
<PackageReference Update="FSharp.Core" Version="10.1.201" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/CCVTAC.Main/Orchestrator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}...")
Expand Down
28 changes: 13 additions & 15 deletions src/CCVTAC.Main/PostProcessing/Tagging/TaggingSet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module TaggingSet =
JsonFile = j
ImageFile = i }

let private createValidated (videoId, files) : Result<TaggingSet, string list> =
let private createValidated (videoId, fileNames) : Result<TaggingSet, string list> =
let ensureNotEmpty xs errorMsg : Validation<'a list, string> =
if List.isNotEmpty xs
then Ok xs
Expand All @@ -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)
Expand All @@ -70,25 +70,23 @@ module TaggingSet =
/// Any validation errors will be accumulated and return in an Error.
let createSets filePaths : Result<TaggingSet list, string list> =
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
6 changes: 3 additions & 3 deletions src/CCVTAC.Main/ResultTracker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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}."

Expand Down
9 changes: 5 additions & 4 deletions src/CCVTAC.Main/Settings/Settings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -129,7 +129,7 @@ module Settings =

Printer.PrintTable table

module Validation =
module Validation' =
open System.IO

let validate settings =
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -208,7 +209,7 @@ module Settings =
writeFile fileInfo defaultSettings

module LiveUpdating =
open Validation
open Validation'

let toggleSplitChapters settings =
{ settings with SplitChapters = not settings.SplitChapters }
Expand Down
8 changes: 4 additions & 4 deletions src/CCVTAC.Tests/CCVTAC.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CCFSharpUtils" Version="0.1.19" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="CCFSharpUtils" Version="0.1.41" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PackageReference Include="coverlet.collector" Version="8.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Update="FSharp.Core" Version="10.0.102" />
<PackageReference Update="FSharp.Core" Version="10.1.201" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CCVTAC.Main\CCVTAC.Main.fsproj" />
Expand Down
Loading