17

Sorry if this question is misguided. I'm using youtube-dl to download song videos as mp3's before adding them to itunes.

The problem is that the videos dont seem to contain the metadata in there. I read what i could understand about --add-metadata option but is this option only used to add the ids if they are already in the video?

I know the artist and song title so Id like a way to add it in directly if possible. Something to the effect --add-metadata-artist "Pink Floyd"

Is that possible with the current configuration options? I saw this related issue but it didnt really help

Here are my current configuration settings:

options = {
        'format':'bestaudio/best',
        'extractaudio':True,
        'audioformat':'mp3',
        'outtmpl':'%(id)s.%(ext)s',     #name the file the ID of the video
        'noplaylist':True,
        'nocheckcertificate':True,
        'proxy':"",
        'addmetadata':True,
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }]
    }
stackPusher
  • 6,076
  • 3
  • 35
  • 36

5 Answers5

21

There is the youtube-dl option: --add-metadata see the post-processing documentation. The documentation says that it will add metadata to the video file, but this will also work for audio files. I've used it to download the m4a audio file for a video, so it should also work for mp3. This option adds Artist, Track Title, Date and Comment tags.

I found that I needed to download FFmpeg for this to work, I just put the ffmpeg.exe file in the same directory as youtube-dl.exe (this is on a windows system).

I just noticed you mentioned you'd noticed this option. From testing it appears that it's using the Video Uploader for the Artist Tag, the actual Video name as the Title tag, the Video publish date as the Date tag and the Video comment for the Comment tag. So for music videos this is probably not ideal.

ptha
  • 836
  • 1
  • 8
  • 22
  • 1
    @zerohedge it takes metadata from the Youtube video itself: Artist, Track Title, Date and Comment tags, and then adds it to the video or audio file metadata tags. You don't need to specify any additional arguments. – ptha Nov 25 '17 at 15:12
  • 1
    haven't touched this side project in years but your answer seems to have exceeded my own in popularity so i'll mark you as the correct answer. thanks! – stackPusher Jan 26 '23 at 14:50
7

Since someone upvoted my question, I'll mention that I did not end up finding a way to do this with youtube-dl, but thats ok because its easy to do with EasyID3:

from mutagen.easyid3 import EasyID3

metatag = EasyID3(pathToMp3File)
metatag['title'] = "Song Title"
metatag['artist'] = "Song Artist"
metatag.RegisterTextKey("track", "TRCK")
metatag['track'] = 7
metatag.save()

More info about how to use it here

Community
  • 1
  • 1
stackPusher
  • 6,076
  • 3
  • 35
  • 36
  • 3
    Thanks for posting your answer! Found this super useful, wrote a nice little python executable for parsing audio files in a directory and applying `artist - title` format metadata. `EasyMP4` from `mutagen.easymp4` also has identical functionality, and can be used for `m4a` files. – Luke Davis Feb 26 '17 at 08:38
  • How do you get the final path to downloaded final after conversion so you are able to change it with EasyID3 ? – Leandro Loureiro Jan 23 '21 at 22:16
1

You can add FFmpegMetadata in the postprocessors lists.

options = {
    'format':'bestaudio/best',
    'extractaudio':True,
    'audioformat':'mp3',
    'outtmpl':'%(id)s.%(ext)s',     #name the file the ID of the video
    'noplaylist':True,
    'nocheckcertificate':True,
    'proxy':"",
    'addmetadata':True,
    'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        },
        {
            'key': 'FFmpegMetadata'
        }]
Chris1320
  • 11
  • 1
1

Found a solution which works for me (inspired by this thread). You need to add an additional post processor like this.

ytd_opt_audio = {
'format': 'bestaudio/best',
'postprocessors': [{
    'key': 'FFmpegExtractAudio',
    'preferredcodec': 'mp3',
    'preferredquality': '192',
},{
    'key': 'FFmpegMetadata',
    'add_metadata': True,
}]}
MrWinter
  • 11
  • 2
0

If you want to do this with Youtube-dl, you can use the --postprocessor-args switch:

--add-metadata --postprocessor-args "-metadata artist=Pink\ Floyd"
pbarney
  • 2,529
  • 4
  • 35
  • 49