KISS 🇺🇦

Stop the war!

Stop the war in Ukraine! Fuck putin!

More information is at: https://war.ukraine.ua/.

There is a fund to support the Ukrainian Army: https://savelife.in.ua/en/donate/, and there is a special bank account that accepts funds in multiple currencies: https://bank.gov.ua/en/about/support-the-armed-forces. I donated to them. Please donate if you can!

Killer putin

Killer putin. Source: politico.eu.

Arrested putin

"It hasn't happened yet, but it will happen sooner or later. Beautiful photo, isn't it?" Source: twitter.

Playing any video from firefox with mpv and youtube-dl

| comments

Modern browsers are very complicated programs, especially because they also need to be secure to protect users from countless threats on the interwebs. That means that the plugins functionality is necessarily quite limited. Firefox used to have XUL extensions, allowing to have the powerful vimperator; but from Firefox 57, only WebExtensions API is supported. There is a replacement for vimperator written with the WebExtensions API: tridactyl, however it’s more limited.

Lots of websites now provide video content. But sometimes videos have ads, sometimes the player’s interface is inconvenient, or the video is blocked on the page even though it can be loaded if you know the link. youtube-dl is an amazing program that can download videos from dozens of websites. How do you make it work with your current tab in Firefox?

Tridactyl

My solution is to use tridactyl’s exclaim_quiet command that allows to run a command in shell. It requires the native messenger to be installed, check with :native; to install, run :nativeinstall.

mpv is the CLI media player nowadays (replacement for mplayer) and it has built-in support for youtube-dl. Make sure mpv is installed, it will bring youtube-dl as a dependency:

1
$ brew install mpv

Put this into your ~/.tridactylrc:

1
bind ,v composite js document.location.href.replace('https://', 'ytdl://') | shellescape | js -p 'PATH="$PATH:/usr/local/bin" mpv ' + JS_ARG | !s

This command binds ,v to run the composite command: get the current tab’s URL, replace https:// with ytdl:// to force mpv to use youtube-dl, escape the URL, prepend the $PATH setting and the mpv command, and launch the resulting command silently.

Having this in the file, either run :source in the tridactyl’s command-line or restart Firefox.

Finally you can press ,v on any webpage that youtube-dl knows about and mpv should start playing the video, now you have all the power and options of mpv to enjoy the video. Note that youtube-dl will also attempt to get a video URL from domain that it doesn’t know about, it may work.

Previous attempts

My first attempt was to run mpv directly and avoid the shell:

1
:composite js document.location.href | shellescape | ! /usr/local/bin/mpv --ytdl --script-opts=ytdl_hook-try_ytdl_first=yes

but it didn’t work: [ytdl_hook] [ytdl_hook] youtube-dl failed: not found or not enough permissions Failed to recognize file format.Exiting... (Errors when loading file).

I switched to creating the command-line for shell with the same result:

1
:composite js document.location.href | shellescape | js -p '/usr/local/bin/mpv --ytdl ' + JS_ARG | !

Enabling debug logs:

1
:composite js document.location.href | shellescape | js -p '/usr/local/bin/mpv --ytdl --msg-level=ytdl_hook=debug ' + JS_ARG | !

revealed the issue:

1
[ytdl_hook] No youtube-dl found with path youtube-dl in config directories …

Hence the final command above that sets $PATH to include /usr/local/bin/.

Comments