mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Support SOCKS5 proxies

Open adamhotep opened this issue 9 years ago • 27 comments

It would be nice to have a config item like socks_proxy or socks5_proxy to support SOCKS proxies.

At the moment, even commands like tsocks mpv http://server/test.webm fail to work, and though curl --socks5 localhost:1080 http://server/test.webm |mpv --cache=512 works, you can't seek since mpv isn't controlling the network stream.

This SO question explains the issue farther.

adamhotep avatar Jul 28 '16 01:07 adamhotep

If you can use a regular HTTP proxy instead of a SOCKS proxy, you can set the environment variable HTTP_PROXY="url" to make FFmpeg and youtube-dl pick up on it.

Judging by a quick glance at FFmpeg code, it doesn't seem to support socks proxies at all, so any support for them in mpv would be blocked by this. (Also keep in mind that youtube-dl would also need support for them if you plan on using it)

haasn avatar Jul 28 '16 07:07 haasn

The combination of privoxy, HTTP_PROXY/HTTPS_PROXY as envvar and youtube-dl works well enough. I would argue that additional code for this in mpv would be an unnecessary burden to maintain.

lamarpavel avatar Jul 28 '16 11:07 lamarpavel

Why do you need socks5?

There is no a good open source SOCKS 5 server available.

nxtreaming avatar Jul 28 '16 11:07 nxtreaming

OpenSSH is an open source SOCKS 5 server. It's even the one I use (ssh -D1080 myserver). I do not use an HTTP proxy and am not interested in setting one up on my remote server. If the right move is to escalate to FFMPEG (and youtube-dl), then so be it. I was just hoping it would be attractive enough to implement here.

adamhotep avatar Jul 28 '16 23:07 adamhotep

I just found this after looking at the man page and not seeing anything socks related. At least for the youtube-dl integration it works for me, like this:

http_proxy=socks5://127.0.0.1:9050 mpv [...]

mpv 0.18.0 youtube-dl 2016.07.09.2

v2px avatar Sep 20 '16 06:09 v2px

@v2px I tried

http_proxy=socks5://127.0.0.1:9050 mpv [...]

But it no longer works. Found polipo to the rescue.

liaowang11 avatar Dec 30 '16 17:12 liaowang11

Btw, I forgot to mention this, but proxychains mpv works fine. I use it for watching youtube videos over tor (which also exposes a SOCKS proxy).

haasn avatar Dec 30 '16 18:12 haasn

Hope mpv could provide proxy support, might you not know, the VPNs are slaughtered in some countries, like China, Iran, North Korea, and people of those nations have to set up socks and http proxy to get the Youtube, Google and so on. So nicely handy thing if MPV could have a proxy support.

Justsoos avatar Jan 29 '17 17:01 Justsoos

@haasn yeap, proxychains is good at linux and unices, but in windows, it is hard to find a handy way except a proxy included in mpv.

Justsoos avatar Jan 29 '17 17:01 Justsoos

I would also love SOCKS proxy support. It's the proxy of choice for Tor.

ilf avatar Aug 18 '17 18:08 ilf

resolved. first, set your environment variable with: $ set http_proxy=http://127.0.0.1:1080 $ set https_proxy=http://127.0.0.1:1080

second, with privoxy or gost to transfer remote socks5 proxy service to a local http proxy port -> 127.0.0.1:1080.

then mpv can use local http proxy instead of any socks ones.

Justsoos avatar Nov 19 '17 14:11 Justsoos

AFAIK, the http_proxy envvar will cover both secure and non-secure http variants, so no need for a set https=... one?

But otherwise, good info I guess.

garoto avatar Nov 19 '17 14:11 garoto

@garoto This is application dependant and I wouldn't trust all programs to get this right. It doesn't hurt to simply

export http_proxy=http://127.0.0.1:8118
export HTTP_PROXY="$http_proxy"
export https_proxy="$http_proxy"
export HTTPS_PROXY="$http_proxy"
export ftp_proxy="$http_proxy"
export rsync_proxy="$http_proxy"
export no_proxy="localhost,127.0.0.1"

to reduce risk of information leaks.

lamarpavel avatar Nov 19 '17 16:11 lamarpavel

If that's the case, then it sucks that there's no conventional way of doing it. Feels kinda dirty to polute your shell .rc with what might be redundant envvars afterall... (I'm on Windows btw).

garoto avatar Nov 19 '17 16:11 garoto

@lamarpavel in Xinux, you can do better with proxychains-ng, u can use socks proxy directly instead of transfer for http proxy.

so, what I said is just for M$ windows.

Justsoos avatar Nov 19 '17 17:11 Justsoos

@garoto AFAIK, the http_proxy envvar will cover both secure and non-secure http variants, so no need for a set https=... one?

bad news, in Win 10, you have to also set https_proxy env, or you can not access https website by proxy.

Justsoos avatar Nov 19 '17 18:11 Justsoos

Ugh, I find it hard to believe that there's logic bult in "Win10" to differentiate between a http_proxy and a https_proxy env. variable, but who knows right?

garoto avatar Nov 19 '17 18:11 garoto

this is my workout in one line command with win 10: cmd.exe /C "set http_proxy=http://127.0.0.1:1080 && set https_proxy=http://127.0.0.1:1080 && c:\mpv.exe "URL"" and before that, have to run privoxy first to convert socks5 proxy to http proxy. terrible experience ...

Justsoos avatar Mar 22 '18 09:03 Justsoos

Is this still not something that we can get? It's been a request for 2 years now.

rypervenche avatar Jun 15 '18 17:06 rypervenche

I mean, you can do something like:

 mpv --ytdl-raw-options=proxy=[socks5://localhost:9050] videolinkhere

But there is some confusing language in the manual about this:

"A proxy URL can be passed for youtube-dl to use it in parsing the website. This is useful for geo-restricted URLs. After youtube-dl parsing, some URLs also require a proxy for playback, so this can pass that proxy information to mpv. Take note that SOCKS proxies aren't supported and https URLs also bypass the proxy. This is a limitation in FFmpeg."

Judging by this text it is half supported, and you must choose between HTTPS or Proxy/Tor?

IamPARANOID avatar May 18 '19 19:05 IamPARANOID

youtube-dl is only used to fetch the actual URL of the video (generally a googlevideo.com one) and then that URL is passed to the ffmpeg http downloader code, which doesnt support socks proxies.

For instance, if you feed the output of the command below to ffplay you get video: $ youtube-dl.exe --get-url https://www.youtube.com/watch?v=8EKl9aF4NnM

I think Justsoos idea of using gost as a forwarder works great and probably the best solution right now.

https://github.com/mpv-player/mpv/issues/3373#issuecomment-345519593

garoto avatar May 18 '19 21:05 garoto

in general, if you run mpv behind proxy, it must be a http proxy, if you have only socks proxy, transfer it to local http proxy first by privoxy or gost.

run it like, assuming your http proxy is 127.0.0.1:1080: http_proxy=http://127.0.0.1:1080 mpv $URL the http:// must be there, or error

if you run mpv to see youtube, you have to install youtube-dl first and run command line like: http_proxy=http://127.0.0.1:1080 mpv --ytdl-raw-options=proxy=%14%127.0.0.1:1080 $YOUTUBE_URL

this command seems a CRAZY one which you MUST NOT change any letter of: http_proxy=http:// and proxy=%14%127.0.0.1:1080 the number 14 is the length of 127.0.0.1:1080, include the punctuation characters, if your proxy's word-length is not exact like my example, pls count them by yourself.

another way to avoid that maddening shackles is setting the mpv.conf like:

ytdl=yes
ytdl-raw-options=proxy=[http://127.0.0.1:1080]

so you do not need to count the numbers on your screen... but you still need to run mpv like: http_proxy=http://127.0.0.1:1080 mpv $YOUTUBE_URL that is a flatter programmer's game, not for users, enjoy it!

Justsoos avatar Oct 19 '19 09:10 Justsoos

@lamarpavel, @Justsoos is there a guide how to setup privoxy to convert socks5 proxy to http(s)?

omnigenous avatar Aug 10 '24 09:08 omnigenous

Why do you need socks5?

There is no a good open source SOCKS 5 server available.

https://3proxy.ru

13ilya-old avatar Aug 17 '24 09:08 13ilya-old

Still no acceptable solution except using vpn?

You can just forget about HTTP proxies, no video hosting does not work with http protocol! I can't find a normal HTTPS proxy, they all give the error curl: (35) OpenSSL/3.1.4: error:0A00010B:SSL routines::wrong version number I can't always use vpn, so I need to be accessible from outside.

SOCKS5 is a perfect solution that works with browser and curl.

But unfortunately it doesn't work anymore neither through http nor through socks5 proxy. :-( YouTube somehow understands that proxy is used. yt-dlp --proxy socks5://127.0.0.1:1080 -F https://www.youtube.com/watch?v=glfh9XC-p9Q

[youtube] Extracting URL: https://www.youtube.com/watch?v=glfh9XC-p9Q
[youtube] glfh9XC-p9Q: Downloading webpage
[youtube] glfh9XC-p9Q: Downloading ios player API JSON
[youtube] glfh9XC-p9Q: Downloading web creator player API JSON
ERROR: [youtube] glfh9XC-p9Q: Sign in to confirm you’re not a bot. This helps protect our community. Learn more

yt-dlp --proxy http://127.0.0.1:3128 -F https://www.youtube.com/watch?v=glfh9XC-p9Q

[youtube] Extracting URL: https://www.youtube.com/watch?v=glfh9XC-p9Q
[youtube] glfh9XC-p9Q: Downloading webpage
[youtube] glfh9XC-p9Q: Downloading ios player API JSON
[youtube] glfh9XC-p9Q: Downloading web creator player API JSON
ERROR: [youtube] glfh9XC-p9Q: Sign in to confirm you’re not a bot. This helps protect our community. Learn more

13ilya-old avatar Aug 17 '24 11:08 13ilya-old

@lamarpavel, @Justsoos is there a guide how to setup privoxy to convert socks5 proxy to http(s)?

I used 3proxy for this. /var/lib/3proxy/3proxy.cfg

auth iponly

allow * 127.0.0.1 *
parent 1000 socks5 SERVER PORT USER PASSWORD

socks -p1080
proxy -a -p3128

3proxy /var/lib/3proxy/3proxy.cfg For test

curl -x socks5://127.0.0.1:1080 https://2ip.io
curl -x http://127.0.0.1:3128 https://2ip.io

The problem is that it doesn't work with YouTube anymore. :-(

13ilya-old avatar Aug 18 '24 22:08 13ilya-old

https://en.wikipedia.org/wiki/Censorship_of_YouTube

I miss doing mpv https://youtube.com... :-(

Tried proxychains with no luck too.

WeAreLiving1984 avatar Sep 30 '24 01:09 WeAreLiving1984