PHPackages                             nambz/youtube-downloader - 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. nambz/youtube-downloader

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

nambz/youtube-downloader
========================

PHP powered alternative for youtube-dl

4.1.0(1y ago)03MITPHPPHP ^7.4|^8.0

Since Jun 1Pushed 1y agoCompare

[ Source](https://github.com/NamBZ/youtube-downloader)[ Packagist](https://packagist.org/packages/nambz/youtube-downloader)[ RSS](/packages/nambz-youtube-downloader/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

This is forked from [Athlon1600/youtube-downloader](https://github.com/Athlon1600/youtube-downloader)

YouTube Downloader
==================

[](#youtube-downloader)

[![Build Status](https://github.com/ytdl-org/youtube-dl/workflows/CI/badge.svg)](https://github.com/ytdl-org/youtube-dl/actions?query=workflow%3ACI)[![](https://camo.githubusercontent.com/e3039c323381d317924e28c419a9b34a0daa55928c82a0cbf2c326472941d5c3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4174686c6f6e313630302f796f75747562652d646f776e6c6f616465722e737667)](https://camo.githubusercontent.com/e3039c323381d317924e28c419a9b34a0daa55928c82a0cbf2c326472941d5c3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4174686c6f6e313630302f796f75747562652d646f776e6c6f616465722e737667)[![](https://camo.githubusercontent.com/21265cb3d9ccad1e59a6c13127e09d2f026d385633be796f58c9d69c1abb21fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4174686c6f6e313630302f796f75747562652d646f776e6c6f616465722e737667)](https://camo.githubusercontent.com/21265cb3d9ccad1e59a6c13127e09d2f026d385633be796f58c9d69c1abb21fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4174686c6f6e313630302f796f75747562652d646f776e6c6f616465722e737667)[![GitHub commit activity (branch)](https://camo.githubusercontent.com/727d501682639118c56a3f08bde71150eb2cb729c672a10c6e6cb8b958c070e1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d69742d61637469766974792f792f6174686c6f6e313630302f796f75747562652d646f776e6c6f61646572)](https://camo.githubusercontent.com/727d501682639118c56a3f08bde71150eb2cb729c672a10c6e6cb8b958c070e1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d69742d61637469766974792f792f6174686c6f6e313630302f796f75747562652d646f776e6c6f61646572)[![](https://camo.githubusercontent.com/2b5717d3d02c9f731abcd813f725ce61fc82b93417b3b2d50fa750fa7c3482e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f4174686c6f6e313630302f796f75747562652d646f776e6c6f616465722e737667)](https://camo.githubusercontent.com/2b5717d3d02c9f731abcd813f725ce61fc82b93417b3b2d50fa750fa7c3482e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f4174686c6f6e313630302f796f75747562652d646f776e6c6f616465722e737667)

This project was inspired by a very popular youtube-dl python package:

Yes, there are multiple other PHP-based youtube downloaders on the Internet, but most of them haven't been updated in years, or they depend on youtube-dl itself.

Pure PHP-based youtube downloaders that work, and are **kept-up-to date** just do not exist.

*Up to v4.1.0,*
this script uses no Javascript interpreters, no calls to shell... nothing but pure PHP with no heavy dependencies either.

[![](https://camo.githubusercontent.com/79a96c9e43158f6d966c876c2c07cc72ac4dc7c123351c2ce48ae1b7c4399632/68747470733a2f2f692e696d6775722e636f6d2f595433394b5a352e706e67)](https://camo.githubusercontent.com/79a96c9e43158f6d966c876c2c07cc72ac4dc7c123351c2ce48ae1b7c4399632/68747470733a2f2f692e696d6775722e636f6d2f595433394b5a352e706e67)

That's all there is to it!

⚠️ Legal Disclaimer
-------------------

[](#warning-legal-disclaimer)

This program is for personal use only. Downloading copyrighted material without permission is against [YouTube's terms of services](https://www.youtube.com/static?template=terms). By using this program, you are solely responsible for any copyright violations. We are not responsible for people who attempt to use this program in any way that breaks YouTube's terms of services.

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

[](#installation)

Recommended way of installing this is via [Composer](http://getcomposer.org):

```
composer require NamBZ/youtube-downloader
```

For pure PHP version:

```
composer require NamBZ/youtube-downloader "4.1.0"
```

Changes in this fork
--------------------

[](#changes-in-this-fork)

### nsig decoding is supported

[](#nsig-decoding-is-supported)

[Deno](https://deno.com/) (an open-source JavaScript runtime) is required for nsig decoding.
To use this project with Deno, you can either

- place the Deno executable into the folder "youtube-downloader/src"; or
- specify the path of the folder containing Deno executable by
    `$youtube->getJsrt()->setPath('path of the folder');`

Hence, "TVHTML5" client, which require nsig, is added. (client ID: "tv")

### player client can be added/modified

[](#player-client-can-be-addedmodified)

You can add additional clients/modify the built-in clients by:
`$youtube->getApiClients()->setClient($client_id, $client_data);`

- `$client_id` - ID of the client
- `$client_data` - client data in array of key-value pairs which must contains "clientName" and "clientVersion",
    for example, adding "WEB\_EMBEDDED\_PLAYER": ```
    $client = array(
        'clientName' => 'WEB_EMBEDDED_PLAYER',
        'clientVersion' => '1.20241201.00.00',
    );
    $youtube->getApiClients()->setClient('web_embedded', $client);
    $downloadOptions = $youtube->getDownloadLinks($url, 'web_embedded');    // use 'web_embedded'

    ```

    (client which requires PO token is not supported)

### Changes since [v4.1.0](https://github.com/NamBZ/youtube-downloader/releases/tag/v4.1.0)

[](#changes-since-v410)

- Two YouTube clients (client ID: "android\_vr" and "ios") are built into YouTubeDownloader
    - To specify a client ```
        $downloadOptions = $youtube->getDownloadLinks($url, $client_id);

        ```
    - `$downloadOptions = $youtube->getDownloadLinks($url);` will use the default client "ios"
- `StreamFormat` object now contains `audioTrack`, `indexRange` and `isDrc` properties
- YouTubeStreamer accepts custom request headers (this can be used for streaming media from sources that require specific headers) ```
    $headers = array("origin: $origin", "referer: $referer");
    $youtube->stream($url, $headers);

    ```

Example usage
-------------

[](#example-usage)

```
use YouTube\YouTubeDownloader;
use YouTube\Exception\YouTubeException;

$youtube = new YouTubeDownloader();

try {
    $downloadOptions = $youtube->getDownloadLinks("https://www.youtube.com/watch?v=aqz-KE-bpKQ");

    if ($downloadOptions->getAllFormats()) {
        echo $downloadOptions->getFirstCombinedFormat()->url;
    } else {
        echo 'No links found';
    }

} catch (YouTubeException $e) {
    echo 'Something went wrong: ' . $e->getMessage();
}
```

`getDownloadLinks` method returns a `DownloadOptions` type object, which holds an array of stream links - some that are audio-only, and some that are both audio and video combined into one.

For typical usage, you are probably interested in dealing with combined streams, for that case, there is the `getCombinedFormats` method.

Other Features
--------------

[](#other-features)

- Stream YouTube videos directly from your server:

```
$youtube = new \YouTube\YouTubeStreamer();
$youtube->stream('https://r4---sn-n4v7knll.googlevideo.com/videoplayback?...');
```

- Pass in your own cookies/user-agent

If you try downloading age-restricted videos, YouTube will ask you to login. The only way to make this work, is to login to your YouTube account in your own web-browser, export those newly set cookies from your browser into a file, and then pass it all to youtube-downloader for use.

```
$youtube = new YouTubeDownloader();
$youtube->getBrowser()->setCookieFile('./your_cookies.txt');
$youtube->getBrowser()->setUserAgent('Opera 7.6');
```

See also:

- Before you continue to YouTube...

Depending on your region, you might be force redirected to a [page](https://unblockvideos.com/images/before-you-continue-cookies.jpg) that asks you to agree to Google's cookie policy. You can programmatically agree to those terms, and bypass that warning permanently via `consentCookies` method on your Browser instance. Example:

```
$youtube = new YouTubeDownloader();
$youtube->getBrowser()->consentCookies();
```

How does it work
----------------

[](#how-does-it-work)

A more detailed explanation on how to download videos from YouTube will be written soon. For now, there is this:

[Athlon1600#25 (comment)](https://github.com/Athlon1600/youtube-downloader/pull/25#issuecomment-439373506)

Miscellaneous Links
-------------------

[](#miscellaneous-links)

-
-
-
- [https://github.com/ytdl-org/youtube-dl/blob/master/youtube\_dl/extractor/youtube.py](https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/extractor/youtube.py)
-

To-do list
----------

[](#to-do-list)

-

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance47

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.8% 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

Unknown

Total

1

Last Release

398d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0134cdb93426e71ca3c373b9d9b058c06834c143a611b11029ea11c64567ee66?d=identicon)[NamBZ](/maintainers/NamBZ)

---

Top Contributors

[![Athlon1600](https://avatars.githubusercontent.com/u/1063088?v=4)](https://github.com/Athlon1600 "Athlon1600 (139 commits)")[![kclauhk](https://avatars.githubusercontent.com/u/78251477?v=4)](https://github.com/kclauhk "kclauhk (32 commits)")[![volkirik](https://avatars.githubusercontent.com/u/33526598?v=4)](https://github.com/volkirik "volkirik (3 commits)")[![NamBZ](https://avatars.githubusercontent.com/u/92571253?v=4)](https://github.com/NamBZ "NamBZ (2 commits)")[![Ibrram](https://avatars.githubusercontent.com/u/29353848?v=4)](https://github.com/Ibrram "Ibrram (1 commits)")[![shivampaw](https://avatars.githubusercontent.com/u/11842979?v=4)](https://github.com/shivampaw "shivampaw (1 commits)")[![Thorsten7701](https://avatars.githubusercontent.com/u/21060848?v=4)](https://github.com/Thorsten7701 "Thorsten7701 (1 commits)")[![unikapps](https://avatars.githubusercontent.com/u/1418027?v=4)](https://github.com/unikapps "unikapps (1 commits)")[![codezi](https://avatars.githubusercontent.com/u/19167750?v=4)](https://github.com/codezi "codezi (1 commits)")

---

Tags

youtube downloaderdownload youtubedownload youtube videos

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nambz-youtube-downloader/health.svg)

```
[![Health](https://phpackages.com/badges/nambz-youtube-downloader/health.svg)](https://phpackages.com/packages/nambz-youtube-downloader)
```

###  Alternatives

[athlon1600/youtube-downloader

PHP powered alternative for youtube-dl

926163.7k13](/packages/athlon1600-youtube-downloader)[dmishh/settings-bundle

Database centric Symfony configuration management. Global and per-user settings supported.

115257.8k1](/packages/dmishh-settings-bundle)

PHPackages © 2026

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