Skip to content

Instantly share code, notes, and snippets.

@ajskateboarder
Last active January 2, 2024 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajskateboarder/c179577068ed8e8f73aaea24c33f8b34 to your computer and use it in GitHub Desktop.
Save ajskateboarder/c179577068ed8e8f73aaea24c33f8b34 to your computer and use it in GitHub Desktop.
Play a YouTube video from the terminal in WSL with PulseAudio
#!/bin/bash
export PULSE_SERVER="tcp:$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')"
pulseaudio --start
# replace USER with a username, VIDEO with a YouTube video ID, and TERMINAL with an terminal (konsole, gnome-terminal, etc.)
pasuspender -- /home/USER/.local/bin/youtube-dl -o - "https://youtube.com/watch?v=VIDEO" | mpv - --no-terminal --really-quiet --display-tags-clr --player-operation-mode=pseudo-gui > /dev/null & disown; sleep 4 && kill `ps -axjf | grep -m 1 "\_ TERMINAL" | awk '{print $2}'`; exit
@ajskateboarder
Copy link
Author

Currently doesn't work because youtube-dl gives 403 - or do I need to update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment