PHP code example of flatgreen / ytdl

1. Go to this page and download the library: Download flatgreen/ytdl 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/ */

    

flatgreen / ytdl example snippets



use Flatgreen\Ytdl\Options;
use Flatgreen\Ytdl\Ytdl;

$ytdl_options = new Options();
// merge with default options
$ytdl_options->addOptions(['-f' => '18/worst']);

// with a direct string commnd line
$ytdl_options->addRawOptions('--one_alone --with_value value --second_alone -t');

$ytdl = new Ytdl($ytdl_options);
// optional, change cache options
// default temporary cache directory and duration 3600 sec.
// no cache with ['duration' => 0]
$ytdl->setCache(['directory' => 'cache', 'duration' => 7200])

$ytdl = new Ytdl($ytdl_options, null, 'usr/share/local/yt-dlp');

$webpage_url = 'https://www.youtube.com/watch?v=DTi8wZ1a1TA';

$info_dict = $ytdl->extractInfos($webpage_url);
$errors = $ytdl->getErrors();

$info_dict = $ytdl->download($webpage_url);
// with a download directory
// $info_dict = $ytdl->download($webpage_url, $directory_to_download);
// with an explicit $info_dict
// $new_info_dict = $ytdl->download($webpage_url, $directory_to_download, $info_dict);
$errors = $ytdl->getErrors();