Witajcie,
Od kilku dni szukam kodu, który będzie w stanie wyświetlić status transmisji z nowej platformy streamingowej jaką jest Hitbox.tv
W sieci natknąłem się na dodatek do wordpress'a, lecz nie jestem w stanie przekształcić go do swoich potrzeb.
Informacje od Hitbox:
http://developers.hitbox.tv/media
Inny kod, który znalazłem gdzies w sieci - zamiast generowania image chciałbym wyświetlić w echo logo, śledzących, ilość osób oglądających (oczywiście po ręcznym wprowadzeniu do kodu nazwy kanału).
<?php
header ("Content-type: image/png");
$channelName = htmlspecialchars($_GET['channel'], ENT_QUOTES);
$arialbd = "arialbd.ttf";
$arial = "arial.ttf";
$json_array = json_decode(file_get_contents('http://api.hitbox.tv/media/live/'.strtolower($channelName)), true);
$getImage = $json_array['livestream'][0]['channel']['user_logo_small'];
$getFollower = $json_array['livestream'][0]['channel']['followers'];
$getViewer = $json_array['livestream'][0]['channel']['livestream_count'] -1;
$getGame = $json_array['livestream'][0]['category_name'];
$imageURL = "http://edge.vie.hitbox.tv/$getImage";
if (!file_exists('user')) {
mkdir('user', 0777, true);
}
if (!file_exists('status')) {
mkdir('status', 0777, true);
}
$image = "user/".$channelName.".jpg";
file_put_contents($image, file_get_contents($imageURL));
if ($json_array['livestream'][0]['media_is_live'] == 1) {
$im = @ImageCreate (300, 64)
or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$background_color = ImageColorAllocate ($im, 247, 247, 247);
$text_color = ImageColorAllocate ($im, 71, 71, 71);
$name_color = ImageColorAllocate ($im, 72, 194, 52);
$online_color = ImageColorAllocate ($im, 222, 46, 46);
ImageTTFText ($im, 13, 0, 70, 21, $name_color, $arialbd, $channelName);
ImageTTFText ($im, 9, 0, 70, 38, $online_color, $arialbd, "LIVE");
ImageTTFText ($im, 9, 0, 98, 38, $text_color, $arial, "playing $getGame");
ImageTTFText ($im, 9, 0, 185, 55, $text_color, $arial, "Viewer: $getViewer");
ImageTTFText ($im, 9, 0, 70, 55, $text_color, $arial, "Follower: $getFollower");
} else {
$im = @ImageCreate (300, 64)
or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$background_color = ImageColorAllocate ($im, 247, 247, 247);
$text_color = ImageColorAllocate ($im, 71, 71, 71);
$name_color = ImageColorAllocate ($im, 72, 194, 52);
ImageTTFText ($im, 13, 0, 70, 21, $name_color, $arialbd, $channelName);
ImageTTFText ($im, 9, 0, 70, 38, $text_color, $arial, "Offline");
ImageTTFText ($im, 9, 0, 70, 55, $text_color, $arial, "Follower: $getFollower");
}
$profile = imagecreatefromjpeg("user/".$channelName.".jpg");
imagecopymerge($im, $profile, 8, 8, 0, 0, 50, 50, 100);
imagepng($im);
imagedestroy($im)
?>
Wordpress dodatek:
<?php
function _hitbox_status($channel = false){
$name = $channel;
$api = 'http://api.hitbox.tv/media/live/'.$name;
$hitbox = _file_get_contents_curl($api, 'WP Hitbox status widget');
if($hitbox['header']['http_code'] == '404'){
return '<li class="st-hitbox-widget-list-item"><span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$name.'</a></span><span class="st-hitbox-widget-indicator">Unknown channel</span></li>';
}elseif($hitbox['header']['http_code'] != '200'){
return '<li class="st-hitbox-widget-list-item"><span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$name.'</a></span><span class="st-hitbox-widget-indicator">Failed to connect to hitbox.tv api.</span></li>';
}
$stream = json_decode($hitbox['data'], true);
if($stream['livestream'][0]['media_is_live'] != 0){
$txt = '<span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$stream['livestream'][0]['media_user_name'].'</a></span>';
$txt .= '<span class="st-hitbox-widget-indicator">'.$stream['livestream'][0]['media_views'].'</span>';
$txt .= '<span class="st-hitbox-widget-status">'.$stream['livestream'][0]['media_status'].'</span>';
if(!empty($stream['livestream'][0]['category_name'])){
$txt .= '<span class="st-hitbox-widget-category">'.$stream['livestream'][0]['category_name'].'</span>';
$boxart = 'http://edge.sf.hitbox.tv'.$stream['livestream'][0]['media_thumbnail'];
}else{
$boxart = HITBOX_TV_WIDGET_URI.'/assets/images/unknown.jpg';
}
$txt .= '<span class="st-hitbox-widget-image"><a target="_blank" href="http://www.hitbox.tv/'.$name.'"><img src="'.$boxart.'" alt=""></a></span>';
}
else{
$txt = '<span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$stream['livestream'][0]['media_user_name'].'</a></span>';
$txt .= '<span class="st-hitbox-widget-indicator">Offline</span>';
$boxart = HITBOX_TV_WIDGET_URI.'/assets/images/offline.jpg';
/* $txt .= '<span class="st-hitbox-widget-image"><a target="_blank" href="http://www.hitbox.tv/'.$name.'"><img src="'.$boxart.'" alt=""></a></span>'; */
}
$return = '<li class="st-hitbox-widget-list-item">
'.$txt.'
</li>';
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);
$header = curl_getinfo($ch);
curl_close($ch);
return array('data' => $data, 'header' => $header);
}
?>
Czy ktoś spotkał się może z kodem, lub wie w jaki sposób pozyskać odpowiednie informacje i je wyświetlić?