From f0042c548660476f728af7f79eb74c890d45b787 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 31 Dec 2021 16:24:27 +0000 Subject: recent (broken) --- lib/App/MediaControl/DB.rakumod | 30 ++++++++++++++++++++++++++++++ lib/App/MediaControl/Web.rakumod | 4 ++++ 2 files changed, 34 insertions(+) (limited to 'lib') diff --git a/lib/App/MediaControl/DB.rakumod b/lib/App/MediaControl/DB.rakumod index 34716c5..96fc6cd 100644 --- a/lib/App/MediaControl/DB.rakumod +++ b/lib/App/MediaControl/DB.rakumod @@ -141,4 +141,34 @@ class App::MediaControl::DB { END } } + + method mark-entry-watched(Int:D() $id) { + self!db: { + .query(q:to/END/,:$id,:time(time)); + UPDATE files + SET watched_time=$time + WHERE id=$id + END + } + } + + method get-recently-watched-folders(Int:D() $limit=20) { + self!db: { + .query(qq:to/END/, :$limit).hashes; + WITH recent(id,watched_time) AS ( + SELECT parent_id AS id, MAX(watched_time) AS watched_time + FROM files + WHERE is_dir=false + AND watched_time IS NOT NULL + AND parent_id IS NOT NULL + GROUP BY parent_id + ORDER BY watched_time DESC + LIMIT $limit + ) + SELECT files.id, files.name, files.is_dir, recent.watched_time + FROM files + JOIN recent ON files.id=recent.id + END + } + } } diff --git a/lib/App/MediaControl/Web.rakumod b/lib/App/MediaControl/Web.rakumod index 076e2f2..b6fd85d 100644 --- a/lib/App/MediaControl/Web.rakumod +++ b/lib/App/MediaControl/Web.rakumod @@ -21,6 +21,7 @@ class App::MediaControl::Web { await self.vlc.play-file(|%( $file:p # no comma! )); + self.db.mark-entry-watched($id); } post -> 'pause' { await self.vlc.command('pl_pause') } post -> 'stop' { await self.vlc.command('pl_stop') } @@ -46,6 +47,9 @@ class App::MediaControl::Web { }; content 'application/json', %reply; } + get -> 'recent' { + content 'application/json', self.db.get-recently-watched-folders(); + } }; my $application = route { -- cgit v1.2.3