1

我正在尝试编写我的第一个液体肥皂程序。它是这样的:

sounds_path = "../var/sounds"

# Log file
set("log.file.path","var/log/liquidsoap.log")
set("harbor.bind_addr", "127.0.0.1")
set("harbor.timeout", 5)
set("harbor.verbose", true)
set("harbor.reverse_dns", false)

silence = blank()
queue = request.queue()

def play(~protocol, ~data, ~headers, uri) =
    request.push("#{sounds_path}#{uri}")
    http_response(protocol=protocol, code=20000)
end

harbor.http.register(port=8080, method="POST", "^/(?!\0)+", play)

stream = fallback(track_sensitive=false, [queue, silence])
...output.whatever...

我想知道是否有任何方法可以从港口回调推送到队列。

否则,我应该如何处理来自 HTTP 调用的请求?我真的想避免telnet。我的最终目标是有一个端点,我可以调用它来让我的流按需播放文件并在其余时间保持沉默。

4

2 回答 2

2

试一试它的液体肥皂,所以它很难理解,但它应该可以解决问题

########### functions ##############
def playnow(source,~action="override", ~protocol, ~data, ~headers, uri) =
      queue_count = list.length(server.execute("playnow.primary_queue"))
      arr = of_json(default=[("key","value")], data)  
      track = arr["track"];
      log("adding playnow track '#{track}'")

      if queue_count != 0 and action == "override" then
        server.execute("playnow.insert 0 #{track}")
        source.skip(source)
        print("skipping playnow queue")
      else
        server.execute("playnow.push #{track}")
        print("no skip required")
      end

      http_response(
        protocol=protocol,
        code=200,
        headers=[("Content-Type","application/json; charset=utf-8")],
        data='{"status":"success", "track": "#{track}", "action": "#{action}"}'
      )
end
######## live stuff below #######

playlist= playlist(reload=1, reload_mode="watch", "/etc/liquidsoap/playlist.xspf")

requested = crossfade(request.equeue(id="playnow"))

live= fallback(track_sensitive=false,transitions=[crossfade, crossfade],[requested,  playlist])

output.harbor(%mp3,id="live",mount="live_radio", radio)

harbor.http.register(port=MY_HARBOR_PORT, method="POST","/playnow", playnow(live))

要使用上述内容,您需要发送带有 json 数据的 post 请求,如下所示: {"track":" http://mydomain/mysong.mp3 "}

这也是假设您拥有正在运行的港口,您应该能够使用liquidsoap docs找到它

于 2019-09-25T15:28:10.213 回答
0

有多种发送到队列的方法,有 telnet,您可以创建 http 输入,或通过港口向 playnow 发送元数据请求,让我知道您选择哪一种,我可以为您提供代码示例

于 2019-09-24T11:09:15.200 回答