In order to make this possible you need the program youtube-dl. In the beginning this program was only made for Youtube, hence the name. But today it has grown to support hundreds of sites, and Twitch is one of them.

There are several ways to install youtube-dl:

  • From your package manager, this version might be outdated.
  • System-wide by placing the script in /usr/local/bin, requires root.
  • As a user by placing the script in ~/bin.

I will install it as a user.

Download youtube-dl and place it in ~/bin:

cd ~/bin
wget https://yt-dl.org/downloads/latest/youtube-dl
chmod +x youtube-dl

Make sure ~/bin is in your PATH environment variable:

echo "$PATH" | grep -o "$HOME/bin"

If you get zero output, then add $HOME/bin to ~.profile:

echo 'PATH="$HOME/bin:$PATH"' >> ~/.profile
source ~/.profile

Make sure your youtube-dl is up-to-date:

youtube-dl -u

Watch a stream in mpv:

mpv "twitch.tv/stream"

Watch a stream in vlc:

youtube-dl -o - "twitch.tv/stream" | vlc -

If you need to login to watch a stream, add the following to ~/.netrc, replacing USERNAME and PASSWORD respectively:

machine twitch
login USERNAME
password PASSWORD

Make sure the permissions on ~/.netrc is properly set:

chmod 600 ~/.netrc

Then add the parameter as follows:

mpv --ytdl-raw-options=netrc "twitch.tv/stream"