Azuracast: HELP Please

Created on 15 Mar 2018  路  5Comments  路  Source: AzuraCast/AzuraCast

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.

question

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.

Note, I'll use demo.azuracast.com as the site url and 1 as 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:

All 5 comments

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.com as the site url and 1 as 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

susl16c picture susl16c  路  3Comments

verdantsquare picture verdantsquare  路  3Comments

Blazedallup picture Blazedallup  路  3Comments

TogarUshindi picture TogarUshindi  路  3Comments

Rafaelrds2017 picture Rafaelrds2017  路  3Comments