summaryrefslogtreecommitdiff
path: root/q-yt
diff options
context:
space:
mode:
Diffstat (limited to 'q-yt')
-rwxr-xr-xq-yt47
1 files changed, 47 insertions, 0 deletions
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