Skip to content

Instantly share code, notes, and snippets.

@icidasset
Last active November 5, 2015 15:18
Show Gist options
  • Save icidasset/c6d972c90a2d2f0565b1 to your computer and use it in GitHub Desktop.
Save icidasset/c6d972c90a2d2f0565b1 to your computer and use it in GitHub Desktop.
A rough idea of how a audio-metadata scanner, using http requests, should work in Javascript.

(1) Make a HEAD request to retrieve the size of the file

  • Use the Content-Length header
  • If this is 0, then exit.

(2) Make an instance of HTTPBinaryFile.

HTTPBinaryFile is a class which extends BinaryFile.
BinaryFile being a generic class which handles binary file data.
Basicly: { bytes: { '0-100': set_of_bytes, '400-500': set_of_bytes }}

HTTPBinaryFile and other classes which extend BinaryFile have a function called 'loadRange'. In the case of HTTPBinaryFile, this makes a ranged http request and stores the requested bytes.

Notes
  • Use typed arrays
  • Use isomorphic-fetch for http(s) requests

(3) Get the first 7 bytes of the file to identify the file format.

Bytes 4 to 7 for mp4 files and bytes 0 to 3 for mp3 files.
Roughly speaking. TODO: read specs.

(4) Make instance of tag reader and read the tags.

Examples

ID3v1 loads the last 128 bytes of the file and then parses that to get the metadata.

Notes

It seems like ID3v2 and ID4 are a whole lot more complicated. Are there any decent articles on these formats?

(5) Profit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment