burakerenel/devtube

一个Laravel包,通过传递URL简单地下载网络视频


README

alt text

如果您想将视频转换为mp3等格式,请仅安装FFMPEG

Ubuntu

sudo apt install ffmpeg

安装 youtube-dl

sudo apt install youtube-dl

通过composer安装

composer require devswebdev/devtube

发布供应商资产

php artisan vendor:publish --provider="DevsWebDev\DevTube\DevTubeServiceProvider"

这将在您的 config/ 目录中发布一个 devtube.php 文件。请在此处设置默认选项。

确保您的 youtube-dl 路径正确,通过将 which youtube-dl 的输出与 devtube.php 中的 bin_path 进行比较

"bin_path" => "/usr/bin/youtube-dl",

示例

namespace App\Http\Controllers;
use DevsWebDev\DevTube\Download;

class YoutubeDownloadController extends Controller
{
    public function download()
    {
    $dl = new Download($url = "https://www.youtube.com/watch?v=ye5BuYf8q4o", $format = "mp4", $download_path = "music" );

    //Saves the file to specified directory
    $media_info = $dl->download();
    $media_info = $media_info->first();

    // Return as a download
    return response()->download($media_info['file']->getPathname());

    }
}

或者在您的web.php路由文件中

use DevsWebDev\DevTube\Download;

Route::get('/', function () {
    $dl = new Download($url = "https://www.youtube.com/watch?v=ye5BuYf8q4o", $format = "mp3", $download_path = "music" );

    //Saves the file to specified directory
    $media_info = $dl->download();
    $media_info = $media_info->first();

    // Return as a download
    return response()->download($media_info['file']->getPathname());

});