I made a simple script in bash and also ported it to batch that lets you input a YouTube video ID and a filename as arguments and automatically downloads and converts it to an MP3 file.
Bash:
Code: Select all
#!/bin/sh
# Dependencies: vlc, lame. Use "sudo apt-get install vlc lame" to install them. :)
# Usage note: sh youtube2mp3.sh YOUTUBE-VIDEO-ID DEST
filename=$(basename "$2")
extension="${filename##*.}"
filename="${filename%.*}"
vlc -I dummy "http://www.youtube.com/watch?v=$1" ":sout=#transcode{acodec=s16l,channels=2}:std{access=file,mux=wav,dst=$filename.wav }" vlc://quit
if [ "$extension" = "mp3" ]; then
echo $extension is mp3
lame -h "$filename.wav" "$(echo $2 | cut -f 1 -d '.').mp3"
# Uncomment the following line to remove the .wav file after having converted it to mp3.
#rm "$filename.wav"
fi
Code: Select all
:: Dependencies: - VLC Media Player (http://www.videolan.org/vlc/)
:: - LAME encoder (http://www.rarewares.org/mp3-lame-bundle.php)
:: NOTE: You should add a semicolon and then the path to your VLC Media Player installation
:: to your PATH environment variable, e.g. ";C:\Program Files\VideoLAN\VLC".
:: IMPORTANT: Don't add a space between the path and the semicolon!
:: Usage note: youtube2mp3 <youtube-video-id> <filename>
@echo off
start /w "" vlc -I dummy http://www.youtube.com/watch?v=%1 ":sout=#transcode{acodec=s16l,channels=2}:std{access=file,mux=wav,dst=%~dpn2.wav }" vlc://quit
if "%~x2"==".mp3" (
start /w "" vlc -I dummy http://www.youtube.com/watch?v=%1 ":sout=#transcode{acodec=s16l,channels=2}:std{access=file,mux=wav,dst=%~dpn2.wav }" vlc://quit
lame -h "%~dpn2.wav" "%~dpn2.mp3"
:: Uncomment the following line to remove the .wav file after having converted it to mp3. ::
:: rm "%~dpn2.wav"
)