scripts

misc scripts and tools
git clone git://git.2f30.org/scripts.git
Log | Files | Refs

ytgrep (665B)


      1 #!/bin/sh
      2 #depends: jq
      3 #usage:
      4 # ytgrep [-n nresults] terms...
      5 
      6 KEY="AIzaSyAa5gAarPnuu9zTVjpp6mPyStbY17uuhSE"
      7 NRES=10	
      8 
      9 search() {
     10   sstr=""
     11   if [ ${#} -ne 1 ]; then #make a list
     12       for arg in $@; do 
     13           sstr=$sstr"$arg|"
     14       done
     15   else 
     16       sstr=$1
     17   fi
     18   curl -s -G "https://www.googleapis.com/youtube/v3/search" -d part="snippet" -d q=$sstr -d maxResults=$NRES -d key=$KEY | jq '[.items[] | {"title":.snippet.title, "url": ["https://www.youtube.com/watch?v=" + .id.videoId] }]' -
     19 }
     20 
     21 command -v jq >/dev/null || {
     22         echo jq is not installed 1>&2
     23         exit 1
     24 }
     25 
     26 case $1 in
     27   -n ) NRES=$2; shift 2; search $@
     28   ;;
     29   * ) search $@
     30   ;;
     31 esac