Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Created January 29, 2016 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ab5tract/d730a845a3915f7abdcf to your computer and use it in GitHub Desktop.
Save ab5tract/d730a845a3915f7abdcf to your computer and use it in GitHub Desktop.
async-transcoder.p6
#!/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;
}
@jonathanstowe
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment