<?php
/*******************************************************************
* justintv.class.php
* Version: 0.1
* Author: Tyler Winfield
* Copyright (C) 2009, Tyler Winfield
* hide@address.com
* http://rionet.ca/
*
* Simple PHP object class for allowing simple communication with
* Justin.tv account(s).
*
* EXAMPLE
*
* $j = new JustinTV();
* $j->usernm = $channel-id
*
* if($j->openstats()) {
* if($j->getStreamStatus()) {
* //stream is online and information loaded
* } else {
* //stream is offline
* }
* } else {
* //server could not be connected to or is offline
* }
*
*******************************************************************
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*******************************************************************/
class JustinTV {
// Public
var $host; //not used
var $port; //not used
var $usernm;
var $passwd; //not used
//Private
var $_xml;
var $_error;
function openstats() {
$fp = fopen("http://api.justin.tv/api/stream/list.xml?channel=".$this->usernm, "r");
if (!$fp) {
$this->_error = "$errstr ($errno)";
return(0);
} else {
while (!feof($fp)) {
$this->_xml .= fgets($fp, 512);
}
fclose($fp);
if(!isset($this->_xml)) {
$this->_error = "Bad login";
return(0);
}
$xmlparser = xml_parser_create();
if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) {
$this->_error = "Unparsable XML";
return(0);
}
xml_parser_free($xmlparser);
return(1);
}
}
function getCurrentListenersCount() {
return($this->_values[$this->_indexes["STREAM_COUNT"][0]]["value"]);
}
function getServerGenre() {
return($this->_values[$this->_indexes["STREAM_TYPE"][0]]["value"]);
}
function getServerURL() {
return($this->_values[$this->_indexes["CHANNEL_URL"][0]]["value"]);
}
function getServerTitle() {
return($this->_values[$this->_indexes["TITLE"][0]]["value"]);
}
function getStreamHitsCount() {
return($this->_values[$this->_indexes["VIEWS_COUNT"][0]]["value"]);
}
function getStreamStatus() {
return($this->_values[$this->_indexes["UP_TIME"][0]]["value"]);
}
function getBitRate() {
return($this->_values[$this->_indexes["VIDEO_BITRATE"][0]]["value"]);
}
function geterror() { return($this->_error); }
}
?>