commit b00e604c77f311053bee6b14e884fd4afec157c7 parent baf5cd21a6fab97f3065e89b9fd9362d7fca92ae Author: dsp <dsp@2f30.org> Date: Mon, 13 Feb 2017 11:02:03 -0700 Initial commit of ytgrep. Uses the youtube API to search for terms. Can return a maximum of 50 results for now. requires jq from ports. Diffstat:
A | ytgrep | | | 31 | +++++++++++++++++++++++++++++++ |
1 file changed, 31 insertions(+), 0 deletions(-)
diff --git a/ytgrep b/ytgrep @@ -0,0 +1,31 @@ +#!/bin/sh +#depends: jq +#usage: +# ytgrep [-n nresults] terms... + +KEY="AIzaSyAa5gAarPnuu9zTVjpp6mPyStbY17uuhSE" +NRES=10 + +search() { + sstr="" + if [ ${#} -ne 1 ]; then #make a list + for arg in $@; do + sstr=$sstr"$arg|" + done + else + sstr=$1 + fi + 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, "id": ["https://www.youtube.com/?v=" + .id.videoId] }]' - +} + +command -v jq >/dev/null || { + echo jq is not installed 1>&2 + exit 1 +} + +case $1 in + -n ) NRES=$2; shift 2; search $@ + ;; + * ) search $@ + ;; +esac