转换广播统计信息


Converting shoucast statistics

我有这个脚本来检查歌曲标题和streamname (DJ)听众,但它并不总是像它应该的那样工作

应该是如果status 1显示抓取的状态,否则显示脱机。但是它不想工作,我从一个朋友那里得到了这段代码,他不想重新编码,但我不知道如何使它与shooutcast 2.0一起工作

下面是代码

<?php
  class radioStuff {
/**
    Shoutcast specific class to grab server stats
*/
private $url = "http://sc.*REMOVED*.co.uk";
private $port = 80;
private $json_object;
public function __construct() {
    $ch = curl_init();
    // Disable SSL verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // Will return the response, if false it print the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Set the url
    curl_setopt($ch, CURLOPT_URL,$this->url . ':' . $this->port . '/stats?json=1');
    // Execute
    $result=curl_exec($ch);
    // Closing
    curl_close($ch);
    $this->json_object = json_decode($result);
}
public function getHabboUrl() {
    $imageString =  'http://www.habbo.com/habbo-imaging/avatarimage?user=' .     $this->json_object->servergenre . '&direction=4&head_direction=3&action=wlk&gesture=sml';
    return $imageString;
}
public function getCurrentListeners() {
    return $this->json_object->currentlisteners;
}
 public function getSTATUS() {
    return $this->json_object->streamstatus;
}
    public function getCurrentDJ() {
    return $this->json_object->servertitle;
}
   public function getCurrentSong() {
    return $this->json_object->songtitle;
   }
 }
$radio = new radioStuff();

if($radio->getSTATUS == 1) {
 $response = array(
 'dj' => 'Radio statistics are offline!',
 'song' => 'We are offline!', 'listeners' => ''
 );
 header('Content-Type: application/json');
 echo json_encode($response);

  } else {
 $response = array(
 'dj' => $radio->getCurrentDJ(),
 'song' => $radio->getCurrentSong(),
 'listeners' => $radio->getCurrentListeners()
  );
   header('Content-Type: application/json');
   echo json_encode($response);
   }

您的代码中有错误:

if($radio->getSTATUS == 1) {

应该

if($radio->getSTATUS() == 1) {

getSTATUS是一个函数,所以你应该用()

来调用它

同样,如果流状态为1 -流是活的,如果流状态为0 -那么你的站是离线的,所以在你的比较中将1替换为0。