Nushell Youtube Script
There is a neat youtube script that allows you to fuzzy search youtube api from really simple tools and it looks something like this from (https://github.com/MarcoLucidi01/bin/blob/master/ytsearch):
#! /usr/bin/env bash
case "$1" in "-h" | "--help")
echo "usage: ytsearch query..."
exit 0
esac
curl -s -G "https://www.youtube.com/results" --data-urlencode "search_query=$*" \
| tr -d '\n' \
| sed -e 's#^.*var \+ytInitialData *=##' -e 's#;</script>.*##' \
| jq -r '..
| .videoRenderer?
| select(.)
| [.title.runs[0].text[:80], (.lengthText.simpleText//"N/A"), (.shortViewCountText.simpleText//"N/A"), (.publishedTimeText.simpleText//"N/A"), .longBylineText.runs[0].text, .videoId]
| @tsv' \
| column -s "$(printf '\t')" -t \
| fzf --with-nth=..-2 \
| awk '{ print "https://www.youtube.com/watch?v="$NF }'
I thought it would be a good highlight of nushell's capabilities to do all of this with nushell alone. Yes, that includes fuzzy finder built-in!
http get https://www.youtube.com/results?search_query=(input|url encode)
| split row "var ytInitialData ="
| last
| split row ";</script>"
| first
| from json
| get -o contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents.0.itemSectionRenderer.contents.videoRenderer
| uniq | sort | drop
| select title.runs.text.0 videoId
| flatten
| input list -f -d "title.runs.text.0"
| get videoId | $"https://www.youtube.com/watch?v=($in)"
There is a certain elegance to this solution and it's somewhat more readable than a lot of these unix tools. The combined size of curl, tr, sed, jq, fzf, awk comes comparably close to nushell's 40 MB(?) binary.