TooTallNate / node-icy

Node.js module for parsing and/or injecting ICY metadata
MIT License
291 stars 48 forks source link

Detecting OGG stream and switching from node-lame decoder to node-ogg decoder? #38

Closed Kezzsim closed 1 year ago

Kezzsim commented 6 years ago

Greetings,

I'd really like to build an app that can support both regular shoutcast / icy mp3 streams as well as the icy OGG streams that Traktor creates natively. Both of the libraries you've written, node-lame and node-ogg decode to raw PCM which is great for streaming one format into another, ultimately the stream I encode and send out will be from the node-lame encoder because it has greater browser support.

However, I've been looking for a way to glean some information from icy that will give me a heads up as to what the stream's file format is so I can use a conditional statement to switch out decoder instances. I've tried getting the information from icy.parse(metadata); and the URL method mentioned in the example (to get the headers) but I can't seem to find something that will let me determine the container for the format icy gets from the server.

I could try to use the lame decoder's .on('format', function(format) { in some sort of a try catch scenario but that seems kind of inefficient; also wondering if there are other resource based things that make this unfeasible.

I'd appreciate the input

Thanks~

mo-g commented 1 year ago

I imagine you're well past this now, but the solution would have been "Content-Type" returned in the request headers. audio/mpeg for mp3 (so decode with lame), application/ogg for vorbis.

Side note - you'd need to use my fork for this, as this version doesn't reliably pass through the headers.