Twitch.tv php online offline stream code..
<?php
class streamer
{
public $streamID;
public $name;
public $race;
public $raceImage;
public $online;
public function __construct($nName, $nRace, $nStreamID) {
$this->name = $nName;
$this->race = $nRace;
$this->streamID = $nStreamID;
$this->race = strtolower($this->race);
switch($this->race) {
case "t":
$this->raceImage = "http://europe-elite.net/wp-content/uploads/2013/06/Ticon_small.png";
break;
case "p":
$this->raceImage = "http://europe-elite.net/wp-content/uploads/2013/06/Picon_small.png";
break;
case "z":
$this->raceImage = "http://europe-elite.net/wp-content/uploads/2013/06/Zicon_small.png";
break;
case "r":
$this->raceImage = "http://europe-elite.net/wp-content/uploads/2013/06/sRandomIcon.png";
break;
}
$id = $this->streamID;
$json_file = file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$id}", 0, null, null);
$json_array = json_decode($json_file, true);
if ($json_array[0]['name'] == "live_user_{$id}") {
$this->online = true;
}
else {
$this->online = false;
}
}
// Sort function
static function cmp_obj($a, $b)
{
$al = strtolower($a->name);
$bl = strtolower($b->name);
if ($al == $bl) {
return 0;
}
return ($al > $bl) ? +1 : -1;
}
}
$streams = array(
new streamer("Myaura", "t", "myaurasc2"),
);
//usort($streams, cmp_obj);
echo "<ul>";
foreach($streams as $stream)
{
echo "<li>";
if ($stream->online)
{ ?>
<img src = "http://europe-elite.net/wp-content/uploads/2013/06/icon-online.png" />
<?php }
else
{ ?>
<img src = "http://europe-elite.net/wp-content/uploads/2013/06/icon-offline.png" />
<?php } ?>
<img src = "<?php echo $stream->raceImage; ?>" />
<?php
echo $stream->name;
echo "</li>";
}
echo "</ul>";
No comments:
Post a Comment