A browser extension to play youtube video from mpv (with the help of yt-dlp) via native messaging protocol. It is still a very rough MVP. Play with it at yout own risk.
We need to compile a both the extension
and the native host application
wrapping mpv which the extension messaging to.
We can use nix
Install nix
nix build
- The directory for the extension
- ./result/share/chrome/extensions
- The native host application
- ./result/bin/youtube-mpv-native-host
Install typescript if you don’t have it.
To check if you have got tsc and fyi my tsc version.
tsc -v
Version 5.2.2
pwd
pnpm i # NOTE: pnpm can be replaced with npm, yarn, etc
tsc
/Users/fanshi/Personal/chrome-extensions/youtube-mpv/extension Lockfile is up to date, resolution step is skipped Progress: resolved 1, reused 0, downloaded 0, added 0 Packages: +4 ++++ Progress: resolved 4, reused 4, downloaded 0, added 4, done devDependencies: + @types/chrome 0.0.254 Done in 865ms
Newly compiled js will be inside ./extension/dist, now this is your extension.
Probably use ghcup to install them. To check if you have got ghc/cabal and fyi my ghc/cabal version.
ghc --version
cabal --version
The Glorious Glasgow Haskell Compilation System, version 9.6.3 cabal-install version 3.10.2.1 compiled using version 3.10.2.1 of the Cabal library
pwd
cabal build -O2
/Users/fanshi/Personal/chrome-extensions/youtube-mpv/native-host Resolving dependencies... Build profile: -w ghc-9.6.3 -O2 In order, the following will be built (use -v for more details): - youtube-mpv-native-host-0.1.0.0 (exe:youtube-mpv-native-host) (first run) Configuring executable 'youtube-mpv-native-host' for youtube-mpv-native-host-0.1.0.0.. Preprocessing executable 'youtube-mpv-native-host' for youtube-mpv-native-host-0.1.0.0.. Building executable 'youtube-mpv-native-host' for youtube-mpv-native-host-0.1.0.0.. [1 of 1] Compiling Main ( app/Main.hs, /Users/fanshi/Personal/chrome-extensions/youtube-mpv/native-host/dist-newstyle/build/x86_64-osx/ghc-9.6.3/youtube-mpv-native-host-0.1.0.0/x/youtube-mpv-native-host/opt/build/youtube-mpv-native-host/youtube-mpv-native-host-tmp/Main.o ) [2 of 2] Linking /Users/fanshi/Personal/chrome-extensions/youtube-mpv/native-host/dist-newstyle/build/x86_64-osx/ghc-9.6.3/youtube-mpv-native-host-0.1.0.0/x/youtube-mpv-native-host/opt/build/youtube-mpv-native-host/youtube-mpv-native-host
pwd
cabal list-bin -O2 youtube-mpv-native-host
/Users/fanshi/Personal/chrome-extensions/youtube-mpv/native-host /Users/fanshi/Personal/chrome-extensions/youtube-mpv/native-host/dist-newstyle/build/x86_64-osx/ghc-9.6.3/youtube-mpv-native-host-0.1.0.0/x/youtube-mpv-native-host/opt/build/youtube-mpv-native-host/youtube-mpv-native-host
You need a browser(Chrome for example) and Mpv + yt-dlp (and to setup ytdl path for mpv as needed)
- https://developer.chrome.com/docs/extensions/develop/concepts/native-messaging#native-messaging-host
- fyi I make the file at ~/Library/Application Support/Google/Chrome/NativeMessagingHosts/youtube.mpv.json, but your location might be different.
{
"name": "youtube.mpv",
"description": "play youtube with mpv",
"path": "${path to your compiled native host executable}",
"type": "stdio",
"allowed_origins": ["chrome-extension://${extension-id}/"]
}
- Or
- Pack it.
You can setup a [youtube-mpv] profile, see https://mpv.io/manual/master/#profiles
Turn on the extension and goto youtube, click on any video and see it youself (via mpv
of course).
PRs accepted