function getYouTubeFlvUrl($pattern) { require_once "youtube-download-php/phptube.php"; $tube = new PHPTube(); $flv_http_path = $tube->download($pattern); return $flv_http_path; }
function GrabFlvFromYoutube($pattern) { require_once "include/youtube-download-php/phptube.php"; $tube = new PHPTube(); $flv_http_path = $tube->download($pattern); echo $flv_http_path; set_time_limit(0); $data = file_get_contents($flv_http_path); $new_flv_path = dirname(_FILE_) . '/flvs/' . $pattern . '.flv'; file_put_contents($new_flv_path, $data); return $new_flv_path; }
function upload() { $username = "******"; $password = "******"; $database = "youbama"; $youtube_username = "******"; $youtube_password = "******"; $file_prefix = "/var/www/youbama/static/videos/"; $link = mysql_connect(localhost, $username, $password); @mysql_select_db($database, $link) or die("Unable to select database"); $phptube = new PHPTube($youtube_username, $youtube_password); # Find all videos that haven't been uploaded yet $query = "SELECT * FROM `main_upload`, `main_video` WHERE `uploaded`=false AND main_upload.video_id=main_video.id"; $result = mysql_query($query, $link); $numrows = mysql_num_rows($result); print "Processing uploads...\n"; for ($i = 0; $i < $numrows; $i++) { $id = mysql_result($result, $i, "main_video.id"); $file = mysql_result($result, $i, "file"); $title = mysql_result($result, $i, "title"); $description = mysql_result($result, $i, "description"); # Upload to YouTube $youtube_id = $phptube->upload($file_prefix . $file, $title, "www.youbama.com youbama barack obama", $description, 25, "EN"); print "Uploaded {$file} ({$youtube_id})\n"; # Mark file as uploaded $query2 = "UPDATE `main_upload`, `main_video` SET `main_video`.`youtube_id`='{$youtube_id}', `uploaded`=true WHERE `main_video`.`id`='{$id}'"; $result2 = mysql_query($query2, $link); } mysql_close($link); }
private function DownloadVideo($url, $FileType = FT_VIDEO) { include ISC_BASE_PATH . "/livevideos/phptube.php"; include ISC_BASE_PATH . "/livevideos/functions.php"; @clearstatcache(); @ini_set('output_buffering', 'off'); // output buffer fix @ini_set('max_execution_time', 0); // time limit fix @ini_set('memory_limit', '1024M'); // memory problem fix //error_reporting(1); @ignore_user_abort(1); @set_time_limit(0); //@ob_end_clean(); @ob_implicit_flush(TRUE); $pattern = getPatternFromUrl($url); if ($FileType == FT_INSVIDEO) { $dir = GetConfig('InstallVideoDirectory'); } else { $dir = GetConfig('VideoDirectory'); } if (is_dir(sprintf("../%s", $dir))) { // Images and downloads will be stored within a directory randomly chosen from a-z. $randomDir = strtolower(chr(rand(65, 90))); if (!is_dir("../" . $dir . "/" . $randomDir)) { if (!@mkdir("../" . $dir . "/" . $randomDir, 0777)) { $randomDir = ''; } } } $patternName = $pattern . ".flv"; // $randomFileName = GenRandFileName($patternName); $fileName = $randomDir . "/" . $randomFileName; $dest = realpath(ISC_BASE_PATH . "/" . $dir); while (file_exists($dest . "/" . $fileName)) { $fileName = basename($randomFileName); $fileName = substr_replace($randomFileName, "-" . rand(0, 10000000000.0), strrpos($randomFileName, "."), 0); $fileName = $randomDir . "/" . $fileName; } $dest .= "/" . $fileName; $tube = new PHPTube(); $flv_http_path = $tube->download($pattern); $data = file_get_contents($flv_http_path); file_put_contents($dest, $data); return $fileName; if (filesize($dest) > 0) { return $fileName; } else { return "failed"; } }
<?php include_once "phptube.php"; $username = "******"; $password = "******"; $database = "youbama"; $youtube_username = "******"; $youtube_password = "******"; $file_prefix = "/var/www/youbama/static/videos/"; $link = mysql_connect(localhost, $username, $password); @mysql_select_db($database, $link) or die("Unable to select database"); $phptube = new PHPTube($youtube_username, $youtube_password); $id = $argv[1]; $query = "SELECT * FROM `main_upload`, `main_video` WHERE main_upload.video_id=main_video.id AND main_video.id={$id}"; $result = mysql_query($query, $link); $numrows = mysql_num_rows($result); print "Found {$numrows} results\n"; $file = mysql_result($result, 0, "file"); $file = "/var/www/youbama/static/videos/" . $file; $title = mysql_result($result, 0, "title"); $description = mysql_result($result, 0, "description"); print "File: {$file}\nTitle: {$title}\nDesc: {$description}\n"; $youtube_id = $phptube->upload($file, $title, "www.youbama.com youbama barack obama", $description, 25, "EN"); print "Uploaded {$youtube_id}\n"; mysql_close($link);