59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
![]() |
const got = require('got')
|
||
|
fs = require('fs');
|
||
|
|
||
|
|
||
|
const url = "http://webservgroup.xyz/smarters4567891/api/home.php?action=dns"
|
||
|
|
||
|
var streamArrays = require('./streamArray.json')
|
||
|
|
||
|
const gotRequest = async (url) => {
|
||
|
|
||
|
let returnResponse = {};
|
||
|
let options = {}
|
||
|
await got(url, options)
|
||
|
.then((response) => {
|
||
|
returnResponse = response;
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
returnResponse = typeof error.response !== 'undefined' ? error.response : error;
|
||
|
|
||
|
if (typeof returnResponse.body === 'string' && returnResponse.body.substring(0, 1) === '{') {
|
||
|
returnResponse.body = JSON.parse(returnResponse.body);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return returnResponse;
|
||
|
};
|
||
|
|
||
|
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---')
|
||
|
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(url) {
|
||
|
const t = await gotRequest(url)
|
||
|
let DNSList = JSON.parse(t.body)
|
||
|
DNSList = splitToArray(DNSList.su)
|
||
|
await mapToStream(DNSList)
|
||
|
}
|
||
|
|
||
|
main(url)
|