Skip to content

Instantly share code, notes, and snippets.

@shortyxs
Last active December 22, 2022 12:21
Show Gist options
  • Save shortyxs/94ddb73f74fa1ad3e3d4e13f9b29419e to your computer and use it in GitHub Desktop.
Save shortyxs/94ddb73f74fa1ad3e3d4e13f9b29419e to your computer and use it in GitHub Desktop.
A simplified Version of the Icecast Title-Script from the @Radio-Zoom API
<?php
/**
* This script can be used to grab artist - title information from an Icecast2 server. No server Password is required because all information are available public.
*
* The default JSON File access on Icecast2 can be used on unhidden mount points only.
*
* @package
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Malte Schroeder <post@malte-schroeder.de>
* @copyright Copyright (c) 2017-2020 Malte Schroeder (http://www.malte-schroeder.de)
*
*/
header('Access-Control-Allow-Origin: *');
$server1 = 'your.server.something:80' ; //your icecast server address including port, without the ending "/"
$mount1 = '/192k.mp3' ; //your radio's mount point, with the leading "/"
error_reporting(0);
$stream1 = getStreamInfo($server1, $mount1);
if (($stream1['info']['status']) == 'OFF AIR') {
echo "Zur Zeit leider keine Titelinformaitionen";}
else {
echo $stream1['info']['artist_song'];
}
// Actually I don't remember where I found the code basis for his. If you recognize your code and want to be mentioned here, please just let me know.
function getStreamInfo($icecastserver, $icecastmount){
if($str = file_get_contents('http://'.$icecastserver.'/status-json.xsl?mount='.$icecastmount)){
#$str = utf8_decode($str);
$json_a = json_decode($str, true);
if(empty($json_a['icestats']['source']['bitrate'])) {
$stream['info']['status'] = 'OFF AIR';
}
else{
$stream['info']['status'] = 'ON AIR';
$stream['info']['title'] = $json_a['icestats']['source']['title'];
$stream['info']['description'] = $json_a['icestats']['source']['server_description'];
$stream['info']['type'] = $json_a['icestats']['source']['server_type'];
$stream['info']['start'] = $json_a['icestats']['source']['stream_start'];
$stream['info']['bitrate'] = $json_a['icestats']['source']['bitrate'];
$stream['info']['listeners'] = $json_a['icestats']['source']['listeners'];
$stream['info']['max_listeners'] = $json_a['icestats']['source']['listener_peak'];
$stream['info']['genre'] = $json_a['icestats']['source']['genre'];
$stream['info']['stream_url'] = $json_a['icestats']['source']['listenurl'];
$stream['info']['artist_song'] = $json_a['icestats']['source']['title'];
$x = explode(" - ",$json_a['icestats']['source']['title']);
$stream['info']['artist'] = $x[0];
$stream['info']['song'] = $x[1];
}
}
return $stream;
}
?>
@localhorst
Copy link

$stream['info']['title']
und
$stream['info']['artist_song']

haben die identische Quelle und somit immer denselben Wert: $json_a['icestats']['source']['title']

@elsilva0
Copy link

And How can we see the current artisst and title playing on our icecast server?

i put the code in a php page empty, then load it with my server, port, and mount point,, but nothing appears on the screen! Isnt the code complete? Thakn you.

@shortyxs
Copy link
Author

This is a tool Script that does not output anything directly. Either you modify it to output directly or you create another script that handles the output by calling this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment