"Picture-in-Picture" mode for YouTube videos in 4 lines of bash code

Add this function to your ~/.bashrc:

function youtube-stream-mpv() {
    local title=$(youtube-dl -e "$1")
    youtube-dl -o - "$1" | mpv --title="mpv - $title - \${width}x\${height}" --force-seekable=yes --ontop -

Make sure that you have mpv and youtube-dl installed.

Then just type youtube-stream-mpv <LINK-TO-YOUTUBE-VIDEO> in terminal, and magic shall happen.


Also tested on macOS. Install mpv and youtube-dl from Homebrew:

$ brew install --cask mpv
$ brew install youtube-dl

and it will work just as well as on Linux.

Awesome WM

When I used to use Awesome WM, I also wrote a of plugin for it, to fix mpv window position and properties:

To use the plugin, add to your rc.lua something like this:

local youtube = require('./youtube-stream-mpv')
If you have any comments, contact me by email.
powered by OpenBSD
© ch1p 2020