Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading YouTube to mp3 and writing metadata (artist/song title) to mp3 file using youtube-dl

I am extracting audio only from youtube videos using youtube-dl. I would like to write the metadata (i.e. Artist Name and Song Title) into the mp3 file after downloading. My attempt to accomplish this starts with this code:

@echo off
set dl=https://www.youtube.com/watch?v=2Y6Nne8RvaA
youtube-dl --metadata-from-title "%(artist)s - %(title)s" --extract-audio --audio-format mp3 -o "%%(title)s.%%(ext)s" --add-metadata %dl%
pause

The output from this code is:

[youtube] 2Y6Nne8RvaA: Downloading webpage
[youtube] 2Y6Nne8RvaA: Downloading video info webpage
[youtube] 2Y6Nne8RvaA: Extracting video information
[download] Destination: Kungs vs Cookin' on 3 Burners - This Girl.webm
[download] 100% of 3.33MiB in 00:02
[fromtitle] Could not interpret title of video as "(title)s"
[ffmpeg] Adding metadata to 'Kungs vs Cookin' on 3 Burners - This Girl.webm'
[ffmpeg] Destination: Kungs vs Cookin' on 3 Burners - This Girl.mp3
Deleting original file Kungs vs Cookin' on 3 Burners - This Girl.webm (pass -k t
o keep)
Press any key to continue . . .

As you can see, the code adds the metadata to .webm filename, but not to the .mp3 file. It is useless to write this to the .webm file because the this file is deleted upon completion of the process. I want this metadata to be written to the .mp3 file so that when I view songs in a folder, it will look like the following:

enter image description here

This format is useful to me because I can then directly input these files into iTunes and the metadata will be intact!

I'm running Windows 7, 64bit, Python 3.5.

like image 598
IRNotSmart Avatar asked Dec 08 '16 23:12

IRNotSmart


People also ask

How do I download MP3 files from youtube-dl?

If you only want to download audio from a YouTube video, you can use the -x option with youtube-dl. This extract-audio option converts the video files to audio-only files. The file is saved in the same directory from where you ran the youtube-dl command.

How do I create a youtube-dl file?

In %APPDATA%\Roaming , create a youtube-dl folder if one doesn't already exist. Inside that folder, create a plain text file named config. txt . Place youtube-dl options in the file as you'd normally use them on the command line with youtube-dl , placing each one on a new line.

Can youtube-dl download from youtube music?

Luckily youtube-dl provides an option to download a whole playlist or just a range of songs within it. For that purpose, you will need to use the following options: --playlist-start NUMBER – Playlist video to start at (default is 1) --playlist-end NUMBER – Playlist video to end at (default is last)

Where do youtube-dl files go?

By default youtube-dl downloads files in the same directory from where you run the command. Mostly it's your home directory. If your name is Tom, then it is /home/Tom. To force it to download elsewhere you should use -o option; and to select quality of video, there is -f option.


Video Answer


1 Answers

That page does not even offer an MP3 file:

$ youtube-dl --format mp3 2Y6Nne8RvaA
ERROR: requested format not available

and even if you try an end-around like you have done, it does not work:

$ youtube-dl --audio-format mp3 2Y6Nne8RvaA
$ ffprobe 'Kungs vs Cookin’ on 3 Burners - This Girl-2Y6Nne8RvaA.mkv'
Input #0, matroska,webm, from 'Kungs vs Cookin’ on 3 Burners - This Girl-2Y6Nne8RvaA.mkv':
  Duration: 00:03:17.48, start: -0.007000, bitrate: 2462 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080
    Stream #0:1(eng): Audio: opus, 48000 Hz, stereo (default)

Use m4a instead:

youtube-dl --format m4a 2Y6Nne8RvaA

You are using:

--extract-audio

when you can just download the audio by itself:

youtube-dl --format m4a 2Y6Nne8RvaA

You are using:

https://www.youtube.com/watch?v=2Y6Nne8RvaA

when you can just use:

2Y6Nne8RvaA

You are not using:

--youtube-skip-dash-manifest

I can tell because of this extra line:

[youtube] 2Y6Nne8RvaA: Downloading video info webpage

Even if everything worked the way you want, you would probably still have trouble because of the ID3 version:

FFmpeg metadata not showing in Windows?

like image 113
Zombo Avatar answered Oct 04 '22 19:10

Zombo