package otaglibc

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file otaglibc.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
(*****************************************************************************)
(*                                                                           *)
(*  Copyright (C) 2025 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/.                 *)
(*                                                                           *)
(*****************************************************************************)

type t
type id3v2_encoding = ID3v2_Latin | ID3v2_UTF16 | ID3v2_UTF16BE | ID3v2_UTF8

(* Should be in the same order than file in c_tag.h *)
type file_type =
  | MPEG
  | OggVorbis
  | FLAC
  | MPC
  | OggFlac
  | WavPack
  | Speex
  | TrueAudio
  | MP4
  | ASF
  | AIFF
  | WAV
  | APE
  | IT
  | Mod
  | S3M
  | XM
  | Opus
  | DSF
  | DSDIFF
  | SHORTEN

type audioproperties = {
  bitrate : int;
  channels : int;
  length : int;
  samplerate : int;
}

type picture = {
  mime_type : string;
  description : string;
  picture_type : string;
  data : bytes;
}

external from_filename : string -> t option = "caml_taglib_file_name"

external from_filename_with_type : string -> file_type -> t option
  = "caml_taglib_file_name_with_type"

let with_open file f =
  file |> from_filename |> Option.map (fun taglib -> f taglib)

let with_open_with_type file type' f =
  Option.map f (from_filename_with_type file type')

external set_strings_unicode : bool -> unit = "caml_taglib_set_strings_unicode"
external title : t -> string option = "caml_taglib_title"
external set_title : t -> string -> unit = "caml_taglib_set_title"
external album : t -> string option = "caml_taglib_album"
external set_album : t -> string -> unit = "caml_taglib_set_album"
external artist : t -> string option = "caml_taglib_artist"
external set_artist : t -> string -> unit = "caml_taglib_set_artist"
external genre : t -> string option = "caml_taglib_genre"
external set_genre : t -> string -> unit = "caml_taglib_set_genre"
external comment : t -> string option = "caml_taglib_comment"
external set_comment : t -> string -> unit = "caml_taglib_set_comment"
external year : t -> int = "caml_taglib_year"
external set_year : t -> int -> unit = "caml_taglib_set_year"
external track : t -> int = "caml_taglib_track"
external set_track : t -> int -> unit = "caml_taglib_set_track"
external save : t -> bool = "caml_taglib_save"

external id3v2_set_default_text_encoding : id3v2_encoding -> unit
  = "caml_taglib_taglib_id3v2_set_default_text_encoding"

external audioproperties : t -> audioproperties option
  = "caml_taglib_audioprops"

external property_keys : t -> string array option = "caml_taglib_property_keys"

external property : t -> string -> string array option
  = "caml_taglib_get_property"

external set_property : t -> string -> string -> unit
  = "caml_taglib_set_property"

external set_property_append : t -> string -> string -> unit
  = "caml_taglib_property_set_append"

external property_clear : t -> string -> unit = "caml_taglib_property_clear"

let set_properties taglib key values =
  let () = property_clear taglib key in
  List.iter (set_property_append taglib key) values

external add_picture : t -> picture -> unit = "caml_taglib_add_picture"
external remove_pictures : t -> unit = "caml_taglib_remove_pictures"
external pictures : t -> picture array = "caml_taglib_get_pictures"