Skip to content

Commit

Permalink
Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Mar 24, 2024
1 parent a9a5acd commit e6893e5
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 22 deletions.
3 changes: 2 additions & 1 deletion examples/meta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let () =
match !format with
| "id3" | "mp3" -> Metadata.ID3.parse_file
| "id3v1" -> Metadata.ID3v1.parse_file
| "id3v2" -> fun ?custom_parser f -> Metadata.ID3v2.parse_file ?custom_parser f
| "id3v2" ->
fun ?custom_parser f -> Metadata.ID3v2.parse_file ?custom_parser f
| "ogg" -> Metadata.OGG.parse_file
| "mp4" -> Metadata.MP4.parse_file
| "" -> Metadata.Any.parse_file
Expand Down
27 changes: 18 additions & 9 deletions src/metadata.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module Make : functor (_ : CharEncoding.T) -> sig
type metadata = (string * string) list

(** Bigarray representation of (large) tags. *)
type bigarray = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
type bigarray =
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t

(** When used, a custom parser can override the default parsing mechanism.
It is passed the metadata label (without normalization), the expected
Expand Down Expand Up @@ -51,10 +52,12 @@ module Make : functor (_ : CharEncoding.T) -> sig
val reset : t -> unit

(** Specialize a parser to operate on files. *)
val with_file : ?custom_parser:custom_parser -> (t -> metadata) -> string -> metadata
val with_file :
?custom_parser:custom_parser -> (t -> metadata) -> string -> metadata

(** Specialize a parser to operate on strings. *)
val with_string : ?custom_parser:custom_parser -> (t -> metadata) -> string -> metadata
val with_string :
?custom_parser:custom_parser -> (t -> metadata) -> string -> metadata
end

(** ID3v1 metadata.*)
Expand Down Expand Up @@ -92,7 +95,8 @@ module Make : functor (_ : CharEncoding.T) -> sig
module ID3 : sig
val parse : Reader.t -> (string * string) list

val parse_file : ?custom_parser:custom_parser -> string -> (string * string) list
val parse_file :
?custom_parser:custom_parser -> string -> (string * string) list
end

(** Return the first application which does not raise invalid. *)
Expand All @@ -102,21 +106,24 @@ module Make : functor (_ : CharEncoding.T) -> sig
module Audio : sig
val parse : Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:custom_parser -> string -> MetadataBase.metadata
end

(** Image file formats. *)
module Image : sig
val parse : Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:custom_parser -> string -> MetadataBase.metadata
end

(** Video file formats. *)
module Video : sig
val parse : Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:custom_parser -> string -> MetadataBase.metadata
end

(** All support file formats. *)
Expand All @@ -125,10 +132,12 @@ module Make : functor (_ : CharEncoding.T) -> sig
val parse : Reader.t -> MetadataBase.metadata

(** Parse the metadata from a file. *)
val parse_file : ?custom_parser:custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:custom_parser -> string -> MetadataBase.metadata

(** Parse the metadata from a string containing the contents of a file. *)
val parse_string : ?custom_parser:custom_parser -> string -> MetadataBase.metadata
val parse_string :
?custom_parser:custom_parser -> string -> MetadataBase.metadata
end

include module type of Any
Expand Down
3 changes: 2 additions & 1 deletion src/metadataAVI.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
val parse : MetadataBase.Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
2 changes: 0 additions & 2 deletions src/metadataBase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type bigarray =
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t

type metadata = (string * string) list

type endianness = Big_endian | Little_endian

type parser_handler = {
Expand Down Expand Up @@ -75,7 +74,6 @@ module Reader = struct
if is_custom then None else Some (read f length)

let drop f n = f.seek n

let byte f = int_of_char (read f 1).[0]
let uint8 f = byte f

Expand Down
3 changes: 2 additions & 1 deletion src/metadataFLAC.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
val parse : MetadataBase.Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata

type picture = {
picture_type : int;
Expand Down
8 changes: 6 additions & 2 deletions src/metadataID3v1.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
val parse : ?recode:MetadataCharEncoding.recode -> MetadataBase.Reader.t -> MetadataBase.metadata
val parse :
?recode:MetadataCharEncoding.recode ->
MetadataBase.Reader.t ->
MetadataBase.metadata

val parse_file : ?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
8 changes: 6 additions & 2 deletions src/metadataID3v2.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(** Parse the ID3v2 header. *)
val parse : ?recode:MetadataCharEncoding.recode -> MetadataBase.Reader.t -> MetadataBase.metadata
val parse :
?recode:MetadataCharEncoding.recode ->
MetadataBase.Reader.t ->
MetadataBase.metadata

(** Parse the ID3v2 header from a file. *)
val parse_file :
Expand Down Expand Up @@ -120,7 +123,8 @@ type text_encoding = [ `ISO_8859_1 | `UTF_16 | `UTF_16BE | `UTF_16LE | `UTF_8 ]
(** Data contained in a frame. *)
type frame_data = [ `Text of text_encoding * string | `Binary of string ]

type frame_flag = [ `File_alter_preservation of bool | `Tag_alter_perservation of bool ]
type frame_flag =
[ `File_alter_preservation of bool | `Tag_alter_perservation of bool ]

(** Default flags for a frame. *)
val default_flags : frame_id -> frame_flag list
Expand Down
3 changes: 2 additions & 1 deletion src/metadataJPEG.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
val parse : MetadataBase.Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
3 changes: 2 additions & 1 deletion src/metadataMP4.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
val parse : MetadataBase.Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
3 changes: 2 additions & 1 deletion src/metadataOGG.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
val parse : MetadataBase.Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
3 changes: 2 additions & 1 deletion src/metadataPNG.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
val parse : MetadataBase.Reader.t -> MetadataBase.metadata

val parse_file : ?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata
val parse_file :
?custom_parser:MetadataBase.custom_parser -> string -> MetadataBase.metadata

0 comments on commit e6893e5

Please sign in to comment.