Aviberry Scripts for Your Site

Download Aviberry scripts

Here you can find samples how using API and simple scripts you can integrate Aviberry to your site. To learn more about API refer to Aviberry API Wiki.

The following script allows sending API request for encoding video to video formats. Upload the following example.html file to your website along with the action.php processing script, changing the login and password to your actual ones at Aviberry. And then open http://yourserver.com/example.html file in your browser and test drive Aviberry conversion scripts.

example.html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aviberry Demo Script</title>
<style type="text/css">
    form table {
        width: 100%;
    }
    .col1 {
        width: 20%;
    }
    .col2 {
        width: 80%;
    }
    .text {
        width: 70%;
    } 
    option {
        padding-left: 20px;
    }
    .submit { 
        margin-top: 10px;
        padding: 0 5px 0 5px;
    } 
</style>
</head>
<body>
    
<h1>Aviberry Demo Script</h1>

<form action="action.php" method="post">
    <table>
        <tr>
            <td class="col1">Source URL [HTTP/FTP/S3]</td>
            <td class="col2">
                <input type="text" class="text" name="source_url" />
            </td>
        </tr>
        <tr>
            <td>Target URL [FTP/S3/mailto]</td>
            <td>
                <input type="text" class="text" name="target_url" />
            </td>
        </tr>
        <tr>
            <td>Format</td>
            <td>
                <select name="format_id">
                    <option value="">Please select a format...</option>
                    <optgroup label="Video:">
                        <option value="16500">AVI video, Xvid (.avi)</option>
                        <option value="16505">MPEG-4 video (.mp4)</option>
                        <option value="16501">MPEG-2 video (.mpeg)</option>
                        <option value="16503">WMV (.wmv)</option>
                        <option value="16508">QuickTime (mov)</option>						
                        <option value="16523">3GPP for cellphone (.3gp)</option>
                        <option value="16506">3GPP2 for cellphone (.3gp2)</option>						
                        <option value="16509">Flash video (.flv)</option>
                        <option value="16520">WebM (.webm)</option>						
                    </optgroup>
                    <optgroup label="Audio:">
                        <option value="16511">MP3 audio (.mp3)</option>
                    </optgroup>
                </select>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="submit" class="submit" value="Convert!" />
            </td>
        </tr>
    </table>
</form>

</body>
</html>

 

action.php processing script

<?php

//
// Main.
//
set_exception_handler('handleException');

// 
// Validate the request.
//
if (
	   (!isset($_POST['source_url']) || empty($_POST['source_url']))
	|| (!isset($_POST['target_url']) || empty($_POST['target_url']))
	|| (!isset($_POST['format_id'])  || empty($_POST['format_id']))
) {
	die('Bad request.');
}

//
// Build URL to access API.
//
define('AVIBERRY_API_HOST',     'www.aviberry.com');
define('AVIBERRY_API_KEY',      ''); // Specify yours.
define('AVIBERRY_API_PASS',     ''); // Specify yours.
define('AVIBERRY_API_VERSION',  'v1.1');
define('AVIBERRY_API_PROTOCOL', 'json');
define('AVIBERRY_API_URL_AUTHORIZED', 'http://' . AVIBERRY_API_KEY . ':' . AVIBERRY_API_PASS . '@' . AVIBERRY_API_HOST . '/api/' . AVIBERRY_API_VERSION . '/' . AVIBERRY_API_PROTOCOL . '/');

// 
// Prepare the request.
//
$methodName   = 'startConversion';

$methodParams = array();
$methodParams['source_url'] = $_POST['source_url'];
$methodParams['target_url'] = $_POST['target_url'];
$methodParams['preset']['format_id'] = $_POST['format_id'];

$request = array();
$request['version'] = '1.1';
$request['method']  = $methodName;
$request['params']  = $methodParams;

$request = json_encode($request);

//
// Send request.
//
try {
	$response = sendRequest(AVIBERRY_API_URL_AUTHORIZED, $request);
} catch(Exception $e) {
	throw new Exception('Unable to start conversion: ' . $e->getMessage());
}

//
// Process response.
//
$response = json_decode($response, true);
if (isset($response['error']))
	throw new Exception('Unable to start conversion: ' . $response['error']['message'], $response['error']['code']);

//
// Print result.
//	
die('<div class="message">' 
	. htmlspecialchars(sprintf('Conversion scheduled. ID: "%s".', $response['result'])) 
	. '</div>'
);



//
// Functions.
//
/**
 * Performs HTTP POST. 
 */
function sendRequest($url, $request) {
	$response = '';
	
	$opts = array (
		'http' => array (
			'method'  => 'POST',
			'header'  => 'Content-type: application/json',
			'content' => $request
		)
	);
	$context  = stream_context_create($opts);
	
	$fp = @fopen($url, 'r', false, $context);
	if (!is_resource($fp))
		throw new Exception('Can\'t access API.');
	
	while (!feof($fp))
		$response .= fread($fp, 8192);
	
	return $response;
}  

/**
 * Displays error.
 */
function handleException($e) {
	die('<div class="error">' . htmlspecialchars($e->getMessage()) . '</div>');
}

?>

 


Sounds good?
Go ahead and test-drive Aviberry conversion scripts today!
Download Now

Scripts video
made easy!

Using the Aviberry scripts makes video publishing fast and convenient, and it's so easy to use: just one button to hit and a simple settings page to complete, so you're not overwhelmed with complicated customizable options.

aviberry logo Ready to begin? Call Aviberry consultant at +1-314-732-0343 and we will provide you with the best options for your workflow.