2019-07-20 09:33:16 +02:00
|
|
|
const util = require('../helpers/util')
|
2018-12-22 20:07:47 +01:00
|
|
|
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'
|
2019-07-20 09:33:16 +02:00
|
|
|
const config = {
|
|
|
|
timeout: 60000,
|
|
|
|
delay: 200
|
|
|
|
}
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
let stats = {
|
|
|
|
tests: 0,
|
|
|
|
channels: 0,
|
|
|
|
failures: 0
|
|
|
|
}
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
const http = axios.create({ timeout: config.timeout })
|
2018-12-22 20:07:47 +01:00
|
|
|
http.defaults.headers.common["User-Agent"] = "VLC/2.2.4 LibVLC/2.2.4"
|
|
|
|
|
2019-04-23 20:49:52 +02:00
|
|
|
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}'`
|
2019-07-20 09:33:16 +02:00
|
|
|
util.writeToFile(errorLog, now.toISOString() + ' ' + line + '\n')
|
2018-12-22 20:07:47 +01:00
|
|
|
console.log(line)
|
2018-11-16 00:41:15 +01:00
|
|
|
}
|
|
|
|
|
2019-05-09 19:04:18 +02:00
|
|
|
function skipPlaylist(filename) {
|
2019-07-07 03:26:05 +02:00
|
|
|
let test_country = process.env.npm_config_country
|
2019-05-09 19:04:18 +02:00
|
|
|
if (test_country && filename !== 'channels/' + test_country + '.m3u') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
async function test() {
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
stats.tests++
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
let countries = util.parsePlaylist('index.m3u')
|
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
|
|
|
|
2019-05-09 19:04:18 +02:00
|
|
|
if (skipPlaylist(country.file)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
const playlist = util.parsePlaylist(country.file)
|
2018-12-22 20:07:47 +01:00
|
|
|
|
|
|
|
for(let channel of playlist) {
|
|
|
|
|
2019-03-19 23:26:21 +01:00
|
|
|
await new Promise(resolve => {
|
2019-07-20 09:33:16 +02:00
|
|
|
setTimeout(resolve, config.delay)
|
2019-03-19 23:26:21 +01:00
|
|
|
})
|
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
stats.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) {
|
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
stats.failures++
|
2018-12-22 20:07:47 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
writeToLog('test', country.file, err.message, channel.file)
|
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
|
|
|
}
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
if(stats.failures === 0) {
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
console.log(`OK (${stats.tests} tests, ${stats.channels} channels)`)
|
2018-12-22 20:07:47 +01:00
|
|
|
|
|
|
|
} else {
|
2018-11-16 00:41:15 +01:00
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
console.log(`FAILURES! (${stats.tests} tests, ${stats.channels} channels, ${stats.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-26 20:41:17 +01:00
|
|
|
console.log('Test is running...')
|
|
|
|
|
2019-07-20 09:33:16 +02:00
|
|
|
test()
|