Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- usage () {
- echo "./$0 <youtube-video-id> <resolution>"
- echo "example: ./$0 cdwal5Kw3Fc 360p"
- }
- main () {
- url="https://youtube.com/get_video_info?video_id=$1"
- videoInfoFile=$(wget -qO- $url)
- declare -A videoInfo
- while read key value
- do
- videoInfo["$key"]="$value"
- done < <(awk -F'&' '{for(i=1;i<=NF;i++) {print $i}}' <<< $videoInfoFile | awk -F'=' '{print $1" "$2}')
- playerResponse=${videoInfo["player_response"]}
- decodedPlayerResponse=$(printf '%b' "${playerResponse//%/\\x}")
- result=($(echo $decodedPlayerResponse | jq .'streamingData' | jq '.formats' | jq '.[] | .url, .qualityLabel'))
- title=$(echo $decodedPlayerResponse | jq .'videoDetails' | jq .'title' | tr "\"" " " | tr -d '[:space:]' | tr "+" " ")
- declare -A links
- for ((i = 0 ; i < ${#result[@]}-1 ; i+=2))
- do
- url=$(echo ${result[$i]} | tr "\"" " " | tr -d '[:space:]')
- resolution=$(echo ${result[$i+1]} | tr "\"" " " | tr -d '[:space:]')
- links["$resolution"]="$url"
- done
- if [ "${links["$2"]}" = "" ]; then
- if [ ${#links[@]} -eq 0 ]; then
- echo "+ Video not available"
- else
- echo "+ Resolution not available"
- echo "+ Downloadable resolution: ${!links[@]}"
- fi
- exit 1
- fi
- target="$title-$2.webm"
- wget ${links["$2"]} -qO "$target"
- }
- if [ $# -eq 0 ]; then
- usage
- exit 1
- fi
- main $1 $2
- exit 0
- # echo ${links["$2"]}
- # echo $result
- # result=$()
- # echo $result
- # jsonFormat=$(echo $videoInfo | tr '&' '\n' | jq -Rsc 'split("\n")')
- # jsonLength=$(echo $jsonFormat | jq length)
- # echo $jsonFormat | jq '.[csi_page_type]'
- # x=$(curl $url)
- # echo $x
- # cat ../Downloads/get_video_info | tr '&' '\n' | jq -Rsc 'split("\n")' | jq '.[0]'
Add Comment
Please, Sign In to add comment