【问题标题】:Converting shoucast statistics转换 shoucast 统计数据
【发布时间】:2016-08-12 02:36:02
【问题描述】:

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

   }

【问题讨论】:

    标签: php shoutcast


    【解决方案1】:

    你的代码有错误:

    if($radio-&gt;getSTATUS == 1) {

    应该是

    if($radio-&gt;getSTATUS() == 1) {

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

    此外,如果流状态为 1 - 流处于活动状态,如果流状态为 0 - 则您的电台处于离线状态,因此在比较中将 1 替换为 0。

    【讨论】:

    • 我需要更多关于这个脚本的帮助
    • 这应该适用于shoutcast 1.0 你能不能让它适用于shoutcast 2.0 public function radioInfo( $url ) { $opts = array( 'http' =&gt; array( 'method' =&gt; 'GET', 'header' =&gt; 'User-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n' ) ); $context = stream_context_create( $opts ); $data = @file_get_contents( $url, false, $context ); if( preg_match( "/Stream is currently up and private (not listed)/", $data ) ) { $return['online'] = true;
    • 我已经在 Shoutcast 2 服务器上测试了你的脚本,它可以工作。
    • 它确实抓住了正确的。这不是整个脚本
    猜你喜欢
    • 1970-01-01
    • 2014-07-11
    • 2022-01-25
    • 1970-01-01
    • 2021-08-14
    • 2017-10-13
    • 1970-01-01
    • 2022-09-30
    • 1970-01-01
    相关资源
    最近更新 更多