summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Ultramarine/Model/Collection.pm634
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Ultramarine/Model/Collection.pm6 b/lib/Ultramarine/Model/Collection.pm6
new file mode 100644
index 0000000..c8cddf7
--- /dev/null
+++ b/lib/Ultramarine/Model/Collection.pm6
@@ -0,0 +1,34 @@
+use v6.d.PREVIEW;
+need Ultramarine::Model::DirScanner;
+
+class Ultramarine::Model::Collection {
+ has $.db is required handles <all-songs>;
+ has $.dirscan is required;
+ has $.file-class is required;
+
+ method new(|c) {
+ my $self = self.bless(|c);
+ start $self.update();
+ return $self;
+ }
+
+ has Promise $.is-ready .= new;
+ has $!mark-ready = $!is-ready.vow;
+
+ method update() {
+ react whenever $.dirscan.scan -> $path {
+ when $path ~~ Ultramarine::Model::DirScanner::EndOfScan {
+ # we should use this to check that all the files in
+ # the db have been seen, and delete those that haven't
+ $!mark-ready.keep(True);
+ }
+ when $path ~~ IO::Path & :f {
+ my $mtime = $path.modified.floor;
+ unless $.db.is-up-to-date(:$path,:$mtime) {
+ my %metadata = $.file-class.new(:$path).metadata;
+ $.db.set-song(:$path,:$mtime,:%metadata) if %metadata.keys;
+ }
+ }
+ }
+ }
+}