ys (908B)
1 #!/bin/sh 2 # 3 # 2f30 4 # search youtube via api 5 6 [ -n "$TORIFY" ] && proxy="--proxy socks5://127.0.0.1:9050" 7 8 KEY="AIzaSyAa5gAarPnuu9zTVjpp6mPyStbY17uuhSE" 9 NRES=10 10 11 search() { 12 sstr="" 13 if [ ${#} -ne 1 ]; then 14 for arg in $@; do 15 sstr=$sstr"$arg+" 16 #sstr=$sstr"$arg|" 17 done 18 else 19 sstr=$1 20 fi 21 22 json="$(curl -s ${proxy} \ 23 -G "https://www.googleapis.com/youtube/v3/search" \ 24 -d part="snippet" \ 25 -d q=$sstr \ 26 -d maxResults=$NRES \ 27 -d key=$KEY | \ 28 jq '[.items[] | {"title":.snippet.title, 29 "url": ["https://www.youtube.com/watch?v=" + .id.videoId] }]' -)" 30 31 printf -- "---------------------------------------------\n" 32 for i in $(seq 0 $(( $NRES - 1)) ); do 33 printf "%s" "$json" | jq ".[${i}].title" 34 printf "%s" "$json" | jq ".[${i}].url[]" 35 printf -- "---------------------------------------------\n" 36 done 37 } 38 39 case $1 in 40 -n) 41 NRES=$2 42 shift 2 43 search $@ 44 ;; 45 *) 46 search $@ 47 ;; 48 esac