HTTP tokenizer for Node.js and browser
npm install @tokenizer/http




shell script
npm install @tokenizer/http
`
or using yarn:
`shell script
yarn add @tokenizer/http
`
Usage
$3
* resolveUrl, boolean, default value is true. Enable caching of redirects of HEAD requests.
$3
`js
// const mm = require('music-metadata-browser'); // Use module 'music-metadata-browser' client side
const mm = require('music-metadata'); // Use module 'music-metadata' in Node.js
const {makeTokenizer} = require('@tokenizer/http');
const audioTrackUrl = 'https://test-audio.netlify.com/Various%20Artists%20-%202009%20-%20netBloc%20Vol%2024_%20tiuqottigeloot%20%5BMP3-V2%5D/01%20-%20Diablo%20Swing%20Orchestra%20-%20Heroines.mp3';
(async () => {
const httpTokenizer = await makeTokenizer(audioTrackUrl);
const metadata = await mm.parseFromTokenizer(httpTokenizer);
console.log('metadata:', metadata);
})();
`
Server requirements
The server needs to send the following headers:
| HTTP header-| Value |
|-------------|-------|
| Access-Control-Allow-Origin | "*" |
| Access-Control-Allow-Methods | "GET,HEAD,OPTIONS" |
| Access-Control-Allow-Headers | "Content-Type, Range" |
| Access-Control-Expose-Headers | "Content-Length, Content-Range" |
Example configuring Apache for streaming. Add the following to .htaccess in the folder sharing your audio tracks:
`
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,HEAD,OPTIONS"
Header set Access-Control-Allow-Headers "Content-Type, User-Agent, If-Modified-Since, Cache-Control, Range"
Header set Access-Control-Expose-Headers "Content-Length, Content-Range"
`
Ref:
* streamroot.io: Range requests basics
Try if range request is supported:
`bash
curl -v -L --header "range: bytes=1-8" http://localhost:8080/bbb/test
``