youtube-dl through a proxy


If you have access to an SSH box in a different region, you can use it as a SOCKS proxy to download YouTube videos with youtube-dl you can’t view in your own country.

NOTE: This post does not condone the use of these tools in this way. You perform such actions at your own risk. You're smart enough to know this, but it needs saying anyway.

The situation

You realised with glee that some classic true crime shows are available on YouTube, but when you go to view them, you get:

This video is not available. Sorry about that.

Being sneaky, you try downloading with youtube-dl. Unfortunately, your hopes are dashed when you realise the reason for not being able to view is your region, not a plugin:

$ youtube-dl
==> [youtube] w3FZ7t2zUHI: Downloading webpage
==> [youtube] w3FZ7t2zUHI: Downloading video info webpage
==> ERROR: w3FZ7t2zUHI: YouTube said: This video is not available.

This cannot stand.

Opening the tunnel

Open a socks proxy to your target box. I like defining these in my ~/.ssh/config file to make things neater:

host us-tunnel
    # = SOCKS Proxies/🇺🇸
    HostName       <IP ADDRESS>
    User           <USERNAME>
    DynamicForward 23232

Then I can open the proxy as such:

$ ssh us-tunnel

Running youtube-dl

There are couple of different ways to do this. One is using the venerable tsocks tool which intercepts and forwards TCP connections through a SOCKS proxy. You can use openroc’s patches to run it on macOS, then define a tunnel and run youtube-dl through it.

I was about to launch into a discussion of this, but turns out youtube-dl now has proxy support! So you can just do this with the above port:

$ youtube-dl --proxy socks5://localhost:23232/ <YOUTUBE URL>

This post could probably have been condensed into two lines.

Author bio and support


Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!