. * */ error_reporting(0); if(isset($_GET["channel"])){ $name = $_GET["channel"]; } else{ $name = "twitch"; } $stream = "https://api.twitch.tv/kraken/streams/".$name; $stream = json_decode(_file_get_contents_curl($stream), true); $account = "https://api.twitch.tv/kraken/channels/".$name; $account = json_decode(_file_get_contents_curl($account), true); if(!$account["display_name"]){ exit("Unknown channel."); } if($stream["stream"] != null){ $txt = "".$stream["stream"]["channel"]["status"]."
"; $txt .= "".$account["display_name"]."

"; $txt .= "Live!

"; if(!empty($stream["stream"]["game"])){ $txt .= "Playing: ".$stream["stream"]["game"]."

"; $boxart = "http://static-cdn.jtvnw.net/ttv-boxart/".$stream["stream"]["game"].".jpg"; }else{ $boxart = "http://i.imgur.com/bwqCxgg.jpg"; } $txt .= "Viewers: ".$stream["stream"]["viewers"]."

"; } else{ $txt = "".$account["display_name"]."

"; $txt .= "Offline.
"; $boxart = "http://i.imgur.com/TqKeUSn.jpg"; } $txt .= "
Go to Channel"; $return = "
".$txt." \"\"
"; echo $return; exit; /* FUNCTIONS */ function _file_get_contents_curl($url, $agent = "My Agent", $cookie = false, $post = false){ $ch = curl_init(); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $agent); if($cookie){ curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIE, $cookie); } curl_setopt($ch, CURLOPT_URL, $url); if($post){ curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } $data = curl_exec($ch); curl_close($ch); return $data; } ?>