mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
26.61k stars 2.83k forks source link

Support SOCKS5 proxies #3373

Open adamhotep opened 7 years ago

adamhotep commented 7 years ago

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.

haasn commented 7 years ago

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)

lamarpavel commented 7 years ago

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.

nxtreaming commented 7 years ago

Why do you need socks5?

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

adamhotep commented 7 years ago

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.

v2px commented 7 years ago

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

liaowang11 commented 7 years ago

@v2px I tried

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

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

haasn commented 7 years ago

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).

Justsoos commented 7 years ago

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 commented 7 years ago

@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.

ilf commented 6 years ago

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

Justsoos commented 6 years ago

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.

garoto commented 6 years ago

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.

lamarpavel commented 6 years ago

@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.

garoto commented 6 years ago

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).

Justsoos commented 6 years ago

@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 commented 6 years ago

@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.

garoto commented 6 years ago

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?

Justsoos commented 6 years ago

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 ...

rypervenche commented 6 years ago

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

IamPARANOID commented 5 years ago

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?

garoto commented 5 years ago

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

Justsoos commented 4 years ago

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!