npm package: @oreohq/ytdl-core
Description: Oreo fork of ytdl-core. YouTube video downloader in pure javascript.
Author: Aniket
Latest version: 4.16.5

# @oreohq/ytdl-core
Oreo fork of `ytdl-core`. This fork is dedicated to fixing bugs and adding features that are not merged into the original repo as soon as possible.

![Builders](https://i.imgur.com/a9owl5Q.png)

<p align="center">
  <img src="https://i.imgur.com/cBiIazb.png" alt="badge" />
  <img src="https://i.imgur.com/1EIFuXp.png" alt="badge" />
</p>


## 📦 Installation
```bash
npm install @oreohq/ytdl-core@latest
```


## 🪴 Usage
```js
const ytdl = require('@oreohq/ytdl-core');

const videoInfo = await ytdl.getBasicInfo('https://www.youtube.com/watch?v=2QjJMT554Bc');
console.log(videoInfo);

// Download a video
ytdl('https://www.youtube.com/watch?v=2QjJMT554Bc').pipe(require('fs').createWriteStream('video.mp4'));
```


### 🍪 Cookies Support
```js
const ytdl = require('@oreohq/ytdl-core');

const cookies = [
  { name: "cookie1", value: "COOKIE1_HERE" },
  { name: "cookie2", value: "COOKIE2_HERE" },
];

// http-cookie-agent / undici agent options
const agentOptions = {
  pipelining: 5,
  maxRedirections: 0,
  localAddress: "127.0.0.1",
};

// agent should be created once if you don't want to change your cookie
const agent = ytdl.createAgent(cookies, agentOptions);
ytdl.getBasicInfo('https://www.youtube.com/watch?v=2QjJMT554Bc' { agent });
```


#### How to get cookies
- Install [EditThisCookie](http://www.editthiscookie.com/) extension for your browser.
- Go to [YouTube](https://www.youtube.com/).
- Log in to your account. (You should use a new account for this purpose)
- Click on the extension icon and click "Export" icon.
- Your cookies will be added to your clipboard and paste it into your code.

> [!WARNING]
> Don't logout it by clicking logout button on youtube/google account manager, it will expire your cookies.
> You can delete your browser's cookies to log it out on your browser.
> Or use incognito mode to get your cookies then close it.


### Proxy Support
```js
const ytdl = require('@oreohq/ytdl-core');

const agent = ytdl.createProxyAgent({ uri: 'my.proxy.server' });
const agentWithCookies = ytdl.createProxyAgent({ uri: 'my.proxy.server' }, [{ name: 'cookie', value: 'COOKIE_HERE' }]);

ytdl.getBasicInfo('https://www.youtube.com/watch?v=2QjJMT554Bc' { agent });
ytdl.getBasicInfo('https://www.youtube.com/watch?v=2QjJMT554Bc' { agentWithCookies });
```


### IP Rotation
To implement IP rotation, you need to assign the desired IP address to the `localAddress` property within `undici.Agent.Options`.
Therefore, you'll need to use a different `ytdl.Agent` for each IP address you want to use.
```js
const { getRandomIPv6 } = require('@oreohq/ytdl-core/lib/utils');
const ytdl = require('@oreohq/ytdl-core');

const proxyAgent1 = ytdl.createAgent(undefined, { localAddress: getRandomIPv6('2001:2::/48') });
ytdl.getBasicInfo('https://www.youtube.com/watch?v=2QjJMT554Bc', { agent: proxyAgent1 });

const proxyAgent2 = ytdl.createAgent(undefined, { localAddress: getRandomIPv6('2001:2::/48') });
ytdl.getBasicInfo('https://www.youtube.com/watch?v=2QjJMT554Bc', { agent: proxyAgent2 });
```


## 👻 Rate Limiting
When doing too many requests YouTube might block. This will result in your requests getting denied with HTTP-StatusCode 429. The following steps might help you:

- Update `@oreohq/ytdl-core` to the latest version
- Use proxies (you can find an example [here](#proxy-support))
- Extend the Proxy Idea by rotating (IPv6-)Addresses
- Use cookies (you can find an example [here](#cookies-support)) (wait for current ratelimits to expire first)
- Wait it out (it usually goes away within a few days)


# 🚛 Update Checks
The issue of using an outdated version of ytdl-core became so prevalent, that ytdl-core now checks for updates at run time, and every 12 hours.
Due to the nature of this library, it is important to always use the latest version as YouTube continues to update.
If you'd like to disable this update check, you can do so by providing the `YTDL_NO_UPDATE` env variable.
```
env YTDL_NO_UPDATE=1 
```

If you'd like to have it send a webhook message on discord, you can do so by providing the following env variables.
```
YTDL_WEBHOOK_URL="Your Webhook Url"
YTDL_WEBHOOK_MENTIONS="String with mentions"
```


## **❔ Support**
<a href="https://discord.gg/invite/GaczkwfgV9"><img src="https://invidget.switchblade.xyz/GaczkwfgV9" alt="Discord"></a>