转换shoucast统计信息

时间:2016-08-12 02:36:03

标签: php shoutcast

我有这个脚本来检查歌曲标题和流名称(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);

   }

1 个答案:

答案 0 :(得分:0)

您的代码中有错误:

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

应该是

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

getSTATUS是一个函数,因此您应该使用()

来调用它

此外,如果流状态为1 - 流是活动的,如果流状态为0 - 那么您的工作站处于脱机状态,因此在比较中将0替换为0。