tags:

views:

248

answers:

2

I am writing a program to diff, and copy entire files or segments based on changes on either end (Rsync-esque... but more like Unison). The main idea is to keep my music folder (all mp3s) up to date over multiple locations.

I'd like to send segmented updates if only small portions of the file have changed, as opposed to copying the entire file. For this, I need a way to diff segments of the file.

I initially tried generating hashes for blocks of every file (Every n bytes I'd hash the segment). I noticed that when I changed one attribute (id3v2 tag on an mp3) all the hashed blocks would change. This makes sense, as I would guess the header is growing as it acquired new information.

This leads me to my actual question. I would like to know how to determine the length of an mp3's header, so I could create 2 comparable hashes.

1) The meta info of the file (header)

2) The actual mpeg stream with audio (This hash should remain unchanged if all I do is alter tag info)

Am I missing anything else?

Thanks!

Ty

A: 

If you want to determine the header information, you'll either:

  • a) need to use a mp3 library that can do the parsing for you, or
  • b) go to the mp3 specification and parse it out as needed.
yodaj007
+1  A: 

If all you want to check the length of is id3v2 tags, then you can find out information about its structure at http://www.id3.org/id3v2.4.0-structure.

If you read the first 3 bytes, and they are equal to "ID3", then skip to the 7th byte, then read the header size. Be careful though, because the size is stored as a "synchsafe integer".

ICR