Play a radio url via curl?

Goal is to start a bash script which contains the curl command to perform specific volumio tasks. Example is:

#!/bin/sh
eval "curl localhost:3000/api/v1/commands/?cmd=stop"

So the syntax curl localhost:3000/api/v1/commands/mycommand seems to be working fine.

Then I see that there is a way to POST a PAYLOAD using json formatted code.

curl localhost:3000/api/v1/replaceAndPlay

but how do I format for curl the PAYLOAD part In order to tell Volumio to stop whatever it’s doing and play a radio uri?

Btw… is there a executable path inside the os that will get preserved after an upgrade?

Thanks!

After some playing around and thanks to a key hint from Jackie, I’ve figured out a working example, actually 3:

curl -i -X POST localhost:3000/api/v1/replaceAndPlay --data "service=webradio&type=webradio&title=Nova%20La%20Nuit&uri=http://nova-ln.ice.infomaniak.ch/nova-ln-128&albumart=https://www.nova.fr/sites/default/files/2020-06/Nova%20la%20Nuit_1.jpg"

curl -i -X POST localhost:3000/api/v1/replaceAndPlay --data "service=webradio&type=webradio&title=KCRW%20Eclectic%2024&uri=http://media.kcrw.com/pls/kcrwmusic.pls&albumart=https://www.kcrw.com/music/shows/eclectic24/@@images/image/listing-square"

curl -i -X POST localhost:3000/api/v1/replaceAndPlay --data "service=webradio&type=webradio&title=BBC%20Radio%204&uri=http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p&albumart=https://radio-directory.firebaseapp.com/volumio/src/images/radio-thumbnails/BBC%20Radio%204%20FM.jpg"

What is now the best location to keep these scripted commands (bash scripts)? Only /media folder or could /usr/local/bin et similar be a valid and upgrade proof alternative?

New volumio version just broke the curl command.

Now its replying with “error” : “request type must be application/json”

Does anyone know why this is suddenly not working anymore after applying latest upgrade jul16?

Hi everyone (or whoever manages to read this post).

I feel like talking to myself in this community. What is going on? Can’t anyone give some sign of presence pls?

Last update broke the api commands I was using and nobody seems willing to give some advice or comments.

1 Like

to be honest, it’s not very clear to me what is the purpose of your experiment.

what use-case are you trying to cover?

Hi, I created myself a volumio dedicated 20-key keyboard to quickly change the most frequently used settings like volume, pause, and play my favourite radio stations o playlists on the fly, without having to open the smartphone and do the many steps to reach a specific command in the web UI. Sometimes it’s ok to use the web UI, browse the music library, etc. but sometimes its just faster to use a dedicated physical “button”.

So the keyboard has been programmed to type a specific text string for each key in its firmware like “volumio stop” which leverages the terminal volume command line client. Unfortunately this command utility does not support to play radio stations so I had to explore alternatives and this is where I tried to stick to official API (REST API section) documentation and use the curl tool to send http requests via bash scripts that are started by the keyboard macros.

I was able to make this work perfectly fine with the above scripted commands but since the last volume update things have changed and I haven’t yet found an alternative compatible “syntax”.

1 Like

OK, now it’s clear.

If it was working before, I think it’s a problem with outdated documentation

@volumio what kind of changes have been applied in recent updates?

Bump bump @volumio bump

Hi,

Great thread… I am also trying to play an audio stream url using curl on Volumio and used your findings above.

I am getting the same error as you now
“error” : “request type must be application/json”

Wondering if you managed to get it working. Thanks.

IIRC there was a change to the API to allow only JSON requests…
So you’ll need to set the proper header (-H) when you make your request.
Something along these lines…

curl --header "Content-Type: application/json" \
  --data '<DATA>' \
localhost:3000/api/v1/

EDIT: Oh yes, here it is!

N.B: I really think we should start proper semver for the BE/FE so that such “breaking” changes are documented somewhere.

Thank you.

could you help me with an example of how to set the header in the 3 example streams mentioned by Astaroth2k here Play a radio url via curl?

It just needs to be valid JSON.

volumio@volumio:~$ curl -i --header "Content-Type: application/json" localhost:3000/api/v1/replaceAndPlay --data '{
  "service": "webradio",
  "type": "webradio",
  "title": "Nova%20La%20Nuit",
  "uri": "http://nova-ln.ice.infomaniak.ch/nova-ln-128",
  "albumart": "https://www.nova.fr/sites/default/files/2020-06/Nova%20la%20Nuit_1.jpg"
}'
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization, Content-Length, X-Requested-With
Content-Type: application/json; charset=utf-8
Content-Length: 22
ETag: W/"16-jY45PQN+HurxTHjG3dOzCLMmswA"
Vary: Accept-Encoding
Date: Wed, 26 Aug 2020 14:53:01 GMT
Connection: keep-alive

{"response":"success"}volumio@volumio:~$
2 Likes

Thanks for taking the time and posting a working example! :v: