Skip to content

Instantly share code, notes, and snippets.

@codepo8 codepo8/vidly.php
Created Dec 1, 2011

Embed
What would you like to do?
vid.ly conversion interface
<?php
$key = '{your key here}';
$message = '';
if(isset($_POST['send'])){
if($_POST['email'] !== '' && $_POST['url'] !== '') {
$query = '<?xml version="1.0"?>'.
'<query><action>AddMedia</action><userid>481</userid>'.
'<userkey>'.$key.'</userkey>'.
'<notify>'.$_POST['email'].'</notify>'.
'<Source><SourceFile>'.$_POST['url'].'</SourceFile>'.
'<CDN>AWS</CDN></Source></query>';
$url = 'http://m.vid.ly/api/';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'xml='.urlencode($query));
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);
if($xml->Success) {
$vid = $xml->Success->MediaShortLink->ShortLink;
$video = '<video controls width="100%" controls preload="none"'.
' poster="http://cf.cdn.vid.ly/'.$vid.'/poster.jpg">'.
'<source src="http://cf.cdn.vid.ly/'.$vid.'/mp4.mp4" '.
'type="video/mp4">'.
'<source src="http://cf.cdn.vid.ly/'.$vid.'/webm.webm" '.
'type="video/webm">'.
'<source src="http://cf.cdn.vid.ly/'.$vid.'/ogv.ogv" '.
'type="video/ogg">'.
'<a target="_blank" href="http://vid.ly/'.$vid.'">'.
'<img src="http://cf.cdn.vid.ly/'.$vid.'/poster.jpg" '.
'width="500"></a>'.
'</video>';
$message = '<div class="success"><h1>Conversion started</h1>'.
'<p>The video conversion is under way. '.
'You should get an email telling you so and an email when '.
'the video URL is ready. The code to copy & paste into '.
'the blog is:</p>'.
'<textarea>'.htmlspecialchars($video).' </textarea>';
} else {
$message = '<div class="error"><h1>Error</h1>'.
'<p>Something went wrong in the conversion,'.
'please try again.</p></div>';
}
} else {
$message = '<div class="error"><h1>Error</h1>'.
'<p>Please provide a video URL and email</p></div>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Convert video and get embed code</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<style>
*{margin:0;padding:0;}
footer,section,header{display:block;}
html {
background: -moz-linear-gradient(#333,#666);
background: -webkit-linear-gradient(#333,#666);
background: -ms-linear-gradient(#333,#666);
background: -o-linear-gradient(#333,#666);
background: linear-gradient(#333,#666);
height: 100%;
font-family: helvetica,arial,sans-serif;
font-size:20px;
}
section {
width: 700px;
margin: 0 auto;
border-radius: 5px;
padding:10px 20px;
background: -moz-linear-gradient(#fff,#999);
background: -webkit-linear-gradient(#fff,#999);
background: -ms-linear-gradient(#fff,#999);
background: -o-linear-gradient(#fff,#999);
background: linear-gradient(#fff,#999);
box-shadow: 4px 4px 10px rgba(0,0,0,0.7);
}
h1{
color: lime;
text-align: center;
padding: 20px;
font-weight: normal;
}
textarea{
width:90%;
font-size:14px;
margin:1em 0;
padding:2% 5%;
}
form div, form {
padding: .5em 0;
overflow: auto;
}
input{
font-size: 16px;
}
label{
font-weight: bold;
width: 5em;
float:left;
}
input[type=submit] {
float: right;
display: block;
font-size: 20px;
padding: 5px 10px;
border:none;
margin-right:10px;
border-radius:5px;
background: -moz-linear-gradient(#cfc,#696);
background: -webkit-linear-gradient(#cfc,#696);
background: -ms-linear-gradient(#cfc,#696);
background: -o-linear-gradient(#cfc,#696);
background: linear-gradient(#cfc,#696);
box-shadow: 4px 4px 5px rgba(0,0,0,0.7);
}
input[type=submit]:hover {
box-shadow: 2px 2px 4px rgba(0,0,0,0.7);
}
.error {
border: 2px solid #c00;
padding: 5px;
margin: 1em 0;
border-left:none;
border-right:none;
}
.error h1 {
font-size: 24px;
text-align:left;
padding:5px 0;
color: #c00;
}
.success {
border: 2px solid #090;
padding: 5px;
margin: 1em 0;
border-left:none;
border-right:none;
}
.success h1 {
font-size: 24px;
text-align:left;
padding:5px 0;
color: #090;
}
</style>
</head>
<body>
<header><h1>Vid.ly conversion and embed</h1></header>
<section>
<?php echo $message; ?>
<p>Simply add the URL of the video to convert below and you get the embed code. An email will inform you about the successful conversion. Conversion could take up to an hour.</p>
<form method="post">
<div><label for="email">Email:</label><input type="text" id="email" name="email"></div>
<div><label for="url">URL:</label><input type="text" id="url" name="url"></div>
<div><input type="submit" name="send" value="make it so"></div>
</form>
</section>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.