Python - Add ID3 tags to mp3 file that has NO tags

后端 未结 1 855
借酒劲吻你
借酒劲吻你 2021-01-11 15:09

I get a lot of podcasts that have no ID3 tags in them. I\'ve tried a number of tools that I could use to loop through directories and add title and artist info to the ID3 ta

1条回答
  •  礼貌的吻别
    2021-01-11 15:36

    Mutagen handles this just fine:

    >>> import mutagen
    >>> from mutagen.easyid3 import EasyID3
    >>> filePath = "8049.mp3"
    
    >>> try:
    >>>    meta = EasyID3(filePath)
    >>> except mutagen.id3.ID3NoHeaderError:
    >>>    meta = mutagen.File(filePath, easy=True)
    >>>    meta.add_tags()
    >>> meta
    {}
    >>> type(meta)
    
    >>> meta['title'] = "This is a title"
    >>> meta['artist'] = "Artist Name"
    >>> meta['genre'] = "Space Funk"
    >>> meta.save(filePath, v1=2)
    >>> changed = EasyID3("8049.mp3")
    >>> changed
    {'genre': [u'Space Funk'], 'title': [u'This is a title'], 'artist': [u'Artist Name']}
    

    0 讨论(0)
提交回复
热议问题