async-transcoder.p6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl6 | |
| use v6; | |
| sub MAIN($dir) { | |
| my $handler-supplier = Supplier.new; | |
| my $handler-supply = $handler-supplier.Supply; | |
| my %seen; | |
| my $dispatch-promise = start { | |
| say "Watching out on '$dir'"; | |
| react { | |
| whenever $dir.IO.watch.grep({ .path ~~ /'.wav'$/ && !%seen{.path} }) -> $change { | |
| %seen{$change.path} = True; | |
| $handler-supplier.emit($change); | |
| } | |
| whenever $handler-supply -> $file { | |
| my $old-path = $file.path; | |
| my $new-path = "~/Desktop/flac/{$old-path.IO.basename}"; | |
| my $copy = Proc::Async.new('cp', $old-path, $new-path); | |
| whenever $copy.start { | |
| my $encode = Proc::Async.new('flac', '-f', $new-path); | |
| $encode.stdout.tap(-> $p { print $p }); | |
| whenever $encode.start { | |
| say "Finished transcoding $new-path"; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| await $dispatch-promise; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For your amusement I made a version that uses https://github.com/jonathanstowe/Tinky at https://github.com/jonathanstowe/Tinky/blob/master/examples/encode-files obviously you will need to install the latest version of that module for it to work. It worked fined for me on Linux copying vast directories of WAV files to the watch dir.
And I found a bug in Tinky while I was testing it so all good :)
Have fun.