node-livestream-metainfo
Advanced tools
Comparing version
20
index.js
const fetch = require("node-fetch"); | ||
const { pipeline } = require("stream"); | ||
const { promisify } = require("util"); | ||
const streamPipeline = promisify(pipeline); | ||
const regex = /StreamTitle=(.*?);/ | ||
@@ -17,10 +13,9 @@ | ||
const song = await new Promise(resolve => { | ||
streamPipeline(response.body, async source => { | ||
source.setEncoding("utf8"); | ||
for await (const chunk of source) { | ||
if (regex.test(chunk)) { | ||
const song = chunk.match(regex)[1]; | ||
resolve(song.substring(1, song.length - 1)); | ||
} | ||
response.body.on("data", chunk => { | ||
chunk = chunk.toString(); | ||
if (regex.test(chunk)) { | ||
response.body.destroy(); | ||
const song = chunk.match(regex)[1]; | ||
return resolve(song.substring(1, song.length - 1)); | ||
} | ||
@@ -33,2 +28,3 @@ }); | ||
description: response.headers.get("icy-description"), | ||
genre: response.headers.get("icy-genre"), | ||
bitrate: parseInt(response.headers.get("icy-br")), | ||
@@ -35,0 +31,0 @@ audioInfo: response.headers.get("ice-audio-info"), |
{ | ||
"name": "node-livestream-metainfo", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"description": "Lightweight module for fetching basic meta information from livestreams", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
0
-100%3264
-4.14%26
-10.34%