Я наконец-то нашел полезную библиотеку для анализа метаданных из аудиопотока, здесь: https://github.com/ghaiklor/icecast-parser. Но, тем не менее, я не могу получить ожидаемый ответ при отправке заголовков, как в примере ниже.
Первая функция делает запрос к радиостанции / каналу и получает поток:
_makeRequest() {
const request = http.request(this.getConfig('url'));
console.log("Making request to: " + this.getConfig('url'));
request.setHeader('Range', 'bytes=0-');
request.setHeader('User-Agent', 'VLC/2.2.4 LibVLC/2.2.4');
request.setHeader('Icy-MetaData', '1');
request.setHeader('Connection', 'close');
request.once('response', this._onRequestResponse.bind(this));
request.once('error', this._onRequestError.bind(this));
request.end();
return this;
}
Когда запрос к радиостанции успешно вызван, эта функция вызывается:
_onRequestResponse(response) {
console.log("Received response!");
console.log("Headers:");
console.log(response.headers['content-type']);
const icyMetaInt = response.headers['icy-metaint'];
console.log("icyMetaInt= " + icyMetaInt);
if (icyMetaInt) {
const reader = new StreamReader(icyMetaInt);
reader.on('metadata', metadata => {
console.log(metadata);
this._destroyResponse(response);
this._queueNextRequest(this.getConfig('metadataInterval'));
this.emit('metadata', metadata);
});
response.pipe(reader);
this.emit('stream', reader);
} else {
this._destroyResponse(response);
this._queueNextRequest(this.getConfig('emptyInterval'));
this.emit('empty');
}
return this;
}
Когда я использую эти функции для этого URL (url: 'http://streaming.radionomy.com/70-s-80-sMetal'),, ответ в консоли:
аудио / MPEG
icyMetaInt = undefined
Я понял, что самый важный заголовок здесь:
setHeader ('Icy-MetaData', '1')
Тем не менее, я не получаю 'icyMetaInt'. URL, кажется, содержит метаданные при проверке его другими инструментами.
Есть идеи, что здесь происходит не так? Спасибо!
;