Skip to content

Instantly share code, notes, and snippets.

@Silur
Created September 20, 2017 10:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Silur/abbcc9a240c726bed8a0db3fdf6dcbf5 to your computer and use it in GitHub Desktop.
Save Silur/abbcc9a240c726bed8a0db3fdf6dcbf5 to your computer and use it in GitHub Desktop.
youtube viewer in bash
# usage ./yt.sh <https://youtube.com/watch?v=....>
urldecode() {
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
video_url="$1"
raw_url=$(curl \
-H 'Upgrade-insecure-requests: 1' \
-H 'Cache-control: max-age=0' \
-H 'Accept-language: en-US,en;q=0.8,bn;q=0.6' \
-H 'Accept-encoding: gzip, deflate, sdch' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' \
"${video_url}" \
| gunzip \
| egrep -o 'https%3A%2F%2F[^\.]*\.googlevideo.com%2F[^,\]*' \
| head -n 1)
mplayer $(urldecode "$raw_url")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment