iptv/scripts/test.js

86 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-10-25 20:11:21 +02:00
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
2019-11-02 12:10:57 +01:00
const helper = require('./helper')
2019-10-25 20:11:21 +02:00
const ffmpeg = require('fluent-ffmpeg')
2018-11-16 00:41:15 +01:00
2019-07-20 09:33:16 +02:00
const config = {
2019-11-03 18:21:35 +01:00
debug: process.env.npm_config_debug || false,
country: process.env.npm_config_country,
exclude: process.env.npm_config_exclude,
2019-10-30 15:50:43 +01:00
timeout: 10
2019-07-20 09:33:16 +02:00
}
2018-11-16 00:41:15 +01:00
2019-07-20 09:33:16 +02:00
let stats = {
2019-11-03 18:21:35 +01:00
playlists: 0,
2019-07-20 09:33:16 +02:00
channels: 0,
failures: 0
}
2018-11-16 00:41:15 +01:00
2019-07-20 09:33:16 +02:00
async function test() {
2018-11-16 00:41:15 +01:00
2019-11-02 10:45:09 +01:00
const playlist = helper.parsePlaylist('index.m3u')
2019-08-07 22:59:44 +02:00
2019-11-03 18:21:35 +01:00
const countries = helper.filterPlaylists(playlist.items, config.country, config.exclude)
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-11-03 18:21:35 +01:00
stats.playlists++
2019-11-03 18:21:35 +01:00
console.log(`Processing '${country.url}'...`)
2019-08-07 22:59:44 +02:00
2019-11-02 10:45:09 +01:00
const playlist = helper.parsePlaylist(country.url)
2018-12-22 20:07:47 +01:00
2019-08-07 22:59:44 +02:00
for(let item of playlist.items) {
2018-12-22 20:07:47 +01:00
2019-07-20 09:33:16 +02:00
stats.channels++
2018-11-16 00:41:15 +01:00
2019-11-03 18:21:35 +01:00
if(config.debug) { console.log(`Checking '${item.url}'...`) }
2018-12-22 20:07:47 +01:00
2019-10-25 20:11:21 +02:00
await new Promise(resolve => {
2019-10-27 12:42:01 +01:00
const timeout = setTimeout(() => {
2019-10-30 15:50:43 +01:00
2019-10-27 12:42:01 +01:00
resolve()
2019-10-30 15:50:43 +01:00
2019-10-27 12:42:01 +01:00
}, config.timeout * 1000)
2019-10-30 15:50:43 +01:00
ffmpeg(item.url, { timeout: 60 }).ffprobe((err) => {
2019-10-25 20:11:21 +02:00
if(err) {
2019-11-03 18:21:35 +01:00
const message = helper.parseMessage(err, item.url)
2018-12-22 20:07:47 +01:00
2019-10-25 20:11:21 +02:00
stats.failures++
2018-12-22 20:07:47 +01:00
2019-11-03 18:21:35 +01:00
helper.writeToLog(country.url, message, item.url)
console.log(`${message} '${item.url}'`)
2019-10-25 20:11:21 +02:00
}
2019-08-08 13:11:11 +02:00
2019-10-27 12:42:01 +01:00
clearTimeout(timeout)
2019-10-25 20:11:21 +02:00
resolve()
2018-12-22 20:07:47 +01:00
2019-10-25 20:11:21 +02: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-11-03 18:21:35 +01:00
console.log(`OK (${stats.playlists} playlists, ${stats.channels} channels)`)
2018-12-22 20:07:47 +01:00
} else {
2018-11-16 00:41:15 +01:00
2019-11-03 18:21:35 +01:00
console.log(`FAILURES! (${stats.playlists} playlists, ${stats.channels} channels, ${stats.failures} failures)`)
2018-11-16 00:41:15 +01:00
2019-09-07 17:24:59 +02:00
process.exit(1)
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()