-3

ストリーミングサーバーからIceCast統計(リスナー、現在の曲)を取得するために、このphpスクリプトに出くわしました。

ここに掲載されました

PHPを使用してIcecast2統計を表示する

<?php

/*
 * SCRIPT CONFIGURATIONS
*/
$SERVER = 'http://myserver.com:8000'; //URL TO YOUR ICECAST SERVER
$STATS_FILE = '/status.xsl'; //PATH TO STATUS.XSL PAGE YOU CAN SEE IN YOUR BROWSER (LEAVE BLANK UNLESS DIFFERENT)

///////////////////// END OF CONFIGURATION --- DO NOT EDIT BELOW THIS LINE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//create a new curl resource
$ch = curl_init();

//set url
curl_setopt($ch,CURLOPT_URL,$SERVER.$STATS_FILE);

//return as a string
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

//$output = our stauts.xsl file
$output = curl_exec($ch);

//close curl resource to free up system resources
curl_close($ch);

//build array to store our radio stats for later use
$radio_info = array();
$radio_info['server'] = $SERVER;
$radio_info['title'] = '';
$radio_info['description'] = '';
$radio_info['content_type'] = '';
$radio_info['mount_start'] = '';
$radio_info['bit_rate'] = '';
$radio_info['listeners'] = '';
$radio_info['most_listeners'] = '';
$radio_info['genre'] = '';
$radio_info['url'] = '';
$radio_info['now_playing'] = array();
   $radio_info['now_playing']['artist'] = '';
   $radio_info['now_playing']['track'] = '';

//loop through $ouput and sort into our different arrays
$temp_array = array();

$search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>";
$search_td = array('<td class="streamdata">','</td>');

if(preg_match_all("/$search_for/siU",$output,$matches)) {
   foreach($matches[0] as $match) {
      $to_push = str_replace($search_td,'',$match);
      $to_push = trim($to_push);
      array_push($temp_array,$to_push);
   }
}

//sort our temp array into our ral array
$radio_info['title'] = $temp_array[0];
$radio_info['description'] = $temp_array[1];
$radio_info['content_type'] = $temp_array[2];
$radio_info['mount_start'] = $temp_array[3];
$radio_info['bit_rate'] = $temp_array[4];
$radio_info['listeners'] = $temp_array[5];
$radio_info['most_listeners'] = $temp_array[6];
$radio_info['genre'] = $temp_array[7];
$radio_info['url'] = $temp_array[8];

$x = explode(" - ",$temp_array[9]);
$radio_info['now_playing']['artist'] = $x[0];
$radio_info['now_playing']['track'] = $x[1];

?>

スクリプトを挿入する場所を誰かが知っていますか?

4

2 に答える 2

1

必要なものはすべてにあります$radio_info。これは、どこにでも簡単に出力できます。

echo htmlspecialchars($radio_info['now_playing']['artist'] . ' - ' . $radio_info['now_playing']['track']);
于 2012-08-15T16:48:37.857 に答える
0

統計をxmlでダウンロードし、SQLにインポートする統計を毎日処理します

// download icecast stats
$username = '';
$password = '';
$url = 'localhost:8000/stats';
$file = 'h:\\stream\\stats\\' . date('Ymd_His') . '.xml';

c:\\stream\\curl.exe --user $username:$password $url -o $file;

//Process to sql by looping through the stats folder and get filenames...

foreach(glob($path . "*.xml") as $filename) {
   $content = file_get_contents($filename);
   $filename = substr($filename, strlen($path), -4);
    process($db, $filename, $content);
  }
   function process($db, $filename, $content) {
    $xml = new SimpleXMLElement($content);
    if(!preg_match('/^(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})$/', $filename, 
    $date)) throw new Exception('Filename does not look like a date.');

foreach($xml->source as $source) {
    $date_sql = $db->real_escape_string(sprintf("%04d-%02d-%02d %02d:%02d:%02d", 
    $date[1], $date[2], $date[3], $date[4], $date[5], $date[6]));
    $stream_sql = $db->real_escape_string($source->genre);
    $title_sql = $db->real_escape_string($source->title);
    $listeners_sql = (int)$source->listeners;

    $sql = "REPLACE INTO song_stats SET date_and_time = '$date_sql', stream = 
   '$stream_sql', title = '$title_sql', listeners = $listeners_sql";

    $db->query($sql);
   }


 }
于 2019-05-26T04:30:05.877 に答える