4

I'd like to create a number of Liquidsoap sources with the same script but with a few variables e.g. station name.

I've seen that I can include a config.liq, for example, but it would be nice if I could read my configuration parameters from something not tied to the language, such as JSON. Liquidsoap has an of_json function but I'm unclear how I can read from a JSON file rather than a JSON string.

What can I do to have an configuration file that is not tied to the scripting language?

Brad
  • 159,648
  • 54
  • 349
  • 530
Dan
  • 3,229
  • 2
  • 21
  • 34

3 Answers3

2

I'm not sure when the facility was added to Liquidsoap (I have 1.2.1 here,) but assuming you have foo.json such as:

[
    {
         station_name : "Some Station",
         station_url  : "http://example.com/"
    },
    {
         station_name : "Some Other Station",
         station_url  : "http://other.example.com/"
    }
]

Then you should be able to read and parse it with something like:

m = file.contents("config.json")
print(of_json(default=[[("error", "badfile")]], m));

Giving

[[("station_name","Some Station"), ("station_url","http://example.com/")], [("station_name","Some Other Station"), ("station_url","http://other.example.com/")]]

If your JSON is a different format you would need to adjust the default template to the of_json

Hope that helps.

1

Good question. I don't have exact code for you, but I've actually been able to read from HTTP by shelling out to cURL. (And then, I found the built-in functions for HTTP requests, but those don't apply to your case I don't think.)

If you can't find a command to read a file directly, just use system() with a call to cat to dump the file.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Great idea, that worked. The function to use is get_process_output because because that returns the output of the command as a string whereas system() returns a unit. – Dan Oct 20 '14 at 10:12
0

I can't find any commands to read a file directly from liquidsoap either.

You could always use environment variables:

station_name = getenv("STATION_NAME")

freedrull
  • 2,194
  • 4
  • 21
  • 33