Skip to content

Instantly share code, notes, and snippets.

@lenivene
Last active April 6, 2021 02:32
Show Gist options
  • Save lenivene/c8952fcc0319207663dc to your computer and use it in GitHub Desktop.
Save lenivene/c8952fcc0319207663dc to your computer and use it in GitHub Desktop.
Get the song name in Shoutcast! Tested code in the "Rádio Vibe Sertaneja"
<?php
/*
* Name: Song name in ShoutCast
* Version: 1.16.10.15.0
* Description: Get the song name in Shoutcast, example of use ( ajax.php?domain='Your IP or domain name'&port='Number port' );
* Author: Lenivene Bezera
* Licence: MPL
*/
$ip = ( isset($_GET['domain']) && !empty($_GET['domain']) ) ? $_GET['domain'] : '69.46.88.19';
$port = ( isset($_GET['port']) && !empty($_GET['port']) ) ? $_GET['port'] : '80';
$url = 'http://' . $ip . ( ( isset($port) && $port != '80' ) ? ':' . $port : '' ) . '/7.html';
$fgc = @file_get_contents("{$url}", 'UTF-8',
stream_context_create(array(
'http' => array(
'header' => "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla/5.0 (compatible; FleetBot ShoutCast/2.1; +https://github.com/lenivene)\r\n\r\n"
)
))
);
if(isset( $fgc ) && empty( $fgc ) ) :
$return = NULL;
else :
$split = explode( ",", str_replace( "</body></html>", "", $fgc ) );
if( isset( $split[6] ) && empty( $split[6] ) ) :
$title = NULL;
else :
$i = 6;
while($i <= count($split)) {
if ($i > 7) :
@$title .= ", " . $split[$i];
else :
@$title .= $split[$i];
endif;
$i++;
}
$title = explode( '-', utf8_encode( !empty( $title ) ? $title : '' ) );
// Filtering char
$filter_cantor = array(' Feat. ', ' ft. ', ' feat. ', ' part. ', ' .part ', ' e ', ' & ', ' ');
$filter_musica = array(' Feat. ', ' ft. ', ' feat. ', ' part. ', ' .part ', ' & ', ' ');
$return = array(
'cantor' => str_replace( $filter_cantor, " ", $title[0]),
'musica' => str_replace( $filter_musica, " ", $title[1]),
);
endif;
endif;
/*
* Callback from JSONP
* Return example {"cantor":"Bruno Marrone", "musica":"Isso cê num conta"}
*/
if( isset( $_GET['callback'] ) && ! empty( $_GET['callback'] ) )
echo $_GET['callback'] . '(' .json_encode( $return ). ')';
else
echo json_encode( $return );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment