我是新手,我们从这开始吧。
在GitHub上有一个php项目可以从YouTube:https://github.com/Athlon1600/youtube-downloader下载视频。我想用它。
我从src
文件夹下载了所有文件和文件夹,然后通过ftp管理器在我的服务器中,在站点的根文件夹( index.php所在的位置)中创建了一个YouTube
文件夹,并将所有文件和文件夹上传到了那里。
现在,在index.php
中,我将来自GitHub页面的示例中的代码:
use YouTube\YouTubeDownloader;
use YouTube\Exception\YouTubeException;
$youtube = new YouTubeDownloader();
try {
$downloadOptions = $youtube->getDownloadLinks("https://www.youtube.com/watch?v=aqz-KE-bpKQ");
if ($downloadOptions->getAllFormats()) {
echo $downloadOptions->getFirstCombinedFormat()->url;
} else {
echo 'No links found';
}
} catch (YouTubeException $e) {
echo 'Something went wrong: ' . $e->getMessage();
}
但是得到了一个错误:
Fatal error: Uncaught Error: Class 'YouTube\YouTubeDownloader' not found
怎么了?
发布于 2021-04-10 10:05:57
这需要作曲家。
您可以从下载最新版本。
下面的指令将假设您正在使用XAMPP,并且您的项目位于C:\xampp\htdocs\MyPhpProject中。
如果您对自己正在做的事情有信心,应该将路径添加到PHP文件夹到path系统变量中,因此只需将"php“而不是EXE的路径放入,但这是可选的。
步骤1:打开命令提示符并运行以下命令,这些命令将将您的目录更改为您的项目DIR并在本地安装Composer。
cd /d C:\xampp\htdocs\MyPhpProject
C:\xampp\php\php.exe -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
C:\xampp\php\php.exe -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
C:\xampp\php\php.exe composer-setup.php
C:\xampp\php\php.exe -r "unlink('composer-setup.php');"
第二步:现在你有了作曲家,你应该初始化它。按照屏幕上的说明运行以下命令。
C:\xampp\php\php.exe composer.phar install
现在应该初始化项目,并在项目中看到一个composer.json文件。
最后,您可以安装插件。
只需从命令提示符窗口运行以下命令:
C:\xampp\php\php.exe composer.phar require athlon1600/youtube-downloader "^3.0"
我还建议使用以下方法,因为这将有助于调试PHP代码:
C:\xampp\php\php.exe composer.phar nette/nette
C:\xampp\php\php.exe composer.phar tracy/tracy
现在,将以下内容添加到文件的顶部(在开头'
if(file_exists('../vendor/autoload.php')) ? require_once('../vendor/autoload.php') : require_once('./vendor/autoload.php');
// If you also installed Tracy add this:
use Tracy\Debugger;
这需要位于每个php文件的顶部,所以我建议创建一个“头”文件,并使用require_once()
调用它来预加载所有依赖项,例如:
require_once('./inc/header.inc.php');
https://stackoverflow.com/questions/67032612
复制相似问题