add file conversion
This commit is contained in:
parent
6c14dbb592
commit
7776fcd05c
|
@ -311,9 +311,16 @@ function search3(req; dl = println)
|
||||||
query = HTTP.URIs.queryparams(req[:query])
|
query = HTTP.URIs.queryparams(req[:query])
|
||||||
q = get(query, "query", "")
|
q = get(query, "query", "")
|
||||||
isempty(q) && return missing_parameter("query")
|
isempty(q) && return missing_parameter("query")
|
||||||
if length(q) > 2 && q[end-1:end] == "!t"
|
if req[:user][:user].upload && length(q) > 2 && q[end-1:end] == "!t"
|
||||||
@info "This is the special torrent mode!"
|
@info "This is the special torrent mode!"
|
||||||
dl(string(strip(q[1:end-2])))
|
list = dl(string(strip(q[1:end-2])))
|
||||||
|
list == nothing return @subsonic(nothing)
|
||||||
|
|
||||||
|
(xdoc, xroot) = subsonic()
|
||||||
|
results = new_child(xroot, "searchResult3")
|
||||||
|
# TODO: Push the results so that we can see what download just started
|
||||||
|
# push!(results, list)
|
||||||
|
return subsonic_return(xdoc)
|
||||||
end
|
end
|
||||||
songCount = parse(Int, get(query, "songCount", "20"))
|
songCount = parse(Int, get(query, "songCount", "20"))
|
||||||
# TODO:
|
# TODO:
|
||||||
|
@ -506,18 +513,44 @@ function getCoverArt(req::Dict)
|
||||||
return sendfile(Beets.albums[n].cover)
|
return sendfile(Beets.albums[n].cover)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function giveconverted(file, bitrate, format)
|
||||||
|
data = convert(file, bitrate = bitrate, format = format)
|
||||||
|
headers = Dict{String,String}()
|
||||||
|
suffix = format
|
||||||
|
mime = suffix in keys(Mux.mimetypes) ? Mux.mimetypes[suffix] : suffix
|
||||||
|
headers["Content-Type"] = mime
|
||||||
|
headers["Content-Length"] = length(data)
|
||||||
|
return Dict(:body => data, :headers => headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
function convert(infile; bitrate = 64, format = "oga")
|
||||||
|
pipeline(`ffmpeg -i $infile -y -c:a libvorbis -b:a $(bitrate)k -f $format pipe:1`,
|
||||||
|
stderr=devnull) |> read
|
||||||
|
end
|
||||||
|
|
||||||
canstream(u::User) = u.stream
|
canstream(u::User) = u.stream
|
||||||
"Streams a given media file."
|
"Streams a given media file."
|
||||||
function stream(req::Dict)
|
function stream(req::Dict)
|
||||||
query = HTTP.URIs.queryparams(req[:query])
|
query = HTTP.URIs.queryparams(req[:query])
|
||||||
canstream(req[:login][:user]) || return unuthorized()
|
canstream(req[:login][:user]) || return unuthorized()
|
||||||
|
|
||||||
id = get(query, "id", "")
|
id = get(query, "id", "")
|
||||||
isempty(id) && return missing_parameter("id")
|
isempty(id) && return missing_parameter("id")
|
||||||
|
|
||||||
|
bitrate = try parse(Int, get(query, "maxBitRate", "0"))
|
||||||
|
catch e
|
||||||
|
isa(e, ArgumentError) && 0
|
||||||
|
@error e
|
||||||
|
end
|
||||||
|
format = get(query, "format", "oga")
|
||||||
|
|
||||||
songs = Beets.songs()
|
songs = Beets.songs()
|
||||||
m = findfirst(x -> (x.uuid == id), songs)
|
m = findfirst(x -> (x.uuid == id), songs)
|
||||||
m === nothing && return not_found("id")
|
m === nothing && return not_found("id")
|
||||||
|
|
||||||
return sendfile(songs[m].path)
|
output = bitrate == 0 ? sendfile(songs[m].path) :
|
||||||
|
giveconverted(songs[m].path, bitrate, format)
|
||||||
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
function sendfile(path; suffix = nothing)
|
function sendfile(path; suffix = nothing)
|
||||||
|
|
|
@ -11,6 +11,7 @@ function torrentdl(query::AbstractString)
|
||||||
TransmissionRPC.getauth(rpc)
|
TransmissionRPC.getauth(rpc)
|
||||||
todl = RuTrackers.getdiscography(me, query)
|
todl = RuTrackers.getdiscography(me, query)
|
||||||
TransmissionRPC.add.(Ref(rpc), RuTrackers.download.(Ref(me), todl))
|
TransmissionRPC.add.(Ref(rpc), RuTrackers.download.(Ref(me), todl))
|
||||||
|
todl
|
||||||
end
|
end
|
||||||
|
|
||||||
dispatch = stack(
|
dispatch = stack(
|
||||||
|
|
Loading…
Reference in New Issue