Search code examples
pythonpython-2.7metadataflacmutagen

Delete Music File Metadata Tag


How do I delete a metadata tag from a FLAC file or MP3 ID3 tag? I can use mutagen to edit information, but how would I delete a single portion of information?

I need to delete a tag entitled fmps_playcount, but not the rest of the metadata.


Solution

  • For ID3 tags you can remove a frame with delall. For example:

    >>> print audio.pprint()
    TPE1=Agalloch
    TALB=The Mantle
    TRCK=1/9
    TIT2=A Celebration For The Death Of Man...
    TCON=Metal
    >>> audio.delall('TCON')
    >>> print audio.pprint()
    TPE1=Agalloch
    TALB=The Mantle
    TRCK=1/9
    TIT2=A Celebration For The Death Of Man...
    

    For deleting the FLAC metadata (I do not have any FLAC files to test this on), I have a good feeling about:

    >>> del audio['tag_to_delete']
    

    Since the help documentation has:

     |  __delitem__(self, key)
     |      Delete a metadata tag key.
     |      
     |      If the file has no tags at all, a KeyError is raised.
    

    You can read more about the delitem magic method here: http://www.rafekettler.com/magicmethods.html