-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathstations.js
33 lines (30 loc) · 960 Bytes
/
stations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const CSON = require('cson-parser');
const path = require('path');
const pMap = require('p-map');
const readFile = require('util').promisify(require('fs').readFile);
const streamInfo = require('./scripts/streamInfo');
module.exports = async function () {
const cson = await readFile(path.join(__dirname, './stations.cson'));
const stations = CSON.parse(cson);
return pMap(stations.playlist.track, async station => {
try {
const stream = await getStreamInfo(station);
if (!stream) return station;
return Object.assign({}, station, { stream });
} catch (err) {
return station;
}
});
};
async function getStreamInfo(station) {
const { streams } = await streamInfo(station.location);
const info = streams && streams[0];
if (!info) return;
return {
codec: info.codec_name,
profile: info.profile,
bitrate: parseFloat(info.bit_rate),
sampleRate: parseFloat(info.sample_rate)
};
}