2013-01-07 14:11:08 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* TwitchStatus
|
2014-02-15 14:53:03 +01:00
|
|
|
* Copyright (C) 2013-2014 Maximilian "MadMakz" Lotz
|
2013-01-07 14:11:08 +01:00
|
|
|
*
|
|
|
|
* http://madmakz.com/
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 3 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
error_reporting(0);
|
|
|
|
|
|
|
|
if(isset($_GET["channel"])){
|
|
|
|
$name = $_GET["channel"];
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$name = "twitch";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$stream = "https://api.twitch.tv/kraken/streams/".$name;
|
2014-02-15 15:18:51 +01:00
|
|
|
$stream = json_decode(_file_get_contents_curl($stream), true);
|
2013-01-07 14:11:08 +01:00
|
|
|
$account = "https://api.twitch.tv/kraken/channels/".$name;
|
2014-02-15 15:18:51 +01:00
|
|
|
$account = json_decode(_file_get_contents_curl($account), true);
|
2013-01-07 14:11:08 +01:00
|
|
|
|
|
|
|
if(!$account["display_name"]){
|
|
|
|
exit("Unknown channel.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if($stream["stream"] != null){
|
2014-02-15 15:18:51 +01:00
|
|
|
$txt = "<b>".$stream["stream"]["channel"]["status"]."</b><br>";
|
|
|
|
$txt .= "<small><b>".$account["display_name"]."</b><br><br>";
|
|
|
|
$txt .= "<b>Live!</b><br><br>";
|
2014-02-16 17:42:58 +01:00
|
|
|
if(!empty($stream["stream"]["game"])){
|
|
|
|
$txt .= "<b>Playing:</b> ".$stream["stream"]["game"]."<br><br>";
|
|
|
|
$boxart = "http://static-cdn.jtvnw.net/ttv-boxart/".$stream["stream"]["game"].".jpg";
|
|
|
|
}else{
|
|
|
|
$boxart = "http://i.imgur.com/bwqCxgg.jpg";
|
|
|
|
}
|
2013-01-07 14:11:08 +01:00
|
|
|
$txt .= "<b>Viewers:</b> ".$stream["stream"]["viewers"]."</small><br>";
|
|
|
|
}
|
|
|
|
else{
|
2014-02-15 15:18:51 +01:00
|
|
|
$txt = "<b>".$account["display_name"]."</b><br><br>";
|
2013-01-07 14:11:08 +01:00
|
|
|
$txt .= "<small><b>Offline.</b></small><br>";
|
2014-02-16 17:42:58 +01:00
|
|
|
$boxart = "http://i.imgur.com/TqKeUSn.jpg";
|
2013-01-07 14:11:08 +01:00
|
|
|
}
|
|
|
|
$txt .= "<br><a href=\"".$account["url"]."\" target=\"_blank\"><b>Go to Channel</b></a>";
|
|
|
|
|
|
|
|
$return = "<table height=\"auto\" border=\"0\" width=\"auto\">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td align=\"left\" valign=\"top\" style=\"max-width: 130px; word-wrap: break-word;\">
|
|
|
|
".$txt."
|
|
|
|
</td>
|
|
|
|
<td align=\"left\">
|
2014-02-15 14:53:03 +01:00
|
|
|
<img width=\"136\" height=\"190\" src=\"".$boxart."\" alt=\"\">
|
2013-01-07 14:11:08 +01:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>";
|
|
|
|
|
|
|
|
echo $return;
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS */
|
2014-02-15 15:18:51 +01:00
|
|
|
function _file_get_contents_curl($url, $agent = "My Agent", $cookie = false, $post = false){
|
2013-01-07 14:11:08 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
?>
|