Comparing
version 6 and
version 5 backThis code example uses the PEAR HTTP request lib.
It demonstrates how you can transfer a video, encode it in Flash format and get it back to your FTP in only one HTTP request.
getCurrentUser->id;
// The video you'll show on your site
// Note that the class Video is not defined, it's just an example
// to interact with the database
$video = new Video(array("user_id" => $my_site_user_id, "status" => "unavailable"));
$video->save();
$my_site_video_id = $video->id;
$req =& new HTTP_Request("http://heywatch.com/download.xml");
// Authenticate via your HeyWatch login / password
$req->setBasicAuth("johndoe", "foo");
// It's a POST request
$req->setMethod(HTTP_REQUEST_METHOD_POST);
// Add all the needed parameters
$req->addPostData("url", $video_url); //correct
// $req->addPostData("video_url", $video_url); //NOT correct
$req->addPostData("format_id", $format_id);
// Force encoding after the download is complete
$req->addPostData("automatic_encode", "true");
$req->addPostData("ftp_directive", $ftp);
$req->addPostData("ping_url_after_encode", $ping_after_encode);
$req->addPostData("ping_url_if_error", $ping_if_error);
// Some custom fields to track your own objects
// You'll receive them in the ping after encode / ping if error
$req->addPostData("my_site_user_id", $my_site_user_id);
$req->addPostData("my_site_video_id", $my_site_video_id);
// Send the request
if (!PEAR::isError($req->sendRequest())) {
echo $req->getResponseBody(); // XML response
}
?>
When all the process is done, you'll receive the HTTP notification at:
/ping/success.php
http: //myhost.com/videos
$video_location = "http://myhost.com/videos/".$filename;
$thumbnail_location = $video_location.".jpg";
// Update the video to be available on your site
$video = Video::find($video_id);
$video->setStatus = "available";
$video->setVideoLocation = $video_location;
$video->setThumbnailLocation = $thumbnail_location;
$video->save();
?>
If the process failed, you'll receive the notification at:
/ping/error.php
setStatus = "error";
$video->save();
// Send a mail to the user about the error
?>