JlSonic/router.jl

44 lines
1.6 KiB
Julia

function restpath!(target, req)
# @show req[:path]
length(req[:path]) < 2 && return false
return req[:path][1] == "rest" &&
startswith(req[:path][2], target)
end
restp(p, app...) = branch(req -> restpath!(p, req), app...)
function torrentdl(query::AbstractString)
global rpc, me
TransmissionRPC.getauth(rpc)
todl = RuTrackers.getdiscography(me, query)
add.(Ref(rpc), RuTrackers.download.(Ref(me), todl))
end
dispatch = stack(
# Browsing
restp("getMusicFolders", _ -> getMusicFolders()),
restp("getMusicDirectory", req -> getMusicDirectory(req)),
restp("getAlbumList", req -> getAlbumList(req)),
restp("getGenres", _ -> getGenres()),
restp("getArtists", _ -> getArtists()),
restp("getArtist", r -> getArtist(r)),
restp("getAlbum", req -> getAlbum(req)),
restp("getSong", req -> getSong(req)),
# Album/song list
restp("getRandomSongs", req -> getRandomSongs(req)),
# Searching
restp("search3", req -> search3(req; dl = torrentdl)),
# Playlists
restp("createPlaylist", req -> createPlaylist(req)),
restp("getPlaylists", req -> getPlaylists(req)),
restp("getPlaylist", req -> getPlaylist(req)),
restp("updatePlaylist", req -> updatePlaylist(req)),
restp("deletePlaylist", req -> deletePlaylist(req)),
# User management
restp("getUser", req -> getUser(req)),
# Media retrieval
restp("stream", req -> stream(req)),
restp("getCoverArt", req -> getCoverArt(req)),
# Media library scanning (can be used to check download status!)
# getScanStatus startScan
)