#!/bin/zsh # Search for things in places key=$(url encode < $XDG_CONFIG_HOME/priv/keys/youtube) requests=12 api_base=$(uri create \ --scheme=https \ --authority=www.googleapis.com \ --path=youtube/v3/search \ --query-param-part=snippet \ --query-param-maxResults=$requests \ --query-param-key=$key) name=${${0:t}#q-} function query { local q type type=video url=$(uri change \ --query-param-q="$*" \ --query-param-type=$type \ <<< $api_base) curl -s $url } function parse { jshon -CQ -e items \ -a \ -e snippet \ -e title -up \ -e description -upp \ -e id -e videoId -u | \ while { read -r title read -r desc read -r id } do printf '%s!%s!%s!%s\n' \ "$name" \ "${title//!}" \ "${desc//!}" \ "ytdl://$id" done } query $@ | parse