Angablade Posted February 5, 2010 Share Posted February 5, 2010 The first bit is tested and works for me. This is the code that uploads the videos to youtube. I commented this code a lot. <?php //** Configuring the emailing area for the upload **// $my_to = ""; // the email that youtube gives you for uploading a video from your phone (http://www.youtube.com/mobile) $my_file = ""; //The actual file name $my_path = $_SERVER['DOCUMENT_ROOT']."/your_path_here/"; // The directory that the file is located in $my_name = ""; // Just your name or something $my_mail = ""; // Email used to register the youtube account with $my_replyto = ""; // Leave empty $my_subject = ""; // Title of video $my_message = ""; // Description of video //** PHP mail function that will send the email || DO NOT EDIT THIS **// function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; mail($mailto, $subject, "", $header); } //** Mailing the actual Video to youtube for uploading || DO NOT EDIT THIS **// mail_attachment($my_file, $my_path, $my_to, $my_mail, $my_name, $my_replyto, $my_subject, $my_message); //** Add any code to delete the uploaded video or something here **// // Do what you wish here. delete the video, do something else.. idc ?> This next bit I have not fully tested. This bit of code should grab information about a video, and also preform a 'I'm feeling lucky' kind of search for youtube. <?php Function sectomin($seconds) { $minutes = 0; while($seconds > 60) { $minutes += 1; $seconds -= 60; }; If(strlen($seconds) == 1) { $seconds = 0 . $seconds; }; Return $minutes . ":" . $seconds; } Function Get_Info($youtubeurl) { $rpme = array("http://","www.",".com","youtube"); $VID = str_ireplace($rpme, "", $youtubeurl); $VID = substr($VID, strpos($VID,"v=") + 3, strlen($VID) - strpos($VID,"v=") + 3); If(strstr($VID,"&")) { $VID = substr($VID, 0, strpos($VID,"&") - 1); } $html = str_ireplace("\n","",fopen("http://www.youtube.com/watch?v=" . $VID, "r")); $Video_id = $VID; $title = substr($html, strpos($html,"<title>") + 18, strlen($html) - strpos($html,"<title>") + 18); $title = substr($title, 0, strpos($title,"</title>") - 1); $author = substr($html, strpos($html,"hLink fn n contributor") + 25, strlen($html) - strpos($html,"hLink fn n contributor") + 25); $author = substr($author, 0, strpos($author,"</a>")); $views = substr($html, strpos($html,"watch-view-count") + 19, strlen($html) - strpos($html,"watch-view-count") + 19); $views = substr($views, 0, strpos($views,"</span>")); $rate_count = substr($html, strpos($html,"ratingMessage"), strlen($html) - strpos($html,"ratingMessage")); $rate_count = substr($rate_count, 0, strpos($rate_count,"</span>")); $rate_count = substr($rate_count, strpos($rate_count,"<span"), strlen($rate_count) - strpos($rate_count,"<span")); $rate_count = str_ireplace("><span class=\"smallText\">", "", $rate_count); $holder = str_ireplace("\n","",fopen("http://www.youtube.com/get_video_info?video_id=" . $VID, "r")); $rating = substr(holder, strpos($holder,"avg_rating=") + 12, strlen($holder) - strpos($holder,"avg_rating=") + 12); $rating = substr($rating, 0, strpos($rating," . ")); $rating = substr($rating, 1, 3); $description = substr($html, strpos($html,"watch-video-desc description") + 45, strlen($html) - strpos($html,"watch-video-desc description") + 45); $description = substr($description, 0, strpos($description,"</span>")); $rpne = array("<br>","<br/>","<br />"); $description = str_ireplace($rpne, "", $description); $length = substr($html, strpos($html,"\"length_seconds") + 20, strlen($html) - strpos($html,"\"length_seconds") + 20); $length = substr($length, 0, strpos($length,"\"")); $length = sectomin($length); $rpqe = array("'",";"); $hostlang = str_ireplace($rpqe, "", substr($html, strpos($html,"ytLocale = ") + 12, strlen($html) - strpos($html,"ytLocale = ") + 12)); $keywords = substr($html, strpos($html, "keywords") + 12, strlen($html) - strpos($html, "keywords") + 12); $keywords = substr($keywords, 0, strpos($keywords,"\"")); $keywords = str_ireplace("%2C", ", ", $keywords); $token = substr($html, strpos($html,", \"t\":") + 9, strlen($html) - strpos($html,", \"t\":") + 9); $token = substr($token, 0, strpos($token, "\"")); $token = str_ireplace("%3D", "=", $token); $thumbnailurl = "http://i3.ytimg.com/vi/" . $VID . "/default.jpg"; Return array($title, $length, $rating, $rate_count, $author, $Description, $keywords, $views, $hostlang, $token, $thumbnailurl, $Video_id); } Function do_search($keywords) { $url = "http://www.youtube.com/results?search_query=" . str_ireplace(" ", "+", $keywords); $html = str_ireplace("\n","",fopen($url, "r")); $VID = substr($html, strpos($html,"video-main-content-"), strlen($html) - strpos($html,"video-main-content-")); $VID = substr($VID, 0, strpos($html,"\"") - 1); Return "http://www.youtube.com/watch?v=" . $VID; } ?> Questions? Comments? Suggestions? Please post them below. I should be able to answer them fairly quickly if I am paying attention. I am releasing this here because I know that I sent Darren a copy, but he is busy, so let the community benefit from the work! If you use this code in something, please post it here. I would love to see what you did with this code. I would also like to state that I would like some form of credit, IF you use this for commercial use. Other then that. Have fun muxxing with the code. I hope you have fun with it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.