Patrick Marchand

Plumb rule for YouTube

Ever wanted to open youtube links in your native player from any acme(1) window?

youtube-dl(1) will parse url’s of youtube and other providers and download the video. mpv(1) is capable of using it as a backend to download youtube videos.

  1. Put this in your plumber(4) file

    type is text
    data matches '(watch\?)([a-zA-Z0-9]+\=[a-zA-Z0-9\_@\-]+\&)*(v\=[a-zA-Z0-9\_@\-]+)+(\&[a-zA-Z0-9]+\=[a-zA-Z0-9\_@\-]+\&?)*'
    plumb start sh -c 'mpv --cache-secs=60 --really-quiet --force-window=immediate --ytdl-format=bestvideo[height\<=?1080]+bestaudio/best --ytdl-raw-options=yes-playlist='"$0"'
  2. Reload your plumb(7) rules with cat plumbing | 9p write plumb/rules

  3. Right click the watch? part of this url


The regex matches any text that has watch?v=id along with any other query parameters.

To test a new plumb rule regex, use plumb start sh -c 'echo '"$0"' as it’s action.

The video is me initiating a young girl to sit-skiing.

The mpv options in order

Other media players can be used by piping the output of youtube-dl to them. Although they might have their own integrations.