wapmorgan / Mp3Info

The fastest PHP library to extract mp3 meta information (duration, bitrate, samplerate and so on) and tags (id3v1, id3v2).
https://wapmorgan.github.io/Mp3Info/
GNU Lesser General Public License v3.0
139 stars 41 forks source link

Add separate classes for local and remote file access #37

Open mbirth opened 3 months ago

mbirth commented 3 months ago

I'm using Mp3Info to query the duration of podcasts hosted on a remote HTTP server. These are usually 1 hour or longer and thus between 100 and 250 MB in size. The current version of Mp3Info always downloads these files completely before returning a result which takes a long time.

I've now fanned out the file reading into two classes - one for local files, that works basically the same as the current version. And another class for remote files that only downloads the parts Mp3Info needs to work on. It does that using HTTP Range requests and currently is configured to download 4 kB blocks. So in the best case, this only has to download 8 kB per file (one block at the beginning of the file, one block at the end) for Mp3Info to be able to read the metadata - which takes far less time than downloading the whole file.