Question

i already have mp3 binary data, i just want to know how can i extract info from it. v1 is easy, take last 128 characters and you are done. but v2 has variable length. documentation says that tag size will be in header but i was unable to find it in any song i tested.

but anyways i simply want to extract album and artist info.. jsut these two, with javascript. lets take for simplicity sake that i have first 2000 bytes of a Taylor swift song in a variable (below is the actual binary data of a song):

ID3!vTYER2010TIT2
Last KissMCDI¬E+96+4484+918B+E800+12F4B+1A636+1EC24+23A8E+2905F+2F7DD+33868+3914B+3D931+44555+4A27BTRCK13TCON(2)CountryPRIVPeakValue¡PRIVAverageLevel{ TPE2
Taylor SwiftPRIV)WM/MediaClassSecondaryIDPRIV'WM/MediaClassPrimaryID¼}`Ñ#ãâK¡H¤*(DPRIVWM/ProviderAMGPRIVWM/WMContentIDÇ1t>êDëþëPRIV"WM/WMCollectionID   ¨F}âH"Y#7 ÈPRIV'WM/WMCollectionGroupID  ¨F}âH"Y#7 ÈTPUBBig MachinePRIVWM/UniqueFileIdentifierAMGa_id=R  2026672;AMGp_id=P   816977;AMGt_id=T 22057912TALB
Speak NowTPE1
Taylor SwiftTLEN369120ÿûà@üK

now i can easily locate the album and artist name (last two lines). and i can also find where the data begins with js pretty easily. just locate TALB and TPE1. simple. but how in the world do i know where the data ends..? they may or may not be adjacent to each other in other songs. they may or may not be uppercase. how do all the other libraries figure out where the data ends?

also there is no 'size' in the beginning as the documentation suggests.

EDIT can anyone help me out please? i really need this

Was it helpful?

Solution

The binary sample you show is missing some data. An ID3 version 2.4 tag frame header is 10 bytes in length and consists of the following fields:

  • ID -- 4 bytes (e.g. TIT2)

  • Size -- 4 bytes (is sync-safe in versions >= 2.4)

  • Flags -- 2 bytes

The size field tells you how many bytes of data are in that particular frame. Similarly the actual tag header is 10 bytes as well:

  • ID -- 3 bytes (always ID3)

  • Version -- 2 bytes (major version and revision. e.g. 0x04 0x00 indicates a 2.4.0 tag version)

  • Flags -- 1 byte

  • Size -- 4 bytes (is sync-safe in versions >= 2.3)

See: http://id3.org/id3v2.4.0-structure

Once your script has the binary data, you can parse these size fields to determine the size of the complete tag as well as the size of each frame. Once you get to this point you're going to run into sync-safe integers.

See: Why are there Synchsafe Integer?

OTHER TIPS

Try this library, looks like it does what you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top