2016-08-12 1 views
0

私は歌のタイトルとさstreamName(DJ)のリスナーを確認するには、このスクリプトを持っていますが、ステータス1のショーは、統計情報が他のショーをオフラインをつかむ何場合、それは変換shoucast統計は

それがあるべき必要があるようにそれは常に動作しません。それが動作するように望んでいない、私は彼がそれを再コーディングしたくない友人オフこのコードを得たが、私はそれがHERESにコード

<?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); 

    } 

答えて

0
Shoutcastは2.0

で動作させるためにどのよう見当がつかないあなたは、コード内のエラーを持っている

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

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

する必要がありますその後、あなたのステーションがオフラインになっているので、0と1を置き換える - ストリームが生きていると、ストリームの状態が0である場合 - あなたは、ストリームの状態が 1であれば、また ()

でそれを呼び出す必要がありますので

getSTATUSは、関数でありますあなたの比較。

+0

ありがとうございました。 – Skye

+0

が、私はこれは、あなたがそれはShoutcastは2.0 'パブリック関数radioInfo($のURL)のために働くことを得ることができますShoutcastは1.0のために働くことになっているこのスクリプト – Skye

+0

{$は付き合え \t \t \t \t \t \tでもう少し助けが必要=アレイ( \t \t \t \t \t \t \t 'HTTP' =>配列( \t \t \t \t \t \t \t \t \t 'メソッド' => 'GET'、 \t \t \t \t \t 'ヘッダ' => 'のUser-Agent:シャウトキャストソングステータス(Mozillaの互換)\ R \ n' は \t \t \t \t \t \t \t \t) \t \t \t \t \t \t)。 \t \t \t $ context = stream_context_create($ opts); \t \t \t $ data = @file_get_contents($ url、false、$ context); \t \t \t(するpreg_match($データ、 "/ストリームは/アップとプライベート(記載されていない)現在")){ \t \t \t \t \t \t \t $真= [ 'オンライン']を返す場合。 ' – Skye