Source file format.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(*****************************************************************************)
(*                                                                           *)
(*  Copyright (C) 2026 Yves Ndiaye                                           *)
(*                                                                           *)
(* This Source Code Form is subject to the terms of the Mozilla Public       *)
(* License, v. 2.0. If a copy of the MPL was not distributed with this       *)
(* file, You can obtain one at https://mozilla.org/MPL/2.0/.                 *)
(*                                                                           *)
(*****************************************************************************)

module Keys = struct
  let filename = "filename"
  let artist_artwork = "artist_artwork"
  let album_cover = "album_cover"
  let music_list = "music_list"
  let artist_list = "artist_list"
  let album_list = "album_list"
  let music_remove = "music_remove"
end

module Default = struct
  open SkhcQuery

  let filename =
    Printf.sprintf "%s-%s %s%s" Keys.disc Keys.track Keys.title Keys.extension

  let artist_artwork = "artist"
  let album_cover = "cover"
  let music_list = Printf.sprintf "%s - %s" Keys.artist Keys.title
  let album_list = Printf.sprintf "%s - %s" Keys.artist Keys.album
  let artist_list = Printf.sprintf "%s - %s" Keys.id Keys.artist

  let music_remove =
    Printf.sprintf "%s - %s: %s" Keys.artist Keys.title SkhcQuery.Keys.path
end

type t = {
  filename : string;
  artist_artwork : string;
  album_cover : string;
  music_list : string;
  album_list : string;
  artist_list : string;
  music_remove : string;
}

let section = "format"

let default : t =
  let open Default in
  {
    filename;
    artist_artwork;
    album_cover;
    music_list;
    album_list;
    artist_list;
    music_remove;
  }

let init ~filename ~artist_artwork ~album_cover ~music_list ~album_list
    ~artist_list ~music_remove =
  {
    filename;
    artist_artwork;
    album_cover;
    music_list;
    artist_list;
    album_list;
    music_remove;
  }

let conv ~default key section =
  match Section.assoc key section with Some e -> e | None -> default

let of_section section =
  let filename = conv ~default:Default.filename Keys.filename section in

  let artist_artwork =
    conv ~default:Default.artist_artwork Keys.artist_artwork section
  in
  let album_cover =
    conv ~default:Default.album_cover Keys.album_cover section
  in
  let music_list = conv ~default:Default.music_list Keys.music_list section in
  let artist_list =
    conv ~default:Default.artist_list Keys.artist_list section
  in
  let album_list = conv ~default:Default.album_list Keys.album_list section in
  let music_remove =
    conv ~default:Default.music_remove Keys.music_remove section
  in
  {
    filename;
    artist_artwork;
    album_cover;
    music_list;
    artist_list;
    album_list;
    music_remove;
  }

let to_section t =
  let {
    filename;
    artist_artwork;
    album_cover;
    music_list;
    artist_list;
    album_list;
    music_remove;
  } =
    t
  in
  Section.init section
    [
      (Keys.filename, filename);
      (Keys.artist_artwork, artist_artwork);
      (Keys.album_cover, album_cover);
      (Keys.music_list, music_list);
      (Keys.album_list, album_list);
      (Keys.artist_list, artist_list);
      (Keys.music_remove, music_remove);
    ]

let filename t = t.filename
let artist_artwork t = t.artist_artwork
let album_cover t = t.album_cover
let music_list t = t.music_list
let artist_list t = t.artist_list
let album_list t = t.album_list
let music_remove t = t.music_remove