anyone knows or can give a sample script to get this API data like Live DJ stream sothat i can make it display in a website? i really struggling for this one. thanks in advance.
Hi,
You can find the documentation for the API there: http://azuracast.com/api/
What you seem to be interested is about the "now playing" data. Here's an example for accessing the DJ information and the current title, in Javascript or PHP.
Note, I'll use
demo.azuracast.comas the site url and1as the station ID.
Make sure to use your own.
The API path you want to query is /api/newplaying/1 (if 1 is you station ID).
The full URL would be: https://demo.azuracast.com/api/nowplaying/1.
To get that with Javascript:
// API Endpoint
var url = 'https://demo.azuracast.com/api/nowplaying/1'
// Fetch the remote file
fetch(url)
.then(function (request) {
// Take the request and parse the data as json
return request.json()
})
.then(function (json) {
// Now we extract the values we want
var live = json.live.is_live // "true" if it is live
var streamer = json.live.streamer_name // name of the streamer
var title = json.now_playing.song.text // current song title
// Here you can put the code that will
// display those three values on the webpage,
// like with jQuery or something...
})
Here's for PHP:
<?php
// API Endpoint
$url = 'https://demo.azuracast.com/api/nowplaying/1';
// Fetch and parse data
$content = file_get_contents($url);
$data = json_decode($content);
$live = $data['live']['is_live']; // "true" if it is live
$streamer = $data['live']['streamer_name']; // name of the streamer
$title = $data['now_playing']['song']['text']; // current song title
// And then you use those three values on your page,
// or send back a JSON or anything you need...
Feel free to search about how to display those values on your website online, as this will fall out of scope of this project. :wink:
@mkody thank you so much.
php don't work
@preterive This issue is closed, and your issue doesn't seem to relate to it. Please create a new issue if you need help.
$data = json_decode($content, true); is the correct
Most helpful comment
Hi,
You can find the documentation for the API there: http://azuracast.com/api/
What you seem to be interested is about the "now playing" data. Here's an example for accessing the DJ information and the current title, in Javascript or PHP.
The API path you want to query is
/api/newplaying/1(if1is you station ID).The full URL would be:
https://demo.azuracast.com/api/nowplaying/1.To get that with Javascript:
Here's for PHP:
Feel free to search about how to display those values on your website online, as this will fall out of scope of this project. :wink: