MadMakz
/
Misc-Tools
Archived
1
0
Fork 0

Added simple PHP TwitchStatus script

This commit is contained in:
MadMakz 2013-01-07 14:11:08 +01:00
parent 3625243a79
commit e8658fe1cb
1 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?php
/*
* TwitchStatus
* Copyright (C) 2013 Maximilian "MadMakz" Lotz
*
* 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;
$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.");
}
$txt = "<b>".$account["display_name"]."</b><br><br>";
if($stream["stream"] != null){
$boxart = "http://static-cdn.jtvnw.net/ttv-boxart/".$stream["stream"]["game"].".jpg";
$txt .= "<small><b>Live!</b><br><br>";
$txt .= "<b>Playing:</b> ".$stream["stream"]["game"]."<br>";
$txt .= "<b>Viewers:</b> ".$stream["stream"]["viewers"]."</small><br>";
}
else{
$boxart = "http://img7.imageshack.us/img7/9652/offlineeu.jpg";
$txt .= "<small><b>Offline.</b></small><br>";
}
$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\">
<img src=\"".$boxart."\" alt=\"\">
</td>
</tr>
</tbody>
</table>";
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;
}
?>