Skip to content

Instantly share code, notes, and snippets.

@steve-todorov
Created March 22, 2016 01:45
Show Gist options
  • Save steve-todorov/04cac601680b205aa68c to your computer and use it in GitHub Desktop.
Save steve-todorov/04cac601680b205aa68c to your computer and use it in GitHub Desktop.
Download youtube videos and convert them to mp3
#!/bin/sh
save_path=`pwd`
checkDeps() {
youtubedl=`which youtube-dl 2> /dev/null`
ffmpeg=`which ffmpeg 2> /dev/null`
if [[ $youtubedl == "" || $ffmpeg == "" ]]; then
echo ""
echo "Youtube-DL or ffmpeg is missing!"
echo ""
echo "Please install Youtube-DL: "
echo " http://rg3.github.io/youtube-dl/download.html"
echo ""
echo "Please install ffmpeg (from packman suse >= 42.1!): "
echo " zypper in ffmpeg lame libavcodec57 libavdevice57 libavfilter6 libavformat57 libavresample3 libavutil55 libdcadec0 libpostproc54 libswresample2 libswscale4 libx264-148 libx265-79 libmp3lame0"
exit
fi
}
convert() {
url=$1
echo "Converting $url to mp3..."
youtube-dl --extract-audio --audio-format=mp3 --audio-quality 320k --embed-thumbnail --add-metadata --write-description --write-info-json -o "$save_path/%(title)s-%(id)s.%(ext)s" "$url"
echo ""
echo ""
}
convertFromUrl() {
url=$1
convert $url
}
convertFromFile() {
f=$1
IFS=$'\n'
for url in `< $f`; do
convert $url
done
}
checkDeps
songs=$1
if [[ $songs == http* ]]; then
convertFromUrl "$songs"
else
if [ !-f $songs ]; then
convertFromFile $songs
else
echo "Could not access $songs - file not readable or doesn't exist!"
exit
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment