Skip to content

Instantly share code, notes, and snippets.

@caseypugh
Created November 22, 2011 23:17
Show Gist options
  • Save caseypugh/1387379 to your computer and use it in GitHub Desktop.
Save caseypugh/1387379 to your computer and use it in GitHub Desktop.
Send your VHX shares to HipChat
<?
///
// Sample usage:
// php vhx_hipchat.php staff myroom authtoken
//
// Screenshot: http://sht.tl/xeT
//
$vhx_user = $argv[1]; // staff
$room_id = $argv[2]; // myroomname
$auth_token = $argv[3]; // 0e50371f002c458ee12926ae6cbdad
$color = !$argv[4] ? "random" : $argv[4];
$log_name = "vhx_log_" . md5($vhx_user . $room_id . $auth_token) . ".txt";
$last_share_id = @file_get_contents($log_name);
$videos = json_decode(file_get_contents("http://vhx.tv/{$vhx_user}/shared.json"));
if (intval($videos[0]->video->id) > intval($last_share_id) || !$last_share_id) {
// Some thumbnail hacking since VHX doesn't pass back custom thumbnail sizes yet
$thumb = str_replace('/0.jpg', '/default.jpg', $videos[0]->video->thumbnail_url);
$thumb = str_replace('200.jpg', '100.jpg', $thumb);
$comment = urlencode($videos[0]->video->share_comment);
$url = "http://vhx.tv{$videos[0]->video->permalink}";
$message = "<b><a href=\"{$url}\">{$videos[0]->video->title}</a></b><br /><b>{$vhx_user}</b>: <em>{$comment}</em><br /><a href=\"{$url}\"><img src=\"{$thumb}\" /></a>";
$curl = "curl -d format=json -d auth_token={$auth_token} -d room_id={$room_id} -d from='VHX' -d message='{$message}' -d color={$color} https://api.hipchat.com/v1/rooms/message";
shell_exec($curl);
file_put_contents($log_name, $videos[0]->video->id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment