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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ The first incarnation of this application was written in C#. However, after pick

As an experiment, I rewrote this application in OOP-style F#, using LLMs solely for the rough initial conversion (which greatly reduced the overall time and labor necessary at the cost of requiring a *lot* of manual cleanup). Ultimately, I was surprised how much I preferred the F# code over the C#, so I decided to keep this tool in F#.

Due to this background, the code is not particularly idiomatic F#, but it is perfectly viable in its current blended-style form. That said, I'll probably tweak it over time to gradually to introduce more FP, mainly for practice.
Due to this background, the code is not particularly idiomatic F#, but it is certainly perfectly viable in its current blended-style form. That said, I'll probably tweak it over time to gradually to introduce more idiomatic F# code.
2 changes: 1 addition & 1 deletion src/CCVTAC.Main/CCVTAC.Main.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Shared.fs" />
<Compile Include="Extensions.fs" />
<Compile Include="Printer.fs" />
<Compile Include="IoUtilities\Directories.fs" />
<Compile Include="IoUtilities\Files.fs" />
Expand Down Expand Up @@ -41,6 +40,7 @@
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CCFSharpUtils" Version="0.1.5" />
<PackageReference Include="CodeConscious.Startwatch" Version="1.0.0" />
<PackageReference Include="FSharpPlus" Version="1.8.0" />
<PackageReference Include="FsToolkit.ErrorHandling" Version="5.1.0" />
Expand Down
1 change: 1 addition & 0 deletions src/CCVTAC.Main/Commands.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace CCVTAC.Main

open CCFSharpUtils.Library
open System

module Commands =
Expand Down
3 changes: 2 additions & 1 deletion src/CCVTAC.Main/Downloading/Updater.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace CCVTAC.Main.Downloading

open CCVTAC.Main.ExternalTools
open CCVTAC.Main
open CCVTAC.Main.ExternalTools
open CCVTAC.Main.Settings.Settings
open CCFSharpUtils.Library

module Updater =

Expand Down
167 changes: 0 additions & 167 deletions src/CCVTAC.Main/Extensions.fs

This file was deleted.

1 change: 1 addition & 0 deletions src/CCVTAC.Main/ExternalTools/Runner.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CCVTAC.Main.ExternalTools

open CCVTAC.Main
open CCFSharpUtils.Library
open Startwatch.Library
open System
open System.Diagnostics
Expand Down
1 change: 1 addition & 0 deletions src/CCVTAC.Main/History.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CCVTAC.Main

open CCVTAC.Main.IoUtilities.Files
open CCFSharpUtils.Library
open System
open System.IO
open System.Text.Json
Expand Down
6 changes: 4 additions & 2 deletions src/CCVTAC.Main/IoUtilities/Directories.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace CCVTAC.Main.IoUtilities

open CCVTAC.Main
open CCFSharpUtils.Library
open System.IO
open System.Text

module Directories =

Expand All @@ -11,7 +13,7 @@ module Directories =
/// Counts the number of audio files in a directory.
let audioFileCount (directory: string) (includedExtensions: string list) =
DirectoryInfo(directory).EnumerateFiles()
|> Seq.filter (fun f -> List.caseInsensitiveContains f.Extension includedExtensions)
|> Seq.filter (fun f -> List.containsIgnoreCase f.Extension includedExtensions)
|> Seq.length

/// Returns the filenames in a given directory, optionally ignoring specific filenames.
Expand Down Expand Up @@ -71,7 +73,7 @@ module Directories =
if Array.isEmpty fileNames then
Ok ()
else
SB($"Unexpectedly found {String.fileLabel fileNames.Length} in working directory \"{dirName}\":{String.newLine}")
StringBuilder($"Unexpectedly found {String.fileLabel fileNames.Length} in working directory \"{dirName}\":{String.newLine}")
.AppendLine
(fileNames
|> Array.truncate showMax
Expand Down
5 changes: 3 additions & 2 deletions src/CCVTAC.Main/IoUtilities/Files.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace CCVTAC.Main.IoUtilities

open System.IO
open CCVTAC.Main
open CCFSharpUtils.Library
open System.IO

module Files =

Expand All @@ -13,7 +14,7 @@ module Files =

let imageFileExts = [".jpg"; ".jpeg"]

let filterByExt ext fs = fs |> List.filter (String.endsWith ext)
let filterByExt ext fs = fs |> List.filter (String.endsWithIgnoreCase ext)

let readAllText (filePath: string) : Result<string, string> =
ofTry (fun _ -> File.ReadAllText filePath)
Expand Down
9 changes: 5 additions & 4 deletions src/CCVTAC.Main/Orchestrator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open CCVTAC.Main.PostProcessing
open CCVTAC.Main.Settings
open CCVTAC.Main.Settings.Settings
open CCVTAC.Main.Settings.Settings.LiveUpdating
open CCFSharpUtils.Library
open Startwatch.Library
open System

Expand Down Expand Up @@ -120,10 +121,10 @@ module Orchestrator =
(printer: Printer)
: Result<BatchResults, string> =

let checkCommand = List.caseInsensitiveContains command
let checkCommand = List.containsIgnoreCase command

// Help
if String.equalIgnoringCase Commands.helpCommand command then
if String.equalIgnoreCase Commands.helpCommand command then
for kvp in Commands.summary do
printer.Info(kvp.Key)
printer.Info $" %s{kvp.Value}"
Expand Down Expand Up @@ -168,7 +169,7 @@ module Orchestrator =
Ok { NextAction = NextAction.Continue; UpdatedSettings = Some newSettings }

// Update audio formats
elif command |> String.startsWith Commands.updateAudioFormatPrefix then
elif command |> String.startsWithIgnoreCase Commands.updateAudioFormatPrefix then
let format = command.Replace(Commands.updateAudioFormatPrefix, String.Empty).ToLowerInvariant()
if String.hasNoText format then
Error "You must append one or more supported audio formats separated by commas (e.g., \"m4a,opus,best\")."
Expand All @@ -181,7 +182,7 @@ module Orchestrator =
Ok { NextAction = NextAction.Continue; UpdatedSettings = Some newSettings }

// Update audio quality
elif command |> String.startsWith Commands.updateAudioQualityPrefix then
elif command |> String.startsWithIgnoreCase Commands.updateAudioQualityPrefix then
let inputQuality = command.Replace(Commands.updateAudioQualityPrefix, String.Empty)
if String.hasNoText inputQuality then
Error "You must enter a number representing an audio quality between 10 (lowest) and 0 (highest)."
Expand Down
5 changes: 3 additions & 2 deletions src/CCVTAC.Main/PostProcessing/Deleter.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CCVTAC.Main.PostProcessing

open CCVTAC.Main
open CCFSharpUtils.Library
open System.IO

module Deleter =
Expand Down Expand Up @@ -35,7 +36,7 @@ module Deleter =
let collectionFileNames =
match getCollectionFiles collectionMetadata workingDirectory with
| Ok files ->
printer.Debug $"""Found {String.fileLabelWithDescriptor "collection" files.Length}."""
printer.Debug $"""Found {String.fileLabelWithDesc "collection" files.Length}."""
files
| Error err ->
printer.Warning err
Expand All @@ -46,6 +47,6 @@ module Deleter =
if Array.isEmpty allFileNames then
printer.Warning "No files to delete were found."
else
printer.Debug $"""Deleting {String.fileLabelWithDescriptor "temporary" allFileNames.Length}..."""
printer.Debug $"""Deleting {String.fileLabelWithDesc "temporary" allFileNames.Length}..."""
deleteAll allFileNames printer
printer.Info "Deleted temporary files."
10 changes: 6 additions & 4 deletions src/CCVTAC.Main/PostProcessing/MetadataUtilities.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace CCVTAC.Main.PostProcessing

open CCVTAC.Main
open CCFSharpUtils.Library
open System
open System.Text
open CCVTAC.Main

module MetadataUtilities =

Expand All @@ -20,7 +21,7 @@ module MetadataUtilities =
sprintf "%s/%s/%s" m d y

let generateComment (v: VideoMetadata) (c: CollectionMetadata option) : string =
let sb = SB()
let sb = StringBuilder()
sb.AppendLine("CCVTAC SOURCE DATA:") |> ignore
sb.AppendLine $"■ Downloaded: {DateTime.Now}" |> ignore
sb.AppendLine $"■ URL: %s{v.WebpageUrl}" |> ignore
Expand All @@ -42,7 +43,7 @@ module MetadataUtilities =
if v.UploadDate.Length = 8 then
sb.AppendLine $"■ Uploaded: %s{formattedUploadDate v.UploadDate}" |> ignore

let description = String.textOrFallback "None." v.Description
let description = String.textElse "None." v.Description
sb.AppendLine $"■ Video description: %s{description}" |> ignore

match c with
Expand All @@ -53,7 +54,8 @@ module MetadataUtilities =
match v.PlaylistIndex with
| Some index -> if index > 0u then sb.AppendLine $"■ Playlist index: %d{index}" |> ignore
| None -> ()
sb.AppendLine($"■ Playlist description: %s{String.textOrEmpty c'.Description}") |> ignore
if String.hasText c'.Description then
sb.AppendLine($"■ Playlist description: %s{c'.Description}") |> ignore
| None -> ()

sb.ToString()
Loading