4

YouTube 検索エンジン + ダウンロード + MP3 変換スクリプトを作成しました。このスクリプトの作成には、 Jeckman の YouTube Downloaderを使用しました。ビデオをコンピューターにダウンロードする代わりに、サーバーにダウンロードしたいことを除いて、すべて問題ありません。ダウンロードした後、FFmpegを使用してビデオをMP3に変換するため、これを行いたいと思います。

コンピューターではなくサーバーにビデオをダウンロードする方法はありますか?

download.php には次のコードが含まれています。

<?php
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext  = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url  = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext; 
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
    header('Content-Type: "' . $mime . '"');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header("Content-Transfer-Encoding: binary");
    header('Pragma: public');
}
else
{
    header('Content-Type: "' . $mime . '"');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header("Content-Transfer-Encoding: binary");
    header('Expires: 0');
    header('Pragma: no-cache');
}
readfile($url);
exit;
}

// Not found
exit('File not found 8{');
?>
4

1 に答える 1

2

YouTube ファイルをサーバーに保存する解決策を見つけました。ヘッダーのものを削除して$download_video_file = file_put_contents($file_path, fopen($url, 'r'));代わりに配置するreadfile($url);と、魔法のように機能しました! ^_^

完全なコードは次のとおりです。

<?php
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext  = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url  = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext; 
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{/*
    header('Content-Type: "' . $mime . '"');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header("Content-Transfer-Encoding: binary");
    header('Pragma: public');
*/}
else
{/*
    header('Content-Type: "' . $mime . '"');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header("Content-Transfer-Encoding: binary");
    header('Expires: 0');
    header('Pragma: no-cache');
*/}
$download_video_file = file_put_contents($file_path, fopen($url, 'r'));
exit;
}

// Not found
exit('File not found 8{');
?>
于 2013-07-24T05:41:10.407 に答える