PHP code example of commandstring / yt-dlp
1. Go to this page and download the library: Download commandstring/yt-dlp 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/ */
commandstring / yt-dlp example snippets
$yt = new YtDlp();
$command = $yt->newCommand($url)->addOption(Options::SKIP_DOWNLOAD)->addOption(Options::DUMP_JSON);
$command->execute()->then(function (string $result) {
echo $result;
}, function (CommandExecutionFailed $e) {
echo (string)$e;
});
public function downloadVideo(string $url, string $outputPath, string $customName, string $format = "mp4"): PromiseInterface;
public function downloadAudio(string $url, string $outputPath, string $customName, string $format = "mp3"): PromiseInterface;
public function getInfo(string $url): PromiseInterface
public function search(string $query, int $results = 1): PromiseInterface
use React\EventLoop\Loop;
use Yt\Dlp\Exceptions\CommandExecutionFailed;
use Yt\Dlp\YtDlp;
$query = "amalee the worlds continuation";
$yt->search($query, 5)->then(function ($results) use ($yt, $errHandler) {
foreach ($results as $video) {
$id = $video->id;
$yt->downloadVideo($id, __DIR__, $id)->then(null, $errHandler);
}
});
Loop::get()->run();