youtube-mp3 () {
# get mp3 from youtube video
# Author: Sergio Luiz Araujo Silva
# site: http://vivaotux.blogspot.com
# mail: voyeg3r [gmail]
# twititer: @voyeg3r
# Instalation: put thins function in your ~/.bashrc
# testing parameters
if [ $# -eq 0 ] ; then
echo -e '\n\tUSAGE: youtube-mp3 youtube-link\n'
return 0
fi
# testing existence of programs
NEEDED_COMMANDS="youtube-dl 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
youtube-dl --restrict-filenames -x --audio-format=mp3 --audio-quality 320k "${1}"
}