【发布时间】: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);
}
【问题讨论】: