2018-12-22 20:07:47 +01:00
|
|
|
const parsers = require('playlist-parser');
|
|
|
|
const M3U = parsers.M3U;
|
|
|
|
const fs = require("fs");
|
|
|
|
const axios = require('axios')
|
|
|
|
const path = require('path')
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
const errorLog = 'error.log'
|
|
|
|
const timeout = 10000
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
let tests = 0
|
|
|
|
let channels = 0
|
|
|
|
let failures = 0
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
const http = axios.create({ timeout })
|
|
|
|
http.defaults.headers.common["User-Agent"] = "VLC/2.2.4 LibVLC/2.2.4"
|
|
|
|
|
|
|
|
function _writeToLog(test, country, msg, url) {
|
2018-11-16 00:41:15 +01:00
|
|
|
var now = new Date()
|
2018-12-22 20:07:47 +01:00
|
|
|
var line = `${test}(): ${country}: ${msg} '${url}'`
|
|
|
|
fs.appendFileSync(path.resolve(__dirname) + '/../' + errorLog, now.toISOString() + ' ' + line + '\n')
|
|
|
|
console.log(line)
|
2018-11-16 00:41:15 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
function _loadPlaylist(filename) {
|
|
|
|
return M3U.parse(fs.readFileSync(path.resolve(__dirname) + "/../" + filename, { encoding: "utf8" }))
|
|
|
|
}
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
async function testAllLinksIsWorking() {
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
tests++
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
let countries = _loadPlaylist('index.m3u')
|
|
|
|
// countries = countries.slice(0, 2)
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
for(let country of countries) {
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
const playlist = _loadPlaylist(country.file)
|
|
|
|
|
|
|
|
for(let channel of playlist) {
|
|
|
|
|
|
|
|
channels++
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-11-16 04:46:05 +01:00
|
|
|
try {
|
2018-12-22 20:07:47 +01:00
|
|
|
|
|
|
|
await http.get(channel.file)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
failures++
|
|
|
|
|
|
|
|
_writeToLog('testAllLinksIsWorking', country.file, err.message, channel.file)
|
|
|
|
|
2018-11-16 00:41:15 +01:00
|
|
|
}
|
2018-12-22 20:07:47 +01:00
|
|
|
|
2018-11-16 00:41:15 +01:00
|
|
|
}
|
2018-12-22 20:07:47 +01:00
|
|
|
}
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
if(failures === 0) {
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
console.log(`OK (${tests} tests, ${channels} channels)`)
|
|
|
|
|
|
|
|
} else {
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 22:04:15 +01:00
|
|
|
console.log(`FAILURES! (${tests} tests, ${channels} channels, ${failures} failures)`)
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
}
|
2018-11-16 00:41:15 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-22 20:07:47 +01:00
|
|
|
testAllLinksIsWorking()
|