diff options
Diffstat (limited to 'lib')
-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 }); + } +} |