1. Go to this page and download the library: Download devswebdev/devtube library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devswebdev / devtube example snippets
return [
// Path to the yt-dlp binary. Use an absolute path if it is not on the PATH.
'bin_path' => env('DEVTUBE_YT_DLP_PATH', 'yt-dlp'),
// Directory (relative to storage_path()) where downloads are saved by default.
'download_path' => env('DEVTUBE_DOWNLOAD_PATH', 'app/devtube'),
// Format key (see 'formats') used when none is supplied.
'default_format' => 'mp4',
// yt-dlp output filename template.
'output_template' => '%(title)s.%(ext)s',
// Per-format yt-dlp options.
'formats' => [
'mp4' => [
'format' => 'mp4',
],
'mp3' => [
'extract_audio' => true,
'audio_format' => 'mp3',
'audio_quality' => '0',
],
],
];
use DevsWebDev\DevTube\Facades\DevTube;
$results = DevTube::download('https://www.youtube.com/watch?v=ye5BuYf8q4o', 'mp4');
$media = $results->first();
if ($media->wasSuccessful()) {
return response()->download($media->path());
}
report($media->error);
use DevsWebDev\DevTube\Download;
$results = (new Download(
url: 'https://www.youtube.com/watch?v=ye5BuYf8q4o',
format: 'mp3',
))->download();
$media = $results->first();
return response()->download($media->path());