JlSonic/router.jl

59 lines
2.0 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)
TransmissionRPC.add.(Ref(rpc), RuTrackers.download.(Ref(me), todl))
todl
end
function albumdl(query::AbstractString)
global rpc, me
TransmissionRPC.getauth(rpc)
todl = RuTrackers.search(me, query)
@show todl
lossless = RuTrackers.islossless.(todl)
discog = RuTrackers.isdiscography.(todl)
m = findfirst(lossless .& .!discog)
m === nothing && return
TransmissionRPC.add(rpc, RuTrackers.download(me, todl[m]))
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;
dlalbum = albumdl,
dlall = 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
)