diff --git a/examples/Makefile b/examples/Makefile index 33afdb5..daf171d 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -4,6 +4,7 @@ all: test id3v2 test: @dune test + @dune build @citest id3v2: @for i in id3v2/*.mp3; do \ diff --git a/examples/artist_title b/examples/artist_title new file mode 100755 index 0000000..06f66a3 --- /dev/null +++ b/examples/artist_title @@ -0,0 +1,2 @@ +#!/bin/sh +dune exec --no-print-directory ./artist_title.exe -- $@ diff --git a/examples/artist_title.ml b/examples/artist_title.ml new file mode 100644 index 0000000..1b4c81c --- /dev/null +++ b/examples/artist_title.ml @@ -0,0 +1,34 @@ +(** Show artist - title of a (list of) files. *) + +let () = + let fname = ref [] in + Arg.parse [] (fun f -> fname := f :: !fname) "artist_title files"; + if !fname = [] then ( + Printf.eprintf "Please enter a filename.\n%!"; + exit 1); + let fname = + !fname + |> List.map + (fun f -> + if String.contains f '*' then ( + let d = Filename.dirname f in + let f = + Filename.basename f + |> Str.global_replace (Str.regexp "\\*") ".*" + |> Str.regexp + in + let files = + Sys.readdir d |> Array.to_list + |> List.filter (fun s -> Str.string_match f s 0) + in + List.map (fun f -> d ^ "/" ^ f) files) + else [f]) + |> List.flatten + in + List.iter + (fun fname -> + let m = Metadata.Any.parse_file fname in + let artist = List.assoc_opt "artist" m |> Option.value ~default:"?" in + let title = List.assoc_opt "title" m |> Option.value ~default:"?" in + Printf.printf "%s - %s\n%!" artist title + ) fname diff --git a/examples/dune b/examples/dune index 6393f62..0112016 100644 --- a/examples/dune +++ b/examples/dune @@ -3,6 +3,11 @@ (modules meta) (libraries str metadata)) +(executable + (name artist_title) + (modules artist_title) + (libraries str metadata)) + (executable (name basic) (modules basic) @@ -40,6 +45,7 @@ (progn (run ./basic.exe) (run ./test.exe) + (run ./artist_title.exe %{deps}) (run ./meta.exe %{deps})))) (rule