How to Watch YT Videos Over TOR Hidden Service Using mpv
I was running my
i2p-browser-bundle and had IncogTube (
tube.i2p) opened to test I2P connectivity. I usually don't go to YT anymore and I stopped even going to Invidious for about a year now (except for testing) and like to watch everything from LBRY/FastLBRY/Odysee.com or Peertube (TILVids.com etc.) now. It has been great so far. I found channels for almost every genre I like watching, which keep me entertained to the extent I don't miss YT/Invidious anymore.
The problemSince
IncogTube totally proxies everything, including videos and thumbnails, I don't have to talk to G00gle servers directly. Which is kind of like using Searx for G00gle search. Since I had it opened, so thought I'd watch some videos through it to catch up with some channels. It loaded videos fine, but Firefox is very slow and unresponsive in my hardware. Videos don't play very well. This is only the case for OpenBSD. It's fine on GNU/Linux. But thankfully mpv can play videos without issues. I don't know why mpv can play the videos, but Firefox can't. So I thought of trying to play it on mpv through IncogTube.
I was careful to use
IncogTube's .onion address in the commands so that the connection stays as secure and end to end encrypted as possible. I was on my OpenBSD install and ran:
export http_proxy=socks5://127.0.0.1:9450 && mpv http://tuberyps2pn6dor6h47brof3w2asmauahhk4ei42krugybzzzo55klad.onion/watch?v=aqz-KE-bpKQ
Frustratingly it returned:
[ffmpeg] tcp: Failed to resolve hostname tuberyps2pn6dor6h47brof3w2asmauahhk4ei42krugybzzzo55klad.onion: no address associated with name
Failed to open [url=http://tuberyps2pn6dor6h47brof3w2asmauahhk4ei42krugybzzzo55klad.onion/watch?v=aqz-KE-bpKQ.]http://tuberyps2pn6dor6h47brof3w2asmauahhk4ei42krugybzzzo55klad.onion/watch?v=aqz-KE-bpKQ.[/url]
[ytdl_hook] ERROR: Unable to download webpage: (caused by URLError(ConnectionRefusedError(61, 'Connection refused')))
[ytdl_hook] youtube-dl failed: unexpected error occurred
Exiting... (Errors when loading file)
Thinking that youtube-dl is not getting the proxy params, I tried more drastic things adding the proxy more explicitly as much as I can:
export http_proxy=socks5://127.0.0.1:9450 && mpv --http-proxy=http://127.0.0.1:9450 --ytdl-raw-options=proxy=http://127.0.0.1:9450 http://tuberyps2pn6dor6h47brof3w2asmauahhk4ei42krugybzzzo55klad.onion/watch?v=aqz-KE-bpKQ
Result is the same. :(
This is obviously wrong. TOR is not meant for HTTP proxies, rather meant for SOCKS proxies. But I was desperate. At the end it got me nowhere.
The SolutionWARNING: Before going into the solutions described, I haven't looked deeply into the security implications of this setup. So do not use this for anything serious. The content you watch is also up to you and I can't be responsible.
I think the problem was that I was focusing on applying the http proxy to things, while TOR is a socks5 proxy. So I needed a way to use http proxy with TOR. With a bit of searching I found Privoxy to a be a solution for this.
So I installed privoxy. Since I was in OpenBSD:
doas pkg_add privoxy
Edited it's config:
doas nano /etc/privoxy/config
, then add below to the file:
...
#for TOR
forward-socks5t / 127.0.0.1:9450 .
#these are "unsecure as the local network is"
#uncomment only if absolutely needed and don't care about security issues
#forward 192.168.[i].[/i]/ .
#forward 10.[i].[/i].[i]/ .
#forward 127.[/i].[i].[/i]/ .
#forward localhost/ .
* My TOR instance was on port 9450. Replace "9450" above with your TOR instance port. If you are running TOR Browser you can use "9150" to use the already running TOR instance. For system installations, it's usually 9050, but still recommend checking for the line containing "SOCKSPort" in /etc/torrc or /etc/tor/torrc.
* Optionally comment
logfile logfile
line to not save details about connections.
(Re)start the "privoxy" service. Since I was in OpenBSD it was
/etc/rc.d/privoxy restart
for me. On other systems it might be
/etc/init.d/privoxy restart
or
sudo systemctl restart privoxy
or anything else described in the init system documentation. We'll have to restart this service every time we change Privoxy config.
You might also want to start the privoxy service on startup. Instructions for this would vary depending on your (init) system.
Solution in actionNow we are ready to run mpv through Privoxy. Privoxy's default port is 8118. So we can run:
export http_proxy=http://127.0.0.1:8118 && mpv http://tuberyps2pn6dor6h47brof3w2asmauahhk4ei42krugybzzzo55klad.onion/watch?v=aqz-KE-bpKQ
So basically Privoxy is letting us use an HTTP proxy to indirectly use TOR's SOCKS5 proxy.
This time it should play. Change the id ("aqz-KE-bpKQ") in the above command to the video you want to watch and it should play right away! Securely and without G00gle!
But what if you want to binge watch videos like this? Changing the URL again and again is annoying, right? That's why the next solution is going to be useful.
Solution for binge watchingHere is a script I wrote that lets you watch videos through IncogTube's TOR onion service one after another. The script keeps asking for new YT/Invidious URLs indefinitely. You can just paste an URL and watch it. When you're done, you can paste another to watch another video. Just a little helper script to automate what I would've had done myself.
Full script is here but the gist is:
#!/usr/bin/env bash
#Privoxy HTTP proxy port.
#Change this only if you've set a different port than the default 8118 on
#Privoxy's config file.
HTTP_PROXY_PORT='8118'
export http_proxy=http://127.0.0.1:${HTTP_PROXY_PORT}
INPUT='--' #Free pass for the first loop
until [ -z "$INPUT" ]; do
echo '== Enter YT/Invidious URL to play or Ctrl+C to quit:'
read INPUT
if [ -n "$INPUT" ]; then
YT_VIDEO_ID=$( echo "$INPUT" | sed -nr 's|.[i]v=(.[/i])|\1|p' )
echo "-- Video id parsed as: ${YT_VIDEO_ID}"
echo "-- Launching mpv through IncogTube's .onion instance..."
mpv http://tuberyps2pn6dor6h47brof3w2asmauahhk4ei42krugybzzzo55klad.onion/watch?v=${YT_VIDEO_ID}
else
echo '== Empty Input. Exiting...'
fi
done
Enjoy!
Ref:-
https://www.privoxy.org/faq/misc.html#TOR-
https://scribe.rip/andregodinho1/navigating-anonimized-on-the-web-with-tor-and-privoxy-on-a-kali-linux-20-55b6f7a57269