Question

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

Was it helpful?

Solution 2

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();
        }

OTHER TIPS

Because SepehrM asked me to post my code as an answer:

TagLib.Tag tempTag = null;
TagLib.File tagFile = TagLib.File.Create(file);
tempTag = new TagLib.Id3v2.Tag();
tagFile.Tag.CopyTo(tempTag,true);
tagFile.RemoveTags(TagLib.TagTypes.AllTags);
tagFile.Save();
tagFile.Dispose();


TagLib.File tagFile2 = TagLib.File.Create(file);
tempTag.CopyTo(tagFile2.Tag, true);
tagFile2.Save();
tagFile2.Dispose();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top