Skip to content

Instantly share code, notes, and snippets.

@go-ive
Created August 15, 2016 21:49
Show Gist options
  • Save go-ive/1322365f4c459f371e054864f60dd5b3 to your computer and use it in GitHub Desktop.
Save go-ive/1322365f4c459f371e054864f60dd5b3 to your computer and use it in GitHub Desktop.
YouTube DL + ffmpeg mp3 downloader script
#!/bin/bash
readonly TMP_DIR="/tmp/ytdl"
readonly TMP_OUT="/tmp/out"
readonly ARGS="$@"
download_video() {
echo "================================ Downloading $1 ================================"
youtube-dl $1 --output ${TMP_DIR}/%\(title\)s
}
delete_tmp() {
rm -rf ${TMP_DIR}
}
convert(){
ffmpeg -i "${TMP_DIR}/${1}" -acodec libmp3lame -ab 128k "${TMP_OUT}/${1}.mp3"
}
get_filename(){
ls ${TMP_DIR}
}
main() {
mkdir -p ${TMP_OUT}
while read url
do
download_video $url
convert "$(get_filename)"
delete_tmp
done < ${ARGS[0]}
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment