19. Converting youtube videos to mp3 files¶
[status: content-mostly-written]
NOTE: before having anyone work on this project you should make sure that the videos you are downloading from youtube are all “OK” to be downloaded. Check the copyright on the videos and youtube’s terms for them.
19.1. Purpose: turn audio from youtube into mp3s¶
Take some URLs with songs, such as (to name a few that could make you run away screaming or have childhood memories):
19.2. preparation/prerequisites¶
have youtube-dl installed. You can do so with any of the methods described here:
https://github.com/rg3/youtube-dl/blob/master/README.md#installation
but since youtube formats move fast, you probably don’t want the stock system youtube-dl.
Easiest is probably to use pip. We do:
$ sudo apt-get install python-pip
$ sudo pip install --upgrade youtube-dl
- the programs easytag and id3info
$ sudo apt-get install easytag libid3-tools
- ffmpeg for converting formats
$ sudo apt-get install ffmpeg
- the media player vlc
$ sudo apt-get install vlc
- a music player. Your system probably come with rhythmbox; another is “clementine”. You can install them with:
$ sudo apt-get install rhythmbox
or
$ sudo apt-get install clementine
19.3. Get the video¶
Grab the video with:
$ youtube-dl -t "https://www.youtube.com/watch?v=CRROegxe7bU"
you can see any files that might have been downloaded with:
$ ls -sh
then canonicalize the name a bit with something like:
$ mv Stevie\ Wonder\ -\ Blowin\'\ in\ the\ wind\ \(Live\).wmv-CRROegxe7bU.mkv Stevie-Wonder_Blowin-in-the-wind-Live.mkv
(Note that that “mv” command could use a lot of “TAB” for filename completion so as to nail the backslashes.)
Now that the filename does not have spaces it is much more manageable.
List again with:
$ ls -sh
19.4. Verify that it’s a good video file¶
You can now play this on your own computer (even disconnected from the network!):
$ vlc Stevie-Wonder_Blowin-in-the-wind-Live.mkv
19.5. Extracting the audio portion¶
Now extract the mp3 audio from the video with:
$ ffmpeg -i Stevie-Wonder_Blowin-in-the-wind-Live.mkv Stevie-Wonder_Blowin-in-the-wind-Live.mp3
And now a listing with
$ ls -sh
shows that you have the mp3 file.
19.6. Tagging the mp3 file¶
There is a format called “id3” which lets you put information about a piece into a music file. This allows music players to form a database of your music and to display information about when you play it.
Edit the file with
$ easytag Stevie-Wonder_Blowin-in-the-wind-Live.mp3
Set the track title and artist.
You can verify that the id3 tags are set with:
$ id3info Stevie-Wonder_Blowin-in-the-wind-Live.mp3
Now you can put it in your ~/Music/ directory and your music player will pick it up.
Note that you can use the –extract-audio option for youtube-dl to extract the audio immediately, but it might use an obscure format like “.opus”, so you’d still need to use ffmpeg to convert it to mp3.