youtube-mp3 () {
# put thins function in your ~/.bashrc
${1:?"error: I need a youtube link"} # testing existence of programs
NEEDED_COMMANDS="yt-dlp ffmpeg"
missing_counter=0
for needed_command in $NEEDED_COMMANDS; do
if ! hash "$needed_command" >/dev/null 2>&1; then
printf "Command not found in PATH: %s\n" "$needed_command" >&2
((missing_counter++))
fi
done
if ((missing_counter > 0)); then
sudo apt-get install -y $NEEDED_COMMANDS fi
# geting video and converting with ffmpeg
yt-dlp --restrict-filenames -x --audio-format=mp3 --audio-quality 320k "${@:-1}"
# get last argument bashy only
# https://stackoverflow.com/a/1854031
}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.