Nirro
Nirro

Reputation: 769

Enqueue liquidsoap request from script instead of command

I'm trying to write my very first liquidsoap program. It goes something like this:

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...

And I was wondering if there is any way to push to the queue from the harbor callback.

Else, how should I proceed about making requests originate from HTTP calls? I really want to avoid telnet. My final objective is having an endpoint that I can call to make my stream play a file on demand and be silent the rest of the time.

Upvotes: 1

Views: 1321

Answers (2)

Mooseh
Mooseh

Reputation: 21

give this a go its liquidsoap so its tricky to understand but it should do the trick

########### 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))

to use the above you need to send a post request with json data like so: {"track":"http://mydomain/mysong.mp3"}

this is also with the assumption you have the harbor running which you should be able to find out using the liquidsoap docs

Upvotes: 2

Mooseh
Mooseh

Reputation: 21

there are multiple methods of sending into the queue, there is telnet, you can create a http input, or a metadata request to playnow via the harbor, let me know which one you opt for and i can provide you with a code example

Upvotes: 0

Related Questions