Search code examples
c#mp3taglibid3taglib-sharp

Delete all pictures of an ID3 tag with taglib-sharp


I delete all pictures of an ID3 tag with taglib-sharp (version 2.1.0):

tagFile.Tag.Pictures = new TagLib.IPicture[0];
tagFile.Save();

If I read the file again with taglib-sharp there are no more pictures. This is OK, but the file size stays the same.

If I delete the picutre with a tool like mp3tag (http://www.mp3tag.de) the file size decreases.

Does anyone have an idea how I could reduce the file size with taglib-sharp?

Thanks in advance.

Rene


Solution

  • I've been looking at this and I have a workaround, if you keep a reference to all the tags you want to keep, remove the tags and add the ones you want back in, the file size shrinks. I realize this is pretty horrible, but it works. So if you just want to keep the title:

            string title;
            using (var taglibFile = TagLib.File.Create(file))
            {
                title = taglibFile.Tag.Title;
                taglibFile.RemoveTags(TagTypes.AllTags);
                taglibFile.Save();
            }
    
            using (var tagLibFile = TagLib.File.Create(file))
            {
                tagLibFile.Tag.Title = title;
                tagLibFile.Save();
            }