Skip to content

Commit 36a491e

Browse files
committed
Added the details command.
See README for details.
1 parent 3bc9b0d commit 36a491e

File tree

6 files changed

+55
-7
lines changed

6 files changed

+55
-7
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ comment
260260
```
261261
To preview the changes add the `-d` (dry run) parameter.
262262

263+
Details
264+
-------
265+
```bash
266+
./fbrary -l $LIBRARY_FILENAME details 1 2 ...
267+
```
268+
Writes all available information to the terminal. Fields that are empty are represented as `-`. A rating of `-1` means that none has been set.
269+
263270
Hints
264271
=====
265272

snapcraft/snap/snapcraft.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: fbrary
22
base: core20
3-
version: '2.1.1'
3+
version: '2.1.2'
44
summary: Manage your audio book library from the command line.
55
description: |
66
Use this tool to manage your audiobook library from the

src/cli/Arguments.fs

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ module Arguments =
103103
| [<CliPrefix(CliPrefix.None)>] Unmatched of string
104104
| [<CliPrefix(CliPrefix.None)>] Write of ParseResults<WriteArgs>
105105
| [<CliPrefix(CliPrefix.None)>] Migrate
106+
| [<CliPrefix(CliPrefix.None)>] Details of int list
106107
| [<CliPrefix(CliPrefix.DoubleDash); First>] Version
107108
interface IArgParserTemplate with
108109
member s.Usage =
@@ -121,5 +122,6 @@ module Arguments =
121122
| Unmatched _ -> "Reads all mp3/ogg files in the given paths and checks if all files are known to the library."
122123
| Write _ -> "Write the meta data stored in the library to the actual mp3/ogg files."
123124
| Migrate -> "Migrate an old library file to the current format."
125+
| Details _ -> "List the complete details (including files) for the given audio books."
124126
| Version -> "Echo the version of this software."
125127

src/cli/Audiobook.fs

+25-1
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,28 @@ module Audiobook =
216216
let allFiles (a: Audiobook) : string list =
217217
match a.Source with
218218
| SingleFile s -> [ s ]
219-
| MultiFile m -> m
219+
| MultiFile m -> m
220+
221+
let details (a: Audiobook) : string list =
222+
let formatDuration (t: TimeSpan) = t.ToString("h\:mm")
223+
let formatBool = function true -> "yes" | false -> "no"
224+
let formatState = function State.Aborted -> "aborted" | State.Completed -> "completed" | State.NotCompleted -> "not completed"
225+
let formatSources =
226+
function
227+
| AudiobookSource.SingleFile s -> [ $"Source: %s{s}" ]
228+
| AudiobookSource.MultiFile many ->
229+
"Source:" :: (many |> List.map (fun s -> $"\t%s{s}"))
230+
let asString = function | Some s -> s | None -> "-"
231+
[
232+
$"Id: %i{a.Id}"
233+
$"Album: %s{a.Album |> asString}"
234+
$"Album Artist: %s{a.AlbumArtist |> asString}"
235+
$"Artist: %s{a.Artist |> asString}"
236+
$"Title: %s{a.Title |> asString}"
237+
$"Duration: %s{a.Duration |> formatDuration}"
238+
$"Rating: %i{a.Rating |> Option.map (Rating.value) |> Option.getOrElse -1}"
239+
$"State: %s{a.State |> formatState}"
240+
$"Genre: %s{a.Genre |> asString}"
241+
$"Comment: %s{a.Comment |> asString}"
242+
$"Has Picture: %s{a.HasPicture |> formatBool}"
243+
] @ (a.Source |> formatSources)

src/cli/Config.fs

+7
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ module Config =
180180
NonInteractive = false
181181
}
182182

183+
type DetailsConfig = {
184+
Ids: int list
185+
}
186+
183187
type Command
184188
= Add of AddConfig
185189
| List of ListConfig
@@ -194,6 +198,7 @@ module Config =
194198
| Uninitialized
195199
| Write of WriteConfig
196200
| Migrate
201+
| Details of DetailsConfig
197202
| Version
198203

199204
type Config = {
@@ -360,6 +365,8 @@ module Config =
360365
{ config with Command = Write updatedWriteConfig }
361366
| MainArgs.Migrate ->
362367
{ config with Command = Migrate }
368+
| MainArgs.Details ids ->
369+
{ config with Command = Details { Ids = ids } }
363370
| MainArgs.Version ->
364371
{ config with Command = Version }
365372

src/cli/Program.fs

+13-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Program =
5151
| true, false -> getFilesAsBooks path
5252
| false, true -> getSubFoldersAsBooks path
5353
| true, true -> getFilesAsBookAndSubFoldersAsBooks path
54-
let files = files |> List.map (IO.filterMp3Files) |> List.skipEmpty
54+
let files = files |> List.map IO.filterMp3Files |> List.skipEmpty
5555
return! files |> List.map createBook |> List.sequenceResultM
5656
}
5757

@@ -351,7 +351,7 @@ module Program =
351351

352352
let filter = match config.ListMissing with
353353
| false -> id
354-
| true -> List.filter (IO.fileDoesNotExist)
354+
| true -> List.filter IO.fileDoesNotExist
355355
let files = books |> List.collect (fun book -> book |> Audiobook.allFiles |> filter |> List.map (sprintf "\"%s\""))
356356

357357
let separator = match config.Separator with
@@ -372,6 +372,12 @@ module Program =
372372
do! metadata |> List.map (TagLib.writeMetaData writeConfig) |> List.sequenceResultM |> Result.map ignore
373373
}
374374

375+
let listDetails (config: Config.DetailsConfig) (library: Library.Library) =
376+
result {
377+
let! books = library |> Library.findByIds config.Ids
378+
do books |> List.iter (Audiobook.details >> List.iter Console.WriteLine)
379+
}
380+
375381
let migrateLibrary (libraryFile: string) _ =
376382
result {
377383
// Make sure the config no longer uses the `LastScanned` field.
@@ -463,17 +469,19 @@ module Program =
463469
| Config.Files filesConfig ->
464470
let! string = listFiles config.LibraryFile filesConfig
465471
if String.IsNullOrWhiteSpace(string) then ()
466-
else do printfn "%s" string
472+
else do Console.WriteLine(string)
467473
| Config.Unmatched unmatchedConfig ->
468474
return! (runOnExisting (unmatched unmatchedConfig config.LibraryFile))
469475
| Config.Uninitialized ->
470-
do printfn "%s" (parser.PrintUsage())
476+
do Console.WriteLine(parser.PrintUsage())
471477
| Config.Write writeConfig ->
472478
return! (runOnExisting (write writeConfig))
473479
| Config.Migrate ->
474480
return! (runOnExisting (migrateLibrary config.LibraryFile))
481+
| Config.Details detailsConfig ->
482+
return! (runOnExisting (listDetails detailsConfig))
475483
| Config.Version ->
476-
do printfn "%s" Version.current
484+
do Console.WriteLine(Version.current)
477485
}
478486

479487
match r with

0 commit comments

Comments
 (0)