ytfzf
ytfzf copied to clipboard
[Feature request]: get video over the proxy if catch "[youtube] Video unavailable"
Background
[yes] I have checked ytfzf(1) and ytfzf(5) or the wiki before creating this.
Problem
Why do we need this feature? I see the list of videos. I select video in this list. But ytfzf returns the error from yt-dlp for some videos:
ytdl_hook: ERROR: [youtube] <video_id>: Video unavailable. This video is restricted. Please check the Google Workspace administrator and/or the network administrator restrictions.
ytdl_hook: youtube-dl failed: unexpected error occurred
cplayer: Failed to recognize file format.
But when I start mpv to play video over tor - than video played.
I research why youtube block some video:
- youtube blocks video if I try to download it from my ISP (Internet Service Provider);
- youtube does not block this video, if I download this video from other ISP in my town. So, restrictions is applied by my ISP, not by IP or Country.
This feature allow to automatically use external proxy for download the videos, which are restricted for IP of the user.
Feature
Description of your proposed feature.
Add an option to conf.sh:
ytdl_opts_fallback
Whether or not to use external proxy for fail downloaded videos.
Format of the value - as in yt-dlp option "proxy".
default= <empty line>
Example:
ytdl_opts_fallback="--ytdl-raw-options-append=proxy=\"http://127.0.0.1:9050\""
With this option:
- ytfzf download video with ytdl_opts;
- if catch an error - download video with ytdl_opts concatenated with ytdl_opts_fallback.
Alternative solutions to problem?
- Variant 1: not use ytfzf.
- Variant 2: configure external proxy for MPV In this case, list of videos will be downloaded directly, but videos will be downloaded over the proxy-server. But than all videos will be downloaded over the proxy-server. And I need to proxyfy only some videos, not each.
handle_keypress_alt_y () {
ytdl_opts="$ytdl_opts --proxy=http://127.0.0.1:9050"
url_handler_opts="$url_handler_opts --ytdl-raw-options-append=proxy=\"http://127.0.0.1:9050\""
}
is_loop=1
custom_shortcut_binds=alt-y
#i kinda messed up in v2.4.0, so this line is necessary for that.
shortcut_binds="${shortcut_binds},${custom_shortcut_binds}"
There is not a reliable way to see why youtubedl/mpv crashed. Therefore, the above config will add a shortcut in fzf, when you press alt-y
it appends the fallback options to ytdl_opts. If you wanted to do ctrl-y
, you could replace handle_keypress_alt_y
with handle_keypress_ctrl_y
and custom_shortcut_binds=ctrl-y
, you can ofc do whatever fzf allows.
It enables loop so that if it can't play the video, it reopens fzf, and you can press alt-y or whatever you choose.
FIX: corrct option, to use tor in yt-dlp, have an "socks" scheme, not "http" scheme:
--proxy=socks4://127.0.0.1:9050
I put this lines into my conf.sh at the end of file:
handle_keypress_alt_y () {
ytdl_opts="$ytdl_opts --proxy=socks4://127.0.0.1:9050"
url_handler_opts="$url_handler_opts --ytdl-raw-options-append=proxy=socks4://127.0.0.1:9050"
}
is_loop=1
custom_shortcut_binds=alt-y
shortcut_binds="${shortcut_binds},${custom_shortcut_binds}"
But still get an error ERROR: [youtube] <video_id>: Video unavailable. This video is restricted.
for "alt-y" and "return" key sequences.
The same error I get if use simple command mpv https://www.youtube.com/watch\?v\=<video_id>
.
Then I try command:
mpv --ytdl-raw-options-append=proxy=socks4://127.0.0.1:9050 https://www.youtube.com/watch\?v\=<video_id>
and get the same error - "video unavialable".
I see my bash alias:
$ alias mpv-tor
mpv-tor='http_proxy= https_proxy= torsocks -q mpv'
I find, that mpv can play videos only over http/https proxy, not by socks proxy. So, to play video over tor, I have 2 variants:
- use proxyficator: torify, proxychains4, tsocks, etc;
- use proxy chain: mpv -> http proxy (privoxy, gost, etc) -> tor proxy.
I configure my Privoxy daemon to forward youtube.com queries to local tor proxy 127.0.0.1:9050 and configure ytfzf with those lines:
ytdl_opts="$ytdl_opts --proxy=http://127.0.0.1:8018"
url_handler_opts="$url_handler_opts --ytdl-raw-options-append=proxy=http://127.0.0.1:8018"
And video, which unavialable by return
key, will play success with alt-y
key sequence.
My problem resolved! But this problem was resolved only partly.
New problem
I need to start separate proxy-server to use chain http proxy -> socks proxy
.
But I already have one instance of Privoxy to do ad-blocking. And I do not want to proxy all videos to the youtube over the 127.0.0.1:9050.
Keep on the separate Privoxy instance to only proxy the videos to youtube over the 127.0.0.1:9050 - is an overhad.
But it is a task for other feature request.