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";
     }
 }
Beispiel #2
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
$url = "http://www.youtube.com/watch?v=FJRMwdmFYWg&feature=popular";
$pattern = getPatternFromUrl($url);
echo "new_flv_path: " . ($flvFile = GrabFlvFromYoutube($pattern));
echo "<br>";
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 getPatternFromUrl($url)
{
    $url = $url . '&';
    $pattern = '/v=(.+?)&+/';
    preg_match($pattern, $url, $matches);
    return $matches[1];