Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于youtube dl norkunas/youtube dl php的Laravel和php包装器_Laravel_Youtube Dl - Fatal编程技术网

用于youtube dl norkunas/youtube dl php的Laravel和php包装器

用于youtube dl norkunas/youtube dl php的Laravel和php包装器,laravel,youtube-dl,Laravel,Youtube Dl,我使用的是Laravel版本6.14.0,我想在Laravel中使用以下Youtube dl包装器 我使用命令composer require norkunas/youtube-dl-php来安装它,得到了以下输出: Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 2 installs, 0 update

我使用的是Laravel版本6.14.0,我想在Laravel中使用以下Youtube dl包装器

我使用命令
composer require norkunas/youtube-dl-php
来安装它,得到了以下输出:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing symfony/options-resolver (v4.4.4): Downloading (100%)         
  - Installing norkunas/youtube-dl-php (v1.4.0): Downloading (100%)         
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
这就是我的控制器的样子

<?php

namespace App\Http\Controllers;

use App\YtScreen;
use Illuminate\Http\Request;
use YoutubeDl\YoutubeDl;
use YoutubeDl\Exception\CopyrightException;
use YoutubeDl\Exception\NotFoundException;
use YoutubeDl\Exception\PrivateVideoException;


class YtScreenController extends Controller
{


    public function frontpage()
    {

        $dl = new YoutubeDl([
        'continue' => true, // force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.
        'format' => 'bestvideo',
    ]);
    // For more options go to https://github.com/rg3/youtube-dl#user-content-options

    $dl->setDownloadPath('/home/user/downloads');
    // Enable debugging
    $dl->debug(function ($type, $buffer) {
        if (\Symfony\Component\Process\Process::ERR === $type) {
            echo 'ERR > ' . $buffer;
        } else {
            echo 'OUT > ' . $buffer;
        }
    });
    try {
        $video = $dl->download('https://www.youtube.com/watch?v=oDAw7vW7H0c');
        echo $video->getTitle(); // Will return Phonebloks
        // $video->getFile(); // \SplFileInfo instance of downloaded file
    } catch (NotFoundException $e) {
        // Video not found
    } catch (PrivateVideoException $e) {
        // Video is private
    } catch (CopyrightException $e) {
        // The YouTube account associated with this video has been terminated due to multiple third-party notifications of copyright infringement
    } catch (\Exception $e) {
        // Failed to download
    }


        return view("frontpage");

    }

}

你能
dd($e)
从每一个
catch
?谢谢!这实际上给了我一条错误信息。包装器无法找到并启动youtube dl。必须设置路径$dl->setBinPath('/snap/bin/youtube-dl'),它就成功了