PHPackages                             commandstring/yt-dlp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. commandstring/yt-dlp

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

commandstring/yt-dlp
====================

A PHP wrapper for yt-dlp

v3.0.0(3y ago)193MITPHPPHP ^8.1

Since Jan 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/CommandString/YtDlp-PHP)[ Packagist](https://packagist.org/packages/commandstring/yt-dlp)[ RSS](/packages/commandstring-yt-dlp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

commandstring/yt-dlp
====================

[](#commandstringyt-dlp)

A promised-based PHP wrapper for [YtDlp](https://github.com/yt-dlp/yt-dlp) built off ReactPHP

**NOTE BEFORE USING YOU WILL NEED TO START A REACT/PROMISE LOOP OR THE SCRIPT WILL DIE BEFORE THE COMMAND FINISHES EXECUTING!!!**

Creating YtDlp
==============

[](#creating-ytdlp)

```
$yt = new YtDlp();
```

You can supply a path to your Yt-Dlp as well if it's not in your path.

CommandBuilder
==============

[](#commandbuilder)

You can use the command builder to create commands programmatically, all options for YtDlp exist inside `\Yt\Dlp\Options` (if I'm missing anything please open an issue)

You can create a new CommandBuilder with your YtDlp instance

```
$command = $yt->newCommand($url)->addOption(Options::SKIP_DOWNLOAD)->addOption(Options::DUMP_JSON);
```

You can then use the execute method to execute. With the then method following that you can check the handle a success/failed command execution

```
$command->execute()->then(function (string $result) {
    echo $result;
}, function (CommandExecutionFailed $e) {
    echo (string)$e;
});
```

Already implemented commands
============================

[](#already-implemented-commands)

```
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;
```

returns the full path of where the audio/video was downloaded

```
public function getInfo(string $url): PromiseInterface
```

returns an stdClass with the video info [Available Fields](https://github.com/yt-dlp/yt-dlp#output-template)

```
public function search(string $query, int $results = 1): PromiseInterface
```

Returns an array of all the results, each item has a structure similar to the getInfo method

Basic Usage
===========

[](#basic-usage)

This code will download the first videos from the query

```
