转换 shoucast 统计数据

Converting shoucast statistics

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

如果状态 1 显示统计抓取的内容,则应该是其他离线显示的内容。但它不想工作,我从一个朋友那里得到了这段代码,他不想重新编码,但我不知道如何让它与 shoutcast 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 - 那么你的站是离线的,所以在你的比较中用 0 替换 1。