MadMakz
/
Misc-Tools
Archived
1
0
Fork 0

Added PHP/Hitbox/hitboxstatus.php

master
MadMakz 8 years ago
parent 7a107c480b
commit 16e5ace5f2

@ -0,0 +1,107 @@
<?php
/*
* HitboxStatus
* Copyright (C) 2014 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/>.
*
*
* Usage: echo _hitbox_status("<hitbox channel/username>");
*
*/
error_reporting(0);
function _hitbox_status($channel = false){
if(isset($channel)){
$name = $channel;
}
else{
$name = "hitboxlive";
}
$stream = "http://api.hitbox.tv/media/live/".$name;
$stream = json_decode(_file_get_contents_curl($stream), true);
$account = "http://api.hitbox.tv/user/".$name;
$account = json_decode(_file_get_contents_curl($account), true);
if(!$account["user_name"]){
$return = "Unknown channel.";
return $return;
}
if($stream["livestream"][0]["media_is_live"] != 0){
$txt = "<b>".$stream["livestream"][0]["media_status"]."</b><br>";
$txt .= "<small><b>".$account["user_name"]."</b><br><br>";
$txt .= "<b>Live!</b><br><br>";
if(!empty($stream["livestream"][0]["category_name"])){
$txt .= "<b>Playing:</b> ".$stream["livestream"][0]["category_name"]."<br><br>";
$boxart = "http://edge.sf.hitbox.tv".$stream["livestream"][0]["category_logo_large"];
}else{
$boxart = "http://i.imgur.com/bwqCxgg.jpg";
}
$txt .= "<b>Viewers:</b> ".$stream["livestream"][0]["media_views"]."</small><br>";
}
else{
$txt = "<b>".$account["user_name"]."</b><br><br>";
$txt .= "<small><b>Offline.</b></small><br>";
$boxart = "http://i.imgur.com/TqKeUSn.jpg";
}
$txt .= "<br><a href=\"http://hitbox.tv/".$account["user_name"]."\" 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 width=\"136\" height=\"190\" src=\"".$boxart."\" alt=\"\">
</td>
</tr>
</tbody>
</table>";
return $return;
}
/* 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;
}
?>