aboutsummaryrefslogtreecommitdiff
path: root/lib/App/MediaControl.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App/MediaControl.rakumod')
-rw-r--r--lib/App/MediaControl.rakumod25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/App/MediaControl.rakumod b/lib/App/MediaControl.rakumod
index 77fda99..cf635d4 100644
--- a/lib/App/MediaControl.rakumod
+++ b/lib/App/MediaControl.rakumod
@@ -1,5 +1,6 @@
use v6.d;
use DB::SQLite;
+use ScanDir;
use Vlc::Client;
use Lirc::Client;
use Lirc::Commands;
@@ -35,8 +36,32 @@ class App::MediaControl {
);
}
+ method !start-scan() {
+ my $root = $.config<media><root>;
+ $!db.clear-seen();
+ start react {
+ whenever scan-dir($root) -> $item {
+ when $item ~~ $root {}
+ when $item ~~ ScanDir::End { $!db.remove-unseen() }
+
+ my $path = $item.parent.relative($root);
+ $path = '' if $path eq '.';
+ my $name = $item.basename;
+
+ if !$item.e {
+ $!db.remove-entry(:$path,:$name);
+ }
+ else {
+ my $is-dir = $item.d;
+ $!db.add-entry(:$path,:$name,:$is-dir);
+ }
+ }
+ }
+ }
+
method start() {
$!db.ensure-schema();
+ self!start-scan();
$!web.start();
}