2019-10-25 18:11:21 +00:00
|
|
|
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
|
|
|
|
|
2019-11-02 09:45:09 +00:00
|
|
|
const helper = require('../scripts/helper')
|
2019-10-25 18:11:21 +00:00
|
|
|
const ffmpeg = require('fluent-ffmpeg')
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-08-08 17:45:13 +00:00
|
|
|
const verbose = process.env.npm_config_debug || false
|
2018-12-22 19:07:47 +00:00
|
|
|
const errorLog = 'error.log'
|
2019-07-20 07:33:16 +00:00
|
|
|
const config = {
|
2019-10-30 14:50:43 +00:00
|
|
|
timeout: 10
|
2019-07-20 07:33:16 +00:00
|
|
|
}
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
let stats = {
|
|
|
|
tests: 0,
|
|
|
|
channels: 0,
|
|
|
|
failures: 0
|
|
|
|
}
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
async function test() {
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
stats.tests++
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-11-02 09:45:09 +00:00
|
|
|
const playlist = helper.parsePlaylist('index.m3u')
|
2019-08-07 20:59:44 +00:00
|
|
|
|
|
|
|
const countries = playlist.items
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2018-12-22 19:07:47 +00:00
|
|
|
for(let country of countries) {
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-11-02 09:45:09 +00:00
|
|
|
if (helper.skipPlaylist(country.url)) {
|
2019-08-12 12:34:42 +00:00
|
|
|
continue
|
2019-05-09 17:04:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 20:59:44 +00:00
|
|
|
console.log(`Checking '${country.url}'...`)
|
|
|
|
|
2019-11-02 09:45:09 +00:00
|
|
|
const playlist = helper.parsePlaylist(country.url)
|
2018-12-22 19:07:47 +00:00
|
|
|
|
2019-08-07 20:59:44 +00:00
|
|
|
for(let item of playlist.items) {
|
2018-12-22 19:07:47 +00:00
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
stats.channels++
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-10-25 18:11:21 +00:00
|
|
|
if(verbose) {
|
|
|
|
console.log(`Checking '${item.url}'...`)
|
|
|
|
}
|
2018-12-22 19:07:47 +00:00
|
|
|
|
2019-10-25 18:11:21 +00:00
|
|
|
await new Promise(resolve => {
|
2019-10-27 11:42:01 +00:00
|
|
|
|
|
|
|
const timeout = setTimeout(() => {
|
2019-10-30 14:50:43 +00:00
|
|
|
|
2019-10-27 11:42:01 +00:00
|
|
|
resolve()
|
2019-10-30 14:50:43 +00:00
|
|
|
|
2019-10-27 11:42:01 +00:00
|
|
|
}, config.timeout * 1000)
|
|
|
|
|
2019-10-30 14:50:43 +00:00
|
|
|
ffmpeg(item.url, { timeout: 60 }).ffprobe((err) => {
|
2019-10-25 18:11:21 +00:00
|
|
|
|
|
|
|
if(err) {
|
2019-10-25 19:45:50 +00:00
|
|
|
const message = parseMessage(err, item.url)
|
2018-12-22 19:07:47 +00:00
|
|
|
|
2019-10-25 18:11:21 +00:00
|
|
|
stats.failures++
|
2018-12-22 19:07:47 +00:00
|
|
|
|
2019-10-25 18:11:21 +00:00
|
|
|
writeToLog(country.url, message, item.url)
|
|
|
|
}
|
2019-08-08 11:11:11 +00:00
|
|
|
|
2019-10-27 11:42:01 +00:00
|
|
|
clearTimeout(timeout)
|
|
|
|
|
2019-10-25 18:11:21 +00:00
|
|
|
resolve()
|
2018-12-22 19:07:47 +00:00
|
|
|
|
2019-10-25 18:11:21 +00:00
|
|
|
})
|
|
|
|
})
|
2018-12-22 19:07:47 +00:00
|
|
|
|
2018-11-15 23:41:15 +00:00
|
|
|
}
|
2018-12-22 19:07:47 +00:00
|
|
|
}
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
if(stats.failures === 0) {
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
console.log(`OK (${stats.tests} tests, ${stats.channels} channels)`)
|
2018-12-22 19:07:47 +00:00
|
|
|
|
|
|
|
} else {
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
console.log(`FAILURES! (${stats.tests} tests, ${stats.channels} channels, ${stats.failures} failures)`)
|
2018-11-15 23:41:15 +00:00
|
|
|
|
2019-09-07 15:24:59 +00:00
|
|
|
process.exit(1)
|
|
|
|
|
2018-12-22 19:07:47 +00:00
|
|
|
}
|
2018-11-15 23:41:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-26 19:41:17 +00:00
|
|
|
console.log('Test is running...')
|
|
|
|
|
2019-07-20 07:33:16 +00:00
|
|
|
test()
|
2019-08-07 20:59:44 +00:00
|
|
|
|
2019-08-08 00:32:27 +00:00
|
|
|
function writeToLog(country, msg, url) {
|
2019-08-07 20:59:44 +00:00
|
|
|
var now = new Date()
|
2019-08-08 00:32:27 +00:00
|
|
|
var line = `${country}: ${msg} '${url}'`
|
2019-11-02 09:45:09 +00:00
|
|
|
helper.appendToFile(errorLog, now.toISOString() + ' ' + line + '\n')
|
2019-10-25 18:11:21 +00:00
|
|
|
console.log(`${msg} '${url}'`)
|
2019-08-07 20:59:44 +00:00
|
|
|
}
|
2019-10-25 19:45:50 +00:00
|
|
|
|
|
|
|
function parseMessage(err, u) {
|
|
|
|
if(!err || !err.message) return
|
|
|
|
|
|
|
|
const msgArr = err.message.split('\n')
|
|
|
|
|
|
|
|
if(msgArr.length === 0) return
|
|
|
|
|
|
|
|
const line = msgArr.find(line => {
|
|
|
|
return line.indexOf(u) === 0
|
|
|
|
})
|
|
|
|
|
|
|
|
if(!line) return
|
|
|
|
|
|
|
|
return line.replace(`${u}: `, '')
|
|
|
|
}
|