[ID3 Dev] tagsize calcultaion

Ben Bennett fiji at ayup.limey.net
Mon Apr 11 11:25:21 PDT 2005


On Mon, Apr 11, 2005 at 11:11:06AM -0700, Eric Pederson wrote:
> Has anyone documented a ID3v2 reading algorithm?  Perhaps that would help
> with adoption by various applications.  It would help me with my
> (prospective) reader (in Python) - I haven't had time to focus sufficiently
> on the spec, yet.

Not that I am aware of.  The basic algorithm I use is pretty simple
though:
 - Look for the tag header at the start (or the footer near the end
   for 2.4) then get the total tag size
 - Read the whole tag into memory
 - Parse the extended header (this is version dependent, 2.3 and 2.4
   are different)
 - Parse the body of the tag frame by frame:
   + Read the frame header & work out the frame size (2.3/2.4
     dependent)
   + Read the frame body
   + Optionally parse the frame body (you can do it now, or do it
     later if an accessor on the frame is called)

The devil is of course in the details.  The nasty problems you will
have to consider are:
 - How to parse all of the frames... I built a simple data structure
   to describe most of the frames and then wrote a generic parser that
   can use the structure to read and validate them
 - How to handle the differences between 2.3 and 2.4 (some tags got
   changed, so if you want to convert between 2.3 and 2.4 you have some
   thinking to do, I am still working on this)
 - If you want to handle tag grouping (for encryption).  I have never
   seen anything that uses this, so I may punt
 - If you want to support the LINK tag... again, I haven't seen
   anything that uses it, so I may punt
 - How to handle bogus 2.4 implementations (e.g. iTunes)

I can make my current Perl code available if you want, but I am still
in an exploratory mode, so the code is not particularly clean, and it
is sprinkled with TODO items.  I need to refactor it and move some
duplicate code into subroutines before I actually am willing to
release it...  Anyway, let me know if you want to see it.

There are programing guidelines at http://www.id3.org/id3guide.htm
that provide some good pointers (mostly for writing frames though).
Also there is a document summarizing the changes between 2.3 and 2.4
that is worth a close read... there are things there that I didn't get
until I re-read it http://www.id3.org/id3v2.4.0-changes.txt.

      Good luck,

		       -ben

---------------------------------------------------------------------
To unsubscribe, e-mail: id3v2-unsubscribe at id3.org
For additional commands, e-mail: id3v2-help at id3.org



More information about the ID3v2 mailing list