From 85a0115e9f6e4a83b87e2214e572a5fe38c6e5e0 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Sun, 15 Sep 2024 22:03:06 +0200 Subject: [PATCH] Initial version --- youtube-cli/README.md | 13 +++++++++++++ youtube-cli/youtube-cli.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 youtube-cli/README.md create mode 100755 youtube-cli/youtube-cli.sh diff --git a/youtube-cli/README.md b/youtube-cli/README.md new file mode 100644 index 0000000..1d8240a --- /dev/null +++ b/youtube-cli/README.md @@ -0,0 +1,13 @@ +# youtube-cli + +Commandline youtube search tool. + +# Prerequisites + +* jq +* yt-dlp +* firefox / something (change script if needed) + +# Usage + + ./youtube-cli.sh diff --git a/youtube-cli/youtube-cli.sh b/youtube-cli/youtube-cli.sh new file mode 100755 index 0000000..45dfc74 --- /dev/null +++ b/youtube-cli/youtube-cli.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +if [ "$#" -gt 0 ]; then + echo "Searching youtube for: $*..." + + tempfile=$(mktemp) + + yt-dlp -j "ytsearch5:$*" 2> /dev/null > $tempfile + + # See: https://mywiki.wooledge.org/BashFAQ/005 + # For alternatives (read file line-by-line), see: https://mywiki.wooledge.org/BashFAQ/001 + mapfile -t youtube_urls < <(cat $tempfile | jq '.webpage_url' | tr -d '"' ) + + mapfile -t choices < <(cat $tempfile | jq '.fulltitle, .webpage_url') + for i in "${!choices[@]}"; do + let m=i%2 + if [ $m -eq 0 ]; then + let j=i/2+1 + echo "$j: ${choices[$i]}" + else + echo " ${choices[$i]}" + fi + done + + echo "" + echo "Enter video index to run:" + read i + if [ -n $i ]; then + # you can dou whatever like'em pee-vee + firefox-developer-edition ${youtube_urls[$i - 1]} + fi + + rm "$tempfile" +else + echo 'Usage: ./youtube-cli.sh ' +fi