Created
October 15, 2023 00:10
-
-
Save manjaroman2/c35f40678e65a310b7de498071559a94 to your computer and use it in GitHub Desktop.
Sample downloading bash script (yt-dlp)
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
#!/usr/bin/bash | |
sample_dir="~/music/sampledl" | |
yt_dlp_path="/usr/local/bin/yt-dlp" | |
audio_format="mp3" | |
regex='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' | |
if [ -n "$1" ]; then | |
URL="$1" | |
else | |
URL=$(xsel -o) | |
if ! [[ $URL =~ $regex ]]; then | |
echo "\"$URL\" <-- this is not a valid URL in your clipboard" | |
exit | |
fi | |
fi | |
yt-dlp -x --audio-format mp3 --audio-quality 0 -o "$sample_dir/%(title)s.%(ext)s" --restrict-filenames $URL | |
echo "[DEBUG] updating yt-dlp" | |
echo "[DEBUG] https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp" | |
curl -s -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o $yt_dlp_path && chmod a+rx $yt_dlp_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment