add torrent download

This commit is contained in:
nixo 2019-05-21 15:40:42 +02:00
parent f9be19a1aa
commit 0b7d0ebdd8
3 changed files with 20 additions and 2 deletions

View File

@ -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:

View File

@ -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)),

View File

@ -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"))