# YouTube Downloader (yt\_dlp) integration

## Example Integration: YouTube Downloader

Here's an example using `yt-dlp` with our High Bandwidth Proxies for video or audio data scraping:

### Basic Usage

Adding a `-test` parameter to the username allows users to test the connection setting.

{% tabs %}
{% tab title="Command Line" %}

```bash
yt-dlp --proxy username-test:password@endpoint:60000 \
"https://www.youtube.com/watch?v=WNCl-69POro"
```

{% endtab %}

{% tab title="Python" %}

```python
import yt_dlp

username = 'YOUR_USERNAME'
password = 'YOUR_PASSWORD'

if not username.endswith("-test"):
    username += "-test"
    
proxy = f'http://{username}:{password}@your-endpoint:60000'

ydl_opts = {
    'proxy': proxy,
}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=WNCl-69POro'])
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
For optimal performance, make sure each video is downloaded using a separate IP address. Refer to the section below for guidance.
{% endhint %}

### Multiple URLs with Different IPs

While using High Bandwidth Proxies, every video is downloaded with a separate IP address to ensure the optimal performance. This is achieved by generating a unique session ID for each request, which effectively assigns a new IP address for each download.

{% tabs %}
{% tab title="Command line" %}

```bash
# First video with one IP
yt-dlp --proxy username-$((1 + RANDOM % 100000)):password@endpoint:60000 \
"https://www.youtube.com/watch?v=6stlCkUDG_s"

# Second video with different IP
yt-dlp --proxy username-$((1 + RANDOM % 100000)):password@endpoint:60000 \
"https://www.youtube.com/watch?v=gsnqXt7d1mU"
```

{% endtab %}

{% tab title="Python" %}

```python
import random
import yt_dlp

def download_with_new_ip(url, username, password):
    session_id = random.randint(1, 100000)
    proxy = f'http://{username}-{session_id}:{password}@your-endpoint:60000'

    ydl_opts = {
        'proxy': proxy
    }
    
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        try:
            print(f"Downloading {url} with new IP ({username}-{session_id})...")
            ydl.download([url])
            print(f"Successfully downloaded {url}")
        except Exception as e:
            print(f"Error downloading {url}: {str(e)}")

def main():
    username = 'YOUR_USERNAME'
    password = 'YOUR_PASSWORD'
    
    videos = [
        'https://www.youtube.com/watch?v=6stlCkUDG_s',
        'https://www.youtube.com/watch?v=gsnqXt7d1mU'
    ]
    
    for video in videos:
        download_with_new_ip(video, username, password)

if __name__ == "__main__":
    main()

```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The function includes basic error handling to ensure the process continues even if one download fails.
{% endhint %}
