diff options
author | dakkar <dakkar@thenautilus.net> | 2017-12-18 19:44:31 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-12-18 19:44:31 +0000 |
commit | e1d6f51d0e7560310e886d81d26e4f9b6a3bd7f1 (patch) | |
tree | 05096c9a334f90f374b1d7650922464fccf3ab37 | |
parent | add xml text-decl (diff) | |
download | Ultramarine-e1d6f51d0e7560310e886d81d26e4f9b6a3bd7f1.tar.gz Ultramarine-e1d6f51d0e7560310e886d81d26e4f9b6a3bd7f1.tar.bz2 Ultramarine-e1d6f51d0e7560310e886d81d26e4f9b6a3bd7f1.zip |
rough model to extract metadata from music files
-rw-r--r-- | lib/Ultramarine/Model/MusicFile.pm6 | 29 |
1 files changed, 29 insertions, 0 deletions
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 }); + } +} |