Download videos from youtube and convert it mp3 all on the commandline

in #linux7 years ago

If you are like me and you listen to music all the time, then you will probably want a way to turn your music into mp3's so that you can listen to it in your car, or maybe you even found a track that you would like to upload to googleplaymusic.
You can download youtube-dl,which is a script that allows you to download youtube videos using their url.
You can use youtube-dl like this:

$  youtube-dl https://www.youtube.com/watch?v=egIWskTD5J8

The video is then downloaded to the current directory. Take note that the video can be in one of three formats. It can be either webm, mkv or mp4. To get the video into mp3 will take some effort. If you downloaded a bunch of videos then it is rather boring to convert each video to mp3 , one by one, by hand. Take note that youtube-dl can be pointed to a playlist
if you would like to download an entire playlist of videos.
For example let's download the playlist of Linux Tutorials from thenewboston channel:

$ youtube-dl https://www.youtube.com/playlist?list=PL6gx4Cwl9DGCkg2uj3PxUWhMDuTw3VKjM

If you downloaded a great deal of videos to a directory, then you can convert the contents of a directory
to mp3. You can do it by running these three commands(Assuming you have videos of all three file types in a directory:

Mkv to mp3:

 $ find . -type f -name "*.mkv" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -c:a libmp3lame -y "${FILE%.mkv}.mp3";' _ '{}' \;

Mp4 to mp3:

$ find . -type f -name "*.mp4" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -c:a libmp3lame -y "${FILE%.mp4}.mp3";' _ '{}' \;

Web too:

$ find . -type f -name "*.webm" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -c:a libmp3lame -y "${FILE%.webm}.mp3";' _ '{}' \;

You will need to have ffmpeg installed.
Please comment if you need help with installing ffmpeg or youtube-dl and I'll try assist as far as I can.
Btw, does anyone know of a script for dtube downloading? Maybe I havn't used the site long enough to know how to download from dtube, but I havn't had any success so far.

Sort:  

You can also have youtube-dl convert to an mp3 automatically after the download by using the -x option like so:

youtube-dl -x --audio-format mp3 https://...

You'll still need ffmpeg installed.

As far as a tool that supports dtube I know of none, but the best bet would be if someone added that support youtube-dl. It already supports many other sites. https://github.com/rg3/youtube-dl/blob/master/docs/supportedsites.md

Thanks that is really informative. I will add that to my wiki. Here is a link to my wiki:
https://yoirtuts.com/index.php?title=Convert_Directory_Of_MKV_Files_To_Mp3

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.030
BTC 59190.54
ETH 2521.17
USDT 1.00
SBD 2.53