Skip to content

fanshi1028/youtube-mpv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Youtube mpv browser extension

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.

Build

We need to compile a both the extension and the native host application wrapping mpv which the extension messaging to.

Nix

We can use nix

Install nix

To build

nix build
The directory for the extension
./result/share/chrome/extensions
The native host application
./result/bin/youtube-mpv-native-host

Non-Nix

The extension

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

Compile the extension, run

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.

The native host application

Install ghc + cabal if you don’t have it

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

Compile the native host

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
To find the path to the compiled executable, and fyi mine is at
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

Hey, of course

You need a browser(Chrome for example) and Mpv + yt-dlp (and to setup ytdl path for mpv as needed)

Setup

To register a native messaging host

{
  "name": "youtube.mpv",
  "description": "play youtube with mpv",
  "path": "${path to your compiled native host executable}",
  "type": "stdio",
  "allowed_origins": ["chrome-extension://${extension-id}/"]
}

To load the extension

Or
Pack it.

To Configure mpv behaviour

You can setup a [youtube-mpv] profile, see https://mpv.io/manual/master/#profiles

Usage

Turn on the extension and goto youtube, click on any video and see it youself (via mpv of course).

Contributing

PRs accepted

License

MIT © fanshi1028

About

use mpv to play youtube video

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published