Created
October 29, 2022 00:41
-
-
Save rsa16/dc2eb2d4e2143afec61f6a276e51417c to your computer and use it in GitHub Desktop.
search youtube and download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tempfile=$(mktemp) | |
youtube_dl_log=$(mktemp) | |
youtube-dl -j "ytsearch5:$*" > $tempfile | |
# workaround for lack of mapfile in bash < 4 | |
# https://stackoverflow.com/a/41475317/6598435 | |
while IFS= read -r line | |
do | |
youtube_urls+=("$line") | |
done < <(cat $tempfile | jq '.webpage_url' | tr -d '"' ) | |
# # for bash >= 4 | |
# mapfile -t youtube_urls < <(cat $tempfile | jq '.webpage_url' | tr -d '"' ) | |
cat $tempfile | jq '.fulltitle, .webpage_url' | |
while : | |
do | |
echo "Enter video number to download." | |
read i | |
# don't download anything if you just press enter | |
if [ ! x"$i" == x"" ] | |
then | |
# to make numbering of videos more intuitive (start from 1 not 0) | |
youtube-dl -x --audio-format mp3 --no-progress ${youtube_urls[$i - 1]} & | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment