PHPackages                             flatgreen/ytdl - 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. flatgreen/ytdl

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

flatgreen/ytdl
==============

A PHP wrapper for youtube-dl or yt-dlp tool. Close to the command line, with a caching system.

v2.6(6mo ago)52103MITPHPPHP &gt;=7.4

Since Aug 21Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/flatgreen/ytdl)[ Packagist](https://packagist.org/packages/flatgreen/ytdl)[ RSS](/packages/flatgreen-ytdl/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (14)Used By (0)

Ytdl
====

[](#ytdl)

PHP wrapper for youtube-dl or yt-dlp.

Two goals:

- be close to the command line of youtube-dl
- minimize requests, while having the maximum amount of information

Prerequisites
-------------

[](#prerequisites)

- php &gt;= 7.4
- [youtube-dl](https://github.com/ytdl-org/youtube-dl#installation) or [yt-dlp](https://github.com/yt-dlp/yt-dlp#installation)
- Strongly recommended: ffmpeg. See [yt-dlp dependencies](https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#dependencies)

Installation
------------

[](#installation)

- Use the package manager [composer](https://getcomposer.org/) to install Ytdl.

```
composer require flatgreen/ytdl
```

- Optional: Create a 'cache' directory (with read|write permissions), by default the cache directory is inside the system temporary directory.

Usage
-----

[](#usage)

### Load the two classes:

[](#load-the-two-classes)

```
require_once 'vendor/autoload.php';
use Flatgreen\Ytdl\Options;
use Flatgreen\Ytdl\Ytdl;
```

### Define the options:

[](#define-the-options)

All in array manner. No URL here.

see : [options for youtube-dl](https://github.com/ytdl-org/youtube-dl#options) or [options for yt-dlp](https://github.com/yt-dlp/yt-dlp#usage-and-options)

```
$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');
```

### Instantiate and extract information:

[](#instantiate-and-extract-information)

Instantiate the class:

```
$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])
```

If you want to set the ytdl executable path, you need to pass the value like below. This will skip the automatic scan (in PATH) of the executable. It is your responsibility to set this path correctly.

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

Define a video url:

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

Read the video informations

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

With some format (like \['-f' =&gt; 'bv\*+ba'\]), there is no $info\_dict\['url'\], but the media can be downloaded with this $info\_dict.

At this moment, $info\_dict is in the cache.

### Download a video

[](#download-a-video)

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

Examples
--------

[](#examples)

- [example-0](/examples/0-version.php) with just '--version' option
- [example-1](/examples/1-extract.php) extract example
- [example-1-1](/examples/1-1-extract-plst.php) extract from a playlist
- [example-2](/examples/2-download.php) download a video (cache and download folders)
- [example-2-2](/examples/2-2-download.php) download with a change of options
- [example-3](/examples/3-download-plst.php) download a playlist (no cache, not optimal)
- [example-4](/examples/4-download-plst-with-cache.php) extract all informations from a playlist and download some videos with cache system.

Versions
--------

[](#versions)

See [CHANGELOG](/CHANGELOG.md)

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License
-------

[](#license)

ytdl is licensed under the MIT License (MIT). Please see the [license file](/LICENSE) for more information.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance69

Regular maintenance activity

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~132 days

Recently: every ~288 days

Total

13

Last Release

182d ago

Major Versions

v1.2.1 → v2.02022-08-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15235232?v=4)[flatgreen](/maintainers/flatgreen)[@flatgreen](https://github.com/flatgreen)

---

Top Contributors

[![flatgreen](https://avatars.githubusercontent.com/u/15235232?v=4)](https://github.com/flatgreen "flatgreen (19 commits)")[![walkero-gr](https://avatars.githubusercontent.com/u/14014909?v=4)](https://github.com/walkero-gr "walkero-gr (1 commits)")

---

Tags

phpwrapperyoutube-dlyt-dlpyoutube-dl

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/flatgreen-ytdl/health.svg)

```
[![Health](https://phpackages.com/badges/flatgreen-ytdl/health.svg)](https://phpackages.com/packages/flatgreen-ytdl)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M568](/packages/shopware-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M203](/packages/sulu-sulu)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
