From acf358317dba4022db049f9eeb4b0f788506a7a7 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Oct 2018 17:57:39 +0000 Subject: [PATCH] Add youtube-dl-x protocol, reduces CPU usage MASSIVELY --- state/liquidsoap/config/main.liq | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/state/liquidsoap/config/main.liq b/state/liquidsoap/config/main.liq index 55b66b5..c1af105 100644 --- a/state/liquidsoap/config/main.liq +++ b/state/liquidsoap/config/main.liq @@ -8,6 +8,50 @@ set("server.telnet.bind_addr", "0.0.0.0") set("decoder.file_extensions.gstreamer",["wav", "webm"]) set("decoder.mime_types.gstreamer",["audio/x-wav", "audio/wav", "video/webm"]) +register(name="Youtube_dl-x protocol settings","protocol.youtube-dl-x",()) +register(name="Youtube-dl path","protocol.youtube-dl-x.path","youtube-dl -x --audio-format wav --postprocessor-args \"-y\"") + +# Register the youtube-dl protocol, using youtube-dl. +# Syntax: youtube-d-xl: +# @flag hidden +def youtube_dl_x_protocol(~rlog,~maxtime,arg) + binary = get(default="youtube-dl","protocol.youtube-dl-x.path") + + log = log(label="protocol.youtube-dl-x") + + def log(~level,s) = + rlog(s) + log(level=level,s) + end + + delay = maxtime - gettimeofday() + cmd = "#{binary} -x --audio-format wav --get-title --get-filename -- #{quote(arg)}" + log(level=4,"Executing #{cmd}") + x = get_process_lines(timeout=delay,cmd) + + x = + if list.length(x) >= 2 then + x + else + ["",".osb"] + end + + + ext = "wav" + title = list.hd(default="",x) + cmd = "rm -f $(output) && #{binary} -x --audio-format wav -q -f bestaudio/best --no-playlist --exec \"mv {} $(output)\" -- #{quote(arg)}" + process = process_uri(extname=ext,cmd) + + if title != "" then + ["annotate:title=#{quote(title)}:#{process}"] + else + [process] + end +end +add_protocol("youtube-dl-x", youtube_dl_x_protocol, + doc="Resolve a request using youtube-dl.", +syntax="youtube-dl-x:uri") + def crossfade(a,b) add(normalize=false, [ sequence([ blank(duration=5.),