From 1f87a9afae9b2c096ecf9d8005d7af9e9903cc40 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 3 Mar 2018 14:07:58 +0000 Subject: very hackish getIndexes --- lib/Ultramarine/Controller.pm6 | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lib/Ultramarine/Controller.pm6 b/lib/Ultramarine/Controller.pm6 index c66e839..0167dd0 100644 --- a/lib/Ultramarine/Controller.pm6 +++ b/lib/Ultramarine/Controller.pm6 @@ -78,6 +78,54 @@ class Ultramarine::Controller { ], } get $getMusicFolders; + + post my $getIndexes = -> 'getIndexes', :$musicFolderId is query, :$ifModifiedSince is query { + await $.collection.is-ready; + + # when musicFolderId is not passed, we get a Mu, which + # breaks the call (it wants an Any) + my $indexes = $.collection.dir-children-of(id=>$musicFolderId) + .classify( *.name.substr(0,1).uc ).pairs.map: -> (:key($initial),:value($dirs)) { + index => [ + name => $initial, + |($dirs.map: { artist => [ id => $^d.id, name => $^d.name ] }) + ] + }; + my $songs = $.collection.songs-children-of(id=>$musicFolderId) + .map: -> $song { + my $c = [ + id => $song.id, + path => $song.path, + isDir => 'false', + isVideo => 'false', + type => 'music', + contentType => 'audio/mpeg', # faking it + |($song.metadata:p), + year => $song.metadata, + bitRate => $song.metadata.Int, + duration => ($song.metadata*60).Int, + suffix => $song.metadata, # I'm guessing + albumId => $song.album_id, + artistId => 1, # real artistId to be fetched + size => 10000, # we don't event store this + created => Instant.from-posix($song.mtime).DateTime.Str, + ]; + warn $c.perl; + child => $c; + } + + respond [ + :status, + indexes => [ + lastModified => now.to-posix[0].Int, + ignoredArticles => '', + |$indexes, + |$songs, + ], + ]; + } + get $getIndexes; + # this is clearly not a Subsonic method get -> 'dakkarList' { await $.collection.is-ready; -- cgit v1.2.3