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

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

kclauhk/youtube-downloader
==========================

PHP powered alternative for youtube-dl

v4.3.8(1mo ago)71.0k↓23.8%MITPHPPHP ^7.4|^8.0

Since Feb 20Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/kclauhk/youtube-downloader)[ Packagist](https://packagist.org/packages/kclauhk/youtube-downloader)[ RSS](/packages/kclauhk-youtube-downloader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (41)Used By (0)

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

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

[](#youtube-downloader)

[![](https://camo.githubusercontent.com/76d4abb00ee7e23c945b5968f4a040f37e81731516cc2b831c26e3b75ce1baac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b636c6175686b2f796f75747562652d646f776e6c6f616465722e737667)](https://camo.githubusercontent.com/76d4abb00ee7e23c945b5968f4a040f37e81731516cc2b831c26e3b75ce1baac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b636c6175686b2f796f75747562652d646f776e6c6f616465722e737667)[![](https://camo.githubusercontent.com/27e12fa278756667254660082def35982728449bcc11230de3ce9ddee0fd90c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b636c6175686b2f796f75747562652d646f776e6c6f616465722e737667)](https://camo.githubusercontent.com/27e12fa278756667254660082def35982728449bcc11230de3ce9ddee0fd90c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b636c6175686b2f796f75747562652d646f776e6c6f616465722e737667)[![](https://camo.githubusercontent.com/033e19aa3715dad197c023aa76c5b86462eeae9bb24743c9d0fc19275b00bf18/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6b636c6175686b2f796f75747562652d646f776e6c6f616465722e737667)](https://camo.githubusercontent.com/033e19aa3715dad197c023aa76c5b86462eeae9bb24743c9d0fc19275b00bf18/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6b636c6175686b2f796f75747562652d646f776e6c6f616465722e737667)

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.

*For [v4.1.x](https://github.com/kclauhk/youtube-downloader/tree/4.1.x),*
the 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 kclauhk/youtube-downloader
```

For pure PHP version:

```
composer require kclauhk/youtube-downloader "~4.1.2"
```

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

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

### translated video details (if available) are supported

[](#translated-video-details-if-available-are-supported)

- To specify the desired language (by YouTube language code) ```
    $downloadOptions = $youtube->getDownloadLinks($url, ['lang'=>'fr']);
    ```
- To specify the desired language and player client ```
    $downloadOptions = $youtube->getDownloadLinks($url, ['client'=>'android', 'lang'=>'fr']);
    ```

(The old way to specify the player client(s) remains valid)

### DASH/HLS manifest (available in "ios"/"web" and live streams)

[](#dashhls-manifest-available-in-iosweb-and-live-streams)

To get the URL of the DASH/HLS manifest

```
$manifestUrl = $downloadOptions->getHlsManifestUrl();

$manifestUrl = $downloadOptions->getDashManifestUrl();
```

(For private/age-restricted videos, fetching the manifest (.m3u8) and MPEG-TS segments requires the same set of cookies)

### n/sig deciphering is supported

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

[Deno](https://deno.com/) (an open-source JavaScript runtime) and the PHP **exec()** function are required. To use this project with Deno, you can either:

- put the Deno binary executable into the "vendor/kclauhk/youtube-downloader/src" directory; or
- specify the directory containing the binary executable by
    `$youtube->getJsrt()->setPath('path of the directory');`

You may use other JS runtimes. [Here](https://github.com/kclauhk/youtube-downloader/blob/main/JSRUNTIME.md#javascript-runtime) are some examples.

Hence, "TVHTML5", which requires n deciphering, is added (client ID: `tv`) and is set as default client if a JS runtime is available.

### player client can be added/modified

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

The currently available clients are `android_vr`, `ios`, `tv`, `web` (Safari user agent) and `web_embedded`. You can add additional clients/modify the built-in clients by:
`$youtube->getApiClients()->setClient($clientId, $context);`

- `$clientId` - ID of the player client
- `$context` - data in an array of key-value pairs which must contain "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 a PO token is not supported)

### Changes since [v4.1.0](https://github.com/kclauhk/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 player client ```
        $downloadOptions = $youtube->getDownloadLinks($url, $clientId);
        ```
    - `$downloadOptions = $youtube->getDownloadLinks($url);` will use the default client
- `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:

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

- Pass in your own cookies to YouTubeStreamer

Cookies are needed for accessing stream links of private/age-restricted videos obtained through the web/web\_embedded client. Set cookie file before streaming:

```
$streamer->setCookieFile('./your_cookies.txt');
```

- Pass in your own cookies/user-agent

If you try downloading private/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('Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:115.0) Gecko/20100101 Firefox/115.0');
```

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

48

—

FairBetter than 95% of packages

Maintenance88

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65% 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 ~10 days

Recently: every ~2 days

Total

39

Last Release

58d ago

### Community

Maintainers

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

---

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 (67 commits)")[![volkirik](https://avatars.githubusercontent.com/u/33526598?v=4)](https://github.com/volkirik "volkirik (3 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/kclauhk-youtube-downloader/health.svg)

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

###  Alternatives

[athlon1600/youtube-downloader

PHP powered alternative for youtube-dl

922160.2k9](/packages/athlon1600-youtube-downloader)[endroid/qr-code

Endroid QR Code

4.8k67.6M348](/packages/endroid-qr-code)[symfony/polyfill-uuid

Symfony polyfill for uuid functions

690335.4M63](/packages/symfony-polyfill-uuid)[symfony/uid

Provides an object-oriented API to generate and represent UIDs

610280.0M754](/packages/symfony-uid)[scribu/scb-framework

A set of useful classes for faster plugin development

22393.3k](/packages/scribu-scb-framework)

PHPackages © 2026

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