问题
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:
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.
回答1:
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?
来源:https://stackoverflow.com/questions/41050896/downloading-youtube-to-mp3-and-writing-metadata-artist-song-title-to-mp3-file