WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Miscellaneous

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Reading MP3s ID3 Tags

Keywords: 	 Reading MP3s ID3 Tags

Question:

Does anyone has a procedure, a script, code for reading MP3s ID tags?

It would be cool if you could pass me the codes or hints. I'm trying to write a program that would put the ID tags on web pages, for personal consultation at the office from my personal databank...

an MP3 ID tag is an MPeg Layer 3 - those that created such a commotion with Napster and all - can send you one thrgouh e-mail if you want to check it out... big though - 3 megs at least

If you have an MP3, open it with word pad (or whatever software that won't convert the file to any format... check at the end, the last 128bites, and you'll see that you have plain text showing there - it is the tag of the MP3.

The point of the exercise is to extract the content of those 128bites, without havin'g to parse through the total file, which would take forever since each file (and I have oh so many) is at least a couple of megs.

Any suggestion on how to extract the last 128 bites in the fastest matter possible?

Answer:

Here's some sample code: Note that:
  1. BinaryReplace is a newer function.
  2. This code checks and if you have an older version it does it the hard way
  3. This is required as some MP3 files have nulls (00) in the buffer which will terminate a string. This code converts nulls to spaces.
  4. The last byte is grabbed with a binarypeek. WinBatch will display it as a decimal number but it really is a binary number and can be operated on as such.

fn="C:\WINDOWS\Desktop\Monty Python - String.mp3"

fs=Filesize(fn)
bb=BinaryAlloc(128+1)
bytes2read=min(128,fs)

BinaryReadEx(bb,0,fn,fs-bytes2read,bytes2read)

if Version() >= "2000C"
   BinaryReplace(bb,""," ",@true)
else
  for xx=0 to 127
     if BinaryPeek(bb,xx) == 0
        BinaryPokeStr(bb,xx," ")
     endif
  next
endif


TagString=BinaryPeekStr(bb,0,127)
LastByte=BinaryPeek(bb,127)
BinaryFree(bb)
Message(Strcat("LastByte=",lastbyte),TagString)

Answer:

Another user reports the following:

You will need to be careful about it. Not all MP3s may have an ID3 embedded. To check to see if it does have ID3, the first three characters of the last 128 bytes of the file should be 'TAG'

I do not need to convert nulls into spaces. My preferred method of extracting the elements of the ID3 is simple. All elements have the same offset, of course, and they all have limits.

I hope you will find this code to be useful:


mp3="Elton John-Someday Out of the Blue.mp3"
size=filesize(mp3)

bb=binaryalloc(128)
binaryreadex(bb,0,mp3,size-128,128)
id3=binarypeekstr(bb,0,3)
if id3=="TAG"
title=strtrim(binarypeekstr(bb,3,30))
artist=strtrim(binarypeekstr(bb,33,30))
album=strtrim(binarypeekstr(bb,63,30))
year=strtrim(binarypeekstr(bb,93,4))
comments=strtrim(binarypeekstr(bb,97,30))
else
title="Untitled"
artist="Unknown Artist"
album=""
year=""
comments=""
endif
For me:

title returns "Someday Out of the Blue"
artist returns "Elton John"
album returns "Road to El Dorado"
year returns "2000"
comments returns a blank string

A Binarypeek(bb,127) will return some integer representing the Genre, but I do not know what goes with what number.

For the binary decryption, I found a page that gave me the information with a cute and verry comprehensible table. Follow this link and have fun:

http://www.mirc.net/tips/id3.php3
See Also:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP+Get~Audio~File~Information.txt
Article ID:   W14623
Filename:   Reading MP3s ID3 Tags.txt
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38