nicfit / eyeD3

eyeD3 is a Python module and command line program for processing ID3 tags. Information about mp3 files (i.e bit rate, sample frequency, play time, etc.) is also provided. The formats supported are ID3v1 (1.0/1.1) and ID3v2 (2.3/2.4).
http://eyed3.nicfit.net/
GNU General Public License v3.0
536 stars 58 forks source link

Remove tags matching a string #522

Open clustor opened 3 years ago

clustor commented 3 years ago

What's the recommended way to iterate through the tags present in an mp3 and remove all the tags if there is an exact match to a string?

Currently I am reviewing text frames, URL tags and comments on a case by case basis. This is ok but not the cleanest solution for a generic approach.

strings_to_match = ["xxxx", "yyyy"]
for fid in list(audiofile.tag.frame_set):
    if fid.startswith(b"T") or fid.startswith(b"TX"):
        if audiofile.tag.getTextFrame(fid) in strings_to_match:
            del audiofile.tag.frame_set[fid]

#Remove all URL frames
for fid in id3.frames.URL_FIDS:
    if(audiofile.tag.frame_set[fid]):
        del audiofile.tag.frame_set[fid]

#Remove COMMENT frame
if(audiofile.tag.frame_set[COMMENT_FID]):
    del audiofile.tag.frame_set[COMMENT_FID]

On a related note, is there a way to remove all tags excluding certain ones programmatically?

nicfit commented 3 years ago

strings_to_match = ["xxxx", "yyyy"]
for fid in list(audiofile.tag.frame_set):
    if fid.startswith(b"T") or fid.startswith(b"TX"):
        if audiofile.tag.getTextFrame(fid) in strings_to_match:
            del audiofile.tag.frame_set[fid]

This works for b"T", but not b"TX". The latter are user text frames and there may multiple TXXX frames, but the descriptions must be unique. So, this room removes all TXXX .