diff options
| author | Nick Shipp <nick@shipp.ninja> | 2017-06-03 01:33:15 -0400 | 
|---|---|---|
| committer | Nick Shipp <nick@shipp.ninja> | 2017-06-03 01:33:15 -0400 | 
| commit | 40f17d1f4bd03c48cb89a6e70e9cd7a3259334c6 (patch) | |
| tree | 5984140fe779d76aac734bf0cc1474c2a03bddce /q-yt | |
Diffstat (limited to 'q-yt')
| -rwxr-xr-x | q-yt | 47 | 
1 files changed, 47 insertions, 0 deletions
| @@ -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 | 
