From 40f17d1f4bd03c48cb89a6e70e9cd7a3259334c6 Mon Sep 17 00:00:00 2001 From: Nick Shipp Date: Sat, 3 Jun 2017 01:33:15 -0400 Subject: Initial commit --- q-yt | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 q-yt (limited to 'q-yt') diff --git a/q-yt b/q-yt new file mode 100755 index 0000000..852b767 --- /dev/null +++ b/q-yt @@ -0,0 +1,47 @@ +#!/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 -- cgit v1.2.3-70-g09d2