diff options
author | dakkar <dakkar@thenautilus.net> | 2021-12-29 13:37:28 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2021-12-29 13:37:28 +0000 |
commit | 7734605735a027b5e998563e8cbc46b9ae3f9dbb (patch) | |
tree | 14bb8cbe1e831d4b34cc66b7e903099fc3b6762d /lib/App/MediaControl.rakumod | |
parent | move more stuff around (diff) | |
download | media-control-7734605735a027b5e998563e8cbc46b9ae3f9dbb.tar.gz media-control-7734605735a027b5e998563e8cbc46b9ae3f9dbb.tar.bz2 media-control-7734605735a027b5e998563e8cbc46b9ae3f9dbb.zip |
scandir
Diffstat (limited to 'lib/App/MediaControl.rakumod')
-rw-r--r-- | lib/App/MediaControl.rakumod | 25 |
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(); } |