74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
fs = require('fs');
|
|
var tableify = require('tableify');
|
|
const express = require('express')
|
|
const basicAuth = require('express-basic-auth')
|
|
const app = express()
|
|
const port = 6969
|
|
|
|
let DNSArray = require('./DNSArray.json')
|
|
let streamArrays = require('./streamArray.json')
|
|
const otherDNS = require('./otherDNS.json')
|
|
|
|
const { gotRequest } = require('./gotRequest')
|
|
|
|
function writeFile(streamArrays) {
|
|
fs.writeFileSync('streamArray.json', JSON.stringify(streamArrays), function (err) {
|
|
if (err) return console.log(err);
|
|
});
|
|
}
|
|
|
|
function splitToArray(DNS) {
|
|
DNS = DNS.split(',')
|
|
return DNS
|
|
}
|
|
|
|
function mapToStream(DNSList) {
|
|
console.log('---Updated URLS---')
|
|
DNSList.unshift(...otherDNS)
|
|
for (let index = 0; index < streamArrays.length; index++) {
|
|
let element = streamArrays[index];
|
|
element.StreamURL = DNSList[index]
|
|
console.log(element.StreamName + ' ' + element.StreamURL)
|
|
}
|
|
writeFile(streamArrays)
|
|
console.log('---Updated URLS---')
|
|
return streamArrays
|
|
}
|
|
|
|
async function main() {
|
|
let requestData
|
|
let jointArray = []
|
|
for (let index = 0; index < DNSArray.length; index++) {
|
|
const url = DNSArray[index];
|
|
requestData = await gotRequest(url)
|
|
let DNSList = JSON.parse(requestData.body)
|
|
DNSList = splitToArray(DNSList.su)
|
|
DNSList.forEach(url => {
|
|
jointArray.push(url)
|
|
});
|
|
}
|
|
await mapToStream(jointArray)
|
|
return streamArrays
|
|
}
|
|
|
|
function arrayToTable(array) {
|
|
return tableify(array)
|
|
}
|
|
|
|
app.use(basicAuth({
|
|
users: { 'BBLBTV': 'BBLBTV' },
|
|
challenge: true,
|
|
realm: 'foo',
|
|
}))
|
|
|
|
app.get('/', async (req, res) => {
|
|
let fullStreamArray = await main()
|
|
let fullStreamHTML = await arrayToTable(fullStreamArray)
|
|
res.send(fullStreamHTML)
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`DNS Logger listening at http://localhost:${port}`)
|
|
})
|
|
|