Re: Adding tags (Was: How to manipulate both V1 and V2 tags in the same file)
Rob Leslie <[email protected]> Tue, 21 Sep 2004 22:44:10 -0700
| Newsgroups | gmane.comp.audio.mad.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sep 21, 2004, at 6:08 AM, Linus Walleij wrote:
> Just out of curiosity - are you experiencing the same problem as me,
> that it seems impossible to add a tag to a file which does not have
> one already using libid3tag, and how have you solved it?
>
> What I am experiencing is:
>
> * If a file has ID3v2 but not ID3v1, only the ID3v2 tag is
> manipulated, no
> ID3v1 tag is added.
To add an ID3v1 tag, you must set the ID3_TAG_OPTION_ID3V1 option on
the file tag, e.g.:
id3_tag_options(tag, ID3_TAG_OPTION_ID3V1, ~0);
Likewise if you want to remove the ID3v1 tag, unset the option by
passing 0 as the third argument. The file interface uses this option to
determine whether the file should have an ID3v1 tag.
To determine whether the file currently has an ID3v1 tag, you can test
like this (before modifying the option):
id3_tag_options(tag, 0, 0) & ID3_TAG_OPTION_ID3V1
> * If a file has ID3v1 only, vice versa.
This is unfortunately because the file interface is incomplete. ID3v2
tag writing in cases where the entire file should ordinarily be
rewritten is not yet implemented.
> * If a file has neither, the file won't have a tag after being
> processed
> by libid3tag either.
This has the same causes as above.
Until the file interface is completed, I suggest manipulating tags in
the file directly yourself. You can render an ID3v2 tag by unsetting
the above option and calling id3_tag_render(); likewise render an ID3v1
tag by setting the option. Rewriting a file involves placing the ID3v2
tag at the beginning, the data stream in the middle, and the ID3v1 tag
at the end.
It's also possible to place the ID3v2 tag at the end, before the ID3v1
tag. To do this you must set the ID3_TAG_OPTION_APPENDEDTAG option
before rendering. The file interface will find and read such tags, but
the ubiquity of other tag-reading tools that support such appended tags
is unknown.
--
Rob Leslie
[email protected]