Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bigarray2
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Dec 13, 2023
2 parents 6853e84 + 11749ea commit a7964d0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ all: build
build:
@dune build

doc:
@dune build @doc

clean:
@dune clean
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,23 @@ Basic usage is

```ocaml
let () =
let filename = "test.mp3" in
let metadata = Metadata.parse_file filename in
let metadata = Metadata.parse_file "test.mp3" in
List.iter (fun (k,v) -> Printf.printf "- %s: %s\n" k v) metadata
```

In the above example, the function `Metadata.Any.parse_file` takes a file name
as argument and returns an association list describing its metadata. It consists
of pairs of strings being the name of the metadata and its value.
In the above example, the function `Metadata.parse_file` takes a file name as
argument and returns an association list describing its metadata. It consists of
pairs of strings being the name of the metadata and its value.

Installing
----------

The preferred way is via opam:

```bash
opam pin add .
opam install metadata
```

It can also be installed via dune:

```
dune install
```

Other libraries
---------------

Expand Down
5 changes: 2 additions & 3 deletions examples/basic.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(** Basic usage of the library. *)

let () =
let filename = "test.mp3" in
let metadata = Metadata.parse_file filename in
List.iter (fun (k,v) -> Printf.printf "- %s: %s\n" k v) metadata
let metadata = Metadata.parse_file "test.mp3" in
List.iter (fun (k, v) -> Printf.printf "- %s: %s\n" k v) metadata
7 changes: 7 additions & 0 deletions src/metadata.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Make (E : CharEncoding.T) = struct
module AVI = MetadataAVI
module MP4 = MetadataMP4

(** Charset conversion function. *)
let recode = E.convert

module ID3 = struct
Expand Down Expand Up @@ -65,10 +66,16 @@ module Make (E : CharEncoding.T) = struct

module Any = struct
let parsers = Audio.parsers @ Image.parsers @ Video.parsers

(** Genering parsing of metadata. *)
let parse = first_valid parsers

let parse_file ?custom_parser file =
Reader.with_file ?custom_parser parse file

(** Parse the metadatas of a string. *)
let parse_string ?custom_parser file =
Reader.with_string ?custom_parser parse file
end

include Any
Expand Down
3 changes: 3 additions & 0 deletions src/metadata.mli
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ module Make : functor (_ : CharEncoding.T) -> sig

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

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

val parsers : (Reader.t -> MetadataBase.metadata) list
Expand Down
2 changes: 2 additions & 0 deletions src/metadataBase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type custom_parser =
unit

module Reader = struct
(** A function to read taking the buffer to fill the offset and the length and
returning the number of bytes actually read. *)
type t = {
read : bytes -> int -> int -> int;
read_ba : (int -> bigarray) option;
Expand Down

0 comments on commit a7964d0

Please sign in to comment.