diff --git a/JlSonic/api.jl b/JlSonic/api.jl index 1cecd41..4489091 100644 --- a/JlSonic/api.jl +++ b/JlSonic/api.jl @@ -307,12 +307,13 @@ function makequery(q::String) return Regex(nq) end -function search3(req) +function search3(req; dl = println) query = HTTP.URIs.queryparams(req[:query]) q = get(query, "query", "") isempty(q) && return missing_parameter("query") if length(q) > 2 && q[end-1:end] == "!t" @info "This is the special torrent mode!" + dlfunc(strip(q[1:end-2])) end songCount = parse(Int, get(query, "songCount", "20")) # TODO: diff --git a/router.jl b/router.jl index 314e0c6..38204e4 100644 --- a/router.jl +++ b/router.jl @@ -6,6 +6,13 @@ function restpath!(target, req) end restp(p, app...) = branch(req -> restpath!(p, req), app...) +function torrentdl(query::AbstractString) + global rpc, me + TransmissionRPC.getauth(rpc) + todl = RuTrackers.getdiscography(query) + add.(Ref(rpc), RuTrackers.download.(Ref(me), todl)) +end + dispatch = stack( # Browsing restp("getMusicFolders", _ -> getMusicFolders()), @@ -19,7 +26,7 @@ dispatch = stack( # Album/song list restp("getRandomSongs", req -> getRandomSongs(req)), # Searching - restp("search3", req -> search3(req)), + restp("search3", req -> search3(req; dl = torrentdl)), # Playlists restp("createPlaylist", req -> createPlaylist(req)), restp("getPlaylists", req -> getPlaylists(req)), diff --git a/server.jl b/server.jl index 338016f..278236a 100644 --- a/server.jl +++ b/server.jl @@ -5,6 +5,16 @@ using Revise push!(LOAD_PATH, "/home/nixo/memories/projects/2018-2019/musicjl") isdir("../juliaMusicDL") && push!(LOAD_PATH, realpath("../juliaMusicDL")) import Beets +import RuTrackers +import MusicBrainz +import TransmissionRPC + +import JSON +# FIXME: replace with JSON2 serialization +me = RuTrackers.RuTracker(read("rutracker.json", String) |> JSON.parse) +rpc = TransmissionRPC.Transmission(TransmissionRPC.Sockets.ip"192.168.1.3") + + retry(Beets.update_albums, delays = Base.ExponentialBackOff(n=10, first_delay=5, max_delay = 100)); push!(LOAD_PATH, realpath("JlSonic"))