PHP code example of devswebdev / devtube

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());

DevTube::download($url, 'mp4', '/var/www/storage/app/my-downloads');

// 2.x
$media_info = $dl->download()->first();
return response()->download($media_info['file']->getPathname());

// 3.0
$media = $dl->download()->first();
return response()->download($media->path());
bash
which yt-dlp
bash
php artisan vendor:publish --provider="DevsWebDev\DevTube\DevTubeServiceProvider" --tag=config
bash
php artisan devtube:download "https://www.youtube.com/watch?v=ye5BuYf8q4o" --format=mp3
php artisan devtube:download "https://www.youtube.com/watch?v=ye5BuYf8q4o" --format=mp4 --path=/absolute/download/dir
bash
php artisan vendor:publish --provider="DevsWebDev\DevTube\DevTubeServiceProvider" --tag=config --force