Skip to content

Instantly share code, notes, and snippets.

@avioli
Created September 3, 2018 00:07
Show Gist options
  • Save avioli/766c8d882eb0154d5f6ca9b027fc2aa7 to your computer and use it in GitHub Desktop.
Save avioli/766c8d882eb0154d5f6ca9b027fc2aa7 to your computer and use it in GitHub Desktop.
Watch YouTube via terminal (not IN terminal)

Watch YouTube via terminal (not IN terminal)

Run this:

hash youtube-dl 2>/dev/null || brew install youtube-dl; hash mpv 2>/dev/null || brew cask install mpv; echo -e '#!/bin/bash\nexec youtube-dl -o - "$@" | mpv --fs -' > ytp && chmod u+x ytp

It installs:

  • youtube-dl
  • mpv
  • creates a script, called ytp in your current dir and makes it user executable.

Then you can watch any YouTube videos (or most of these) from your terminal (but not IN your terminal).

./ytp "https://www.youtube.com/watch?v=7a5NyUITbyk"

NOTE: the player plays in full-screen, because of the --fs argument. Remove it, if you want to play in a window by default.

Bonus

Move the ytp script to a dir in your path, so you don't have to invoke it from that creation dir via ./ytp ...:

mv ./ytp /usr/local/bin/ytp

Then you can play from any dir:

ytp "https://www.youtube.com/watch?v=7a5NyUITbyk"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment