PHP Code:
<?php
// Youtube Developer Key. NEEDED TO WORK...
$YT_Developer_Key = "AI39si7SnB9SXTjsmmmbzQwMFmKqE4gkIU6EpBQsM9zKcgBl9ql7JsBbDebEZ51b_uDMQDSQ_egkBUkJf3J2qa35erTQhXTLnA";
// Get your Developer Key @ http://code.google.com/apis/youtube/dashboard/gwt/index.html
####### Account Info. ###########
$upload_acc***91;'youtube_com'***93;***91;'user'***93; = 'my-little-pony-@pages.plusgoogle.com'; //Set your username/email
$upload_acc***91;'youtube_com'***93;***91;'pass'***93; = 'anh123456'; //Set your password
##############################
$YT_Developer_Key = trim($YT_Developer_Key);
if (empty($YT_Developer_Key)) html_error("Developer Key is empty, please set yours @ {$page_upload***91;"youtube.com"***93;}.", 0);
if (!preg_match("@\.(mp4|flv|mpe?g|mkv|wmv|mov|3gp|avi)$@i", $lname, $fext)) echo "<p style='color:red;text-align:center;font-weight:bold;'>This file format doesn't looks like a video file allowed by youtube.</p>\n";
// Check for https support.
$usecurl = $cantuse = false;
if (!extension_loaded('openssl')) {
if (extension_loaded('curl')) {
$cV = curl_version();
if (in_array('https', $cV***91;'protocols'***93;, true)) $usecurl = true;
} else $cantuse = true;
if ($cantuse) html_error("Need OpenSSL enabled in php or cURL (with SSL) to use this plugin.");
}
$not_done = true;
$continue_up = $login = false;
$categories = array('People' => 'People & Blogs', 'Film' => 'Film & Animation', 'Autos' => 'Autos & Vehicles', 'Music' => 'Music', 'Animals' => 'Pets & Animals', 'Sports' => 'Sports', 'Travel' => 'Travel & Events', 'Games' => 'Gaming', 'Comedy' => 'Comedy', 'News' => 'News & Politics', 'Entertainment' => 'Entertainment', 'Education' => 'Education', 'Howto' => 'Howto & Style', 'Nonprofit' => 'Nonprofits & Activism', 'Tech' => 'Science & Technology');
if ($upload_acc***91;'youtube_com'***93;***91;'user'***93; && $upload_acc***91;'youtube_com'***93;***91;'pass'***93;) {
$_REQUEST***91;'up_login'***93; = $upload_acc***91;'youtube_com'***93;***91;'user'***93;;
$_REQUEST***91;'up_pass'***93; = $upload_acc***91;'youtube_com'***93;***91;'pass'***93;;
$auul = array();
$auul***91;'enable'***93; = true; // Change it to true and set the values below for use with auul.
$auul***91;'title'***93; = ""; // If Empty: <Filename>.
$auul***91;'description'***93; = ' '; // If Empty: 'Uploaded with rapidleech.'
$auul***91;'tags'***93; = ' '; // Add tags like 'tag1, tag 2, tag3' - If Invalid, 'Example tag, upload, rapidleech'.
$auul***91;'category'***93; = ' '; // 'People', 'Film', 'Autos', 'Music', 'Animals', 'Sports', 'Travel', 'Games', 'Comedy', 'News', 'Entertainment', 'Education', 'Howto', 'Nonprofit' or 'Tech' (Case sensitive) - If Invalid: 'People'.
$auul***91;'access'***93; = 'unlisted'; // 'public', 'unlisted' or 'private' (Case sensitive) - If Invalid: 'public'.
$auul***91;'embed'***93; = true; // Change to false for disable embedding.
if ($auul***91;'enable'***93;) {
$_REQUEST***91;'up_title'***93; = $auul***91;'title'***93;;
$_REQUEST***91;'up_description'***93; = $auul***91;'description'***93;;
$_REQUEST***91;'up_tags'***93; = $auul***91;'tags'***93;;
$_REQUEST***91;'up_category'***93; = $auul***91;'category'***93;;
$_REQUEST***91;'up_access'***93; = $auul***91;'access'***93;;
$_REQUEST***91;'up_embed'***93; = ($auul***91;'embed'***93; ? 'yes' : 'no');
$_REQUEST***91;'action'***93; = "FORM";
}
$login = true;
echo "<p style='text-align:center;font-weight:bold;'>Using Default Login and Pass.</p>\n";
}
if ($_REQUEST***91;'action'***93; == "FORM") $continue_up=true;
else {
echo "<table border='0' style='width:270px;' cellspacing='0' align='center'>
<form method='POST'>
<input type='hidden' name='action' value='FORM' />";
if (!$login) echo "<tr><td style='white-space:nowrap;'> YouTube or Google Login*</td><td> <input type='text' name='up_login' value='' style='width:160px;' /></td></tr>
<tr><td style='white-space:nowrap;'> Password*</td><td> <input type='password' name='up_pass' value='' style='width:160px;' /></td></tr>\n";
echo "<tr><td colspan='2' align='center'><br />Video options *<br /><br /></td></tr>
<tr><td style='white-space:nowrap;'>Title:</td><td> <input type='text' name='up_title' value='$lname' style='width:160px;' /></td></tr>
<tr><td style='white-space:nowrap;'>Category:</td><td> <select name='up_category' style='width:160px;height:20px;'>\n";
foreach($categories as $n => $v) echo "\t<option value='$n'>$v</option>\n";
echo "</select></td></tr>\n";
echo "<tr><td style='white-space:nowrap;'>Privacy: <br /><select name='up_access' style='width:8em;height:20px;'><option value='public'>Public</option><option value='unlisted'>Unlisted</option><option value='private'>Private</option></select></td><td style='white-space:nowrap;'><input type='checkbox' name='up_embed' value='no' /> Make video not embeddable</td></tr>";
echo "<tr><td colspan='2' align='center'><br /><small>By clicking 'Upload', you certify that you own all rights to the content or that you are authorized by the owner to make the content publicly available on YouTube, and that it otherwise complies with the YouTube Terms of Service located at <a href='http://www.youtube.com/t/terms' target='_blank'>http://www.youtube.com/t/terms</a></small><br /><br /><input type='submit' value='Upload' /></td></tr>\n";
echo "<tr><td colspan='2' align='center'><small>*You can set it as default in <b>{$page_upload***91;"youtube.com"***93;}</b></small></td></tr>\n";
echo "</table>\n</form>\n";
echo "<script type='text/javascript'>self.resizeTo(700,580);</script>\n"; //Resize upload window
}
if ($continue_up) {
$not_done = false;
// Login
echo "<table style='width:600px;margin:auto;'>\n<tr><td align='center'>\n<div id='login' width='100%' align='center'>Validating login</div>\n";
if (empty($_REQUEST***91;'up_login'***93;) || empty($_REQUEST***91;'up_pass'***93;)) html_error("Login or pass empty.", 0);
$post = array();
$post***91;"Email"***93; = urlencode($_REQUEST***91;'up_login'***93;);
$post***91;"Passwd"***93; = urlencode($_REQUEST***91;'up_pass'***93;);
$post***91;"service"***93; = 'youtube';
if (!$usecurl) {
$page = geturl ("www.google.com", 80, '/accounts/ClientLogin', "https://www.google.com/accounts/ClientLogin", 0, $post, 0, 0, 0, 0, 'https');
is_page($page);
} else {
$page = YT_cURL ("https://www.google.com/accounts/ClientLogin", $post);
}
is_present($page, "Error=BadAuthentication", "Login Failed: The login/password entered are incorrect.");
is_present($page, "Error=NotVerified", "Login Failed: The account has not been verified.");
is_present($page, "Error=TermsNotAgreed", "Login Failed: The account has not agreed to terms.");
is_present($page, "Error=CaptchaRequired", "Login Failed: Need CAPTCHA. (Not supported yet)... Or check you login and try again.");
is_present($page, "Error=Unknown", "Login Failed.");
is_present($page, "Error=AccountDeleted", "Login Failed: The user account has been deleted.");
is_present($page, "Error=AccountDisabled", "Login Failed: The user account has been disabled.");
is_present($page, "Error=ServiceDisabled", "Login Failed: The user's access to the specified service has been disabled.");
is_present($page, "Error=ServiceUnavailable", "Login Failed: Service is not available; try again later.");
if (!preg_match('@Auth=(***91;^\r|\n***93;+)@i', $page, $auth)) html_error("Login Failed: Auth token not found.", 0);
// Preparing upload
echo "<script type='text/javascript'>document.getElementById('login').style.display='none';</script>\n<div id='info' width='100%' align='center'>Preparing upload</div>\n";
$vtitle = trim($_REQUEST***91;'up_title'***93;);
$vtitle = empty($vtitle) ? $lname : rtags($vtitle);
$vdescription = trim($_REQUEST***91;'up_description'***93;);
$vdescription = empty($vdescription) ? "Uploaded with rapidleech." : rtags($vdescription);
$vtags = trim($_REQUEST***91;'up_tags'***93;);
if (!empty($vtags)) {
$vtag = explode(',', $vtags);
$vtags = '';
foreach ($vtag as $tag) {
$vtags .= rtags($tag, '') . ', ';
}
$vtags = substr($vtags, 0, -2);
}
if (empty($vtags)) $vtags = 'Example tag, upload, rapidleech';
if (array_key_exists($_REQUEST***91;'up_category'***93;, $categories)) $vcategory = $_REQUEST***91;'up_category'***93;;
else $vcategory = "People";
$xml2 = "\r\n";
$xml = "<?xml version='1.0'?>\r\n<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:yt='http://gdata.youtube.com/schemas/2007'>\r\n";
$xml .= " <media:group>\r\n";
$xml .= " <media:title type='plain'>$vtitle</media:title>\r\n";
$xml .= " <media:description type='plain'>$vdescription</media:description>\r\n";
$xml .= " <media:keywords>$vtags</media:keywords>\r\n";
// @<atom:category term='(***91;^'***93;+)' label='(***91;^'***93;+)'***91;^>***93;+><yt:assignable/>@i
$xml .= " <media:category scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>$vcategory</media:category>\r\n";
if ($_REQUEST***91;'up_access'***93; != 'public') {
if ($_REQUEST***91;'up_access'***93; == 'unlisted') $xml2 .= " <yt:accessControl action='list' permission='denied'/>\r\n";
if ($_REQUEST***91;'up_access'***93; == 'private') $xml .= " <yt:private/>\r\n";
}
if ($_REQUEST***91;'up_embed'***93; == 'no') $xml2 .= " <yt:accessControl action='embed' permission='denied'/>\r\n";
$xml .= " </media:group>$xml2";
$xml .= "</entry>";
// Uploading
echo "<script type='text/javascript'>document.getElementById('info').style.display='none';</script>\n";
// UploadToYoutube($host, $port, $url, $dkey, $uauth, $XMLReq, $file, $filename)
$upfiles = UploadToYoutube("uploads.gdata.youtube.com", 80, "/feeds/api/users/default/uploads", $YT_Developer_Key, $auth***91;1***93;, $xml, $lfile, $lname);
// Upload Finished
echo "<script type='text/javascript'>document.getElementById('progressblock').style.display='none';</script>";
is_page($upfiles);
is_present($upfiles, "Invalid developer key");
if (preg_match('@<error>(.*)</error>@i', $upfiles, $err)) html_error("Error: (".htmlentities($err***91;1***93;, ENT_QUOTES).") .", 0);
if (!preg_match('@<yt:videoid>(***91;^<***93;+)</yt:videoid>@i', $upfiles, $vid)) html_error("Error: Video ID not found.", 0);
echo "<p style='text-align:center;font-weight:bold;'>Please check your video in your <a href='http://www.youtube.com/my_videos'>youtube page</a> for details/errors.<br />The '".lang(71)."' link is for go to 'edit video' page.</p>\n";
$download_link = "http://www.youtube.com/watch?v=".$vid***91;1***93;;
$adm_link = "http://www.youtube.com/my_videos_edit?ns=1&video_id={$vid***91;1***93;}&next=%2Fmy_videos";
}
function rtags($str, $rpl='_') {
$str = trim($str);
$str = str_replace(array('<', '>'), $rpl, $str);
return $str;
}
// Small cURL function for login (If OpenSSL isn't loaded and cURL have SSL support)
function YT_cURL($link, $post) {
$opt = array(CURLOPT_HEADER => 1, CURLOPT_REFERER => $link,
CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2");
$opt***91;CURLOPT_POST***93; = 1;
$opt***91;CURLOPT_POSTFIELDS***93; = formpostdata($post);
$ch = curl_init($link);
foreach ($opt as $O => $V) { // Using this instead of 'curl_setopt_array'
curl_setopt($ch, $O, $V);
}
$page = curl_exec($ch);
$errz = curl_errno($ch);
$errz2 = curl_error($ch);
curl_close($ch);
if ($errz != 0) html_error("YT:***91;cURL:$errz***93; $errz2");
return $page;
}
// upfile function edited for YT upload.
function UploadToYoutube($host, $port, $url, $dkey, $uauth, $XMLReq, $file, $filename) {
global $nn, $lastError, $sleep_time, $sleep_count;
if (!is_readable($file)) {
$lastError = sprintf(lang(65),$file);
return FALSE;
}
$fileSize = getSize($file);
$bound = "--------" . md5(microtime());
$saveToFile = 0;
$postdata .= "--" . $bound . $nn;
$postdata .= 'Content-Type: application/atom+xml; charset=UTF-8' . $nn . $nn;
$postdata .= $XMLReq . $nn;
$postdata .= "--" . $bound . $nn;
$postdata .= "Content-Type: application/octet-stream" . $nn . $nn;
$zapros = "POST " . str_replace ( " ", "%20", $url ) . " HTTP/1.1{$nn}Host: $host{$nn}Authorization: GoogleLogin auth=$uauth{$nn}GData-Version: 2.1{$nn}X-GData-Key: key=$dkey{$nn}Slug: $filename{$nn}Content-Type: multipart/related; boundary=$bound{$nn}Content-Length: " . (strlen($postdata) + strlen($nn . "--$bound--$nn") + $fileSize) . "{$nn}Connection: Close$nn$nn$postdata";
$errno = 0; $errstr = "";
$fp = @stream_socket_client("$host:$port", $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
if (!$fp) html_error(sprintf(lang(88),$host,$port));
if ($errno || $errstr) {
$lastError = $errstr;
return false;
}
echo "<p>";
printf(lang(90),$host,$port);
echo "</p>";
echo(lang(104).' <b>'.$filename.'</b>, '.lang(56).' <b>'.bytesToKbOrMb($fileSize).'</b>...<br />');
global $id;
$id = md5(time() * rand( 0, 10 ));
require(TEMPLATE_DIR . '/uploadui.php');
flush();
$timeStart = getmicrotime();
$chunkSize = GetChunkSize($fileSize);
fputs($fp, $zapros);
fflush($fp);
$fs = fopen($file, 'r');
$local_sleep = $sleep_count;
while ( ! feof ( $fs ) ) {
$data = fread ( $fs, $chunkSize );
if ($data === false) {
fclose($fs);
fclose($fp);
html_error (lang(112));
}
if (($sleep_count !== false) && ($sleep_time !== false) && is_numeric($sleep_time) && is_numeric($sleep_count) && ($sleep_count > 0) && ($sleep_time > 0)) {
$local_sleep --;
if ($local_sleep == 0) {
usleep($sleep_time);
$local_sleep = $sleep_count;
}
}
$sendbyte = fputs($fp, $data);
fflush($fp);
if ($sendbyte === false) {
fclose($fs);
fclose($fp);
html_error(lang(113));
}
$totalsend += $sendbyte;
$time = getmicrotime() - $timeStart;
$chunkTime = $time - $lastChunkTime;
$chunkTime = $chunkTime ? $chunkTime : 1;
$lastChunkTime = $time;
$speed = round($sendbyte / 1024 / $chunkTime, 2);
$percent = round($totalsend / $fileSize * 100, 2);
echo '<script type="text/javascript">pr('."'" . $percent . "', '" . bytesToKbOrMb ( $totalsend ) . "', '" . $speed . "');</script>\n";
flush();
}
fclose ($fs);
fputs ($fp, $nn . "--" . $bound . "--" . $nn);
fflush ($fp);
while (!feof($fp)) {
$data = fgets($fp, 16384);
if ($data === false) {
break;
}
$page .= $data;
}
fclose ($fp);
return $page;
}
//***91;15-7-2011***93; Written by Th3-822.
//***91;14-9-2011***93; Added error msg for Invalid Developer Key && Added text before Upload button. - Th3-822.
//***91;19-9-2011***93; Added more values for video upload, added auul support && Added function for use https with cURL if OpenSSL isn't loaded && Added a default Developer Key. - Th3-822.
?>
Bookmarks