mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-15 11:30:04 -04:00
Move test script to /scripts
This commit is contained in:
parent
5f3faef290
commit
24755101b2
2 changed files with 2 additions and 2 deletions
111
scripts/test.js
Normal file
111
scripts/test.js
Normal file
|
@ -0,0 +1,111 @@
|
|||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
|
||||
|
||||
const helper = require('./helper')
|
||||
const ffmpeg = require('fluent-ffmpeg')
|
||||
|
||||
const verbose = process.env.npm_config_debug || false
|
||||
const errorLog = 'error.log'
|
||||
const config = {
|
||||
timeout: 10
|
||||
}
|
||||
|
||||
let stats = {
|
||||
tests: 0,
|
||||
channels: 0,
|
||||
failures: 0
|
||||
}
|
||||
|
||||
async function test() {
|
||||
|
||||
stats.tests++
|
||||
|
||||
const playlist = helper.parsePlaylist('index.m3u')
|
||||
|
||||
const countries = playlist.items
|
||||
|
||||
for(let country of countries) {
|
||||
|
||||
if (helper.skipPlaylist(country.url)) {
|
||||
continue
|
||||
}
|
||||
|
||||
console.log(`Checking '${country.url}'...`)
|
||||
|
||||
const playlist = helper.parsePlaylist(country.url)
|
||||
|
||||
for(let item of playlist.items) {
|
||||
|
||||
stats.channels++
|
||||
|
||||
if(verbose) {
|
||||
console.log(`Checking '${item.url}'...`)
|
||||
}
|
||||
|
||||
await new Promise(resolve => {
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
|
||||
resolve()
|
||||
|
||||
}, config.timeout * 1000)
|
||||
|
||||
ffmpeg(item.url, { timeout: 60 }).ffprobe((err) => {
|
||||
|
||||
if(err) {
|
||||
const message = parseMessage(err, item.url)
|
||||
|
||||
stats.failures++
|
||||
|
||||
writeToLog(country.url, message, item.url)
|
||||
}
|
||||
|
||||
clearTimeout(timeout)
|
||||
|
||||
resolve()
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(stats.failures === 0) {
|
||||
|
||||
console.log(`OK (${stats.tests} tests, ${stats.channels} channels)`)
|
||||
|
||||
} else {
|
||||
|
||||
console.log(`FAILURES! (${stats.tests} tests, ${stats.channels} channels, ${stats.failures} failures)`)
|
||||
|
||||
process.exit(1)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
console.log('Test is running...')
|
||||
|
||||
test()
|
||||
|
||||
function writeToLog(country, msg, url) {
|
||||
var now = new Date()
|
||||
var line = `${country}: ${msg} '${url}'`
|
||||
helper.appendToFile(errorLog, now.toISOString() + ' ' + line + '\n')
|
||||
console.log(`${msg} '${url}'`)
|
||||
}
|
||||
|
||||
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}: `, '')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue