From e1d6f51d0e7560310e886d81d26e4f9b6a3bd7f1 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 18 Dec 2017 19:44:31 +0000 Subject: rough model to extract metadata from music files --- lib/Ultramarine/Model/MusicFile.pm6 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/Ultramarine/Model/MusicFile.pm6 diff --git a/lib/Ultramarine/Model/MusicFile.pm6 b/lib/Ultramarine/Model/MusicFile.pm6 new file mode 100644 index 0000000..ec1cbd7 --- /dev/null +++ b/lib/Ultramarine/Model/MusicFile.pm6 @@ -0,0 +1,29 @@ +use v6.d.PREVIEW; +use JSON::Fast; + +=begin example + +my @files = @*ARGS.map: { Ultramarine::Model::MusicFile.new(path=>$_) }; +my @metadata-p = @filesĀ».metadata; +await Promise.allof(@metadata-p); + +say (@metadata-pĀ».result).perl; + +=end example + +class Ultramarine::Model::MusicFile { + has $.path is required; + + method metadata(-->Promise) { + my $result = Promise.new; + my $proc = Proc::Async.new( + 'avprobe', + '-show_format','-of', 'json', + $.path, + ); + my Str $json-str=''; + $proc.stdout.tap(->$data { $json-str~=$data }); + $proc.stderr.tap(->$err {}); + return $proc.start.then(->$status { from-json $json-str }); + } +} -- cgit v1.2.3