Small refactoring
This commit is contained in:
parent
39a12432d7
commit
c67426689b
@ -136,20 +136,6 @@ helper.filterPlaylists = function(arr, include = '', exclude = '') {
|
|||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.skipPlaylist = function(filename) {
|
|
||||||
let testCountry = process.env.npm_config_country
|
|
||||||
let excludeList = process.env.npm_config_exclude
|
|
||||||
let excludeCountries = excludeList ? excludeList.split(',') : []
|
|
||||||
|
|
||||||
if (testCountry && filename !== 'channels/' + testCountry + '.m3u') return true
|
|
||||||
|
|
||||||
for(const countryCode of excludeCountries) {
|
|
||||||
if (filename === 'channels/' + countryCode + '.m3u') return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
helper.generateTable = function(data, options) {
|
helper.generateTable = function(data, options) {
|
||||||
let output = '<table>\n'
|
let output = '<table>\n'
|
||||||
|
|
||||||
@ -191,6 +177,28 @@ helper.createChannel = function(data) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helper.writeToLog = function(country, msg, url) {
|
||||||
|
var now = new Date()
|
||||||
|
var line = `${country}: ${msg} '${url}'`
|
||||||
|
this.appendToFile('error.log', now.toISOString() + ' ' + line + '\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.parseMessage = function(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}: `, '')
|
||||||
|
}
|
||||||
|
|
||||||
class Playlist {
|
class Playlist {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
this.header = data.header
|
this.header = data.header
|
||||||
|
@ -3,33 +3,30 @@ process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
|
|||||||
const helper = require('./helper')
|
const helper = require('./helper')
|
||||||
const ffmpeg = require('fluent-ffmpeg')
|
const ffmpeg = require('fluent-ffmpeg')
|
||||||
|
|
||||||
const verbose = process.env.npm_config_debug || false
|
|
||||||
const errorLog = 'error.log'
|
|
||||||
const config = {
|
const config = {
|
||||||
|
debug: process.env.npm_config_debug || false,
|
||||||
|
country: process.env.npm_config_country,
|
||||||
|
exclude: process.env.npm_config_exclude,
|
||||||
timeout: 10
|
timeout: 10
|
||||||
}
|
}
|
||||||
|
|
||||||
let stats = {
|
let stats = {
|
||||||
tests: 0,
|
playlists: 0,
|
||||||
channels: 0,
|
channels: 0,
|
||||||
failures: 0
|
failures: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
async function test() {
|
async function test() {
|
||||||
|
|
||||||
stats.tests++
|
|
||||||
|
|
||||||
const playlist = helper.parsePlaylist('index.m3u')
|
const playlist = helper.parsePlaylist('index.m3u')
|
||||||
|
|
||||||
const countries = playlist.items
|
const countries = helper.filterPlaylists(playlist.items, config.country, config.exclude)
|
||||||
|
|
||||||
for(let country of countries) {
|
for(let country of countries) {
|
||||||
|
|
||||||
if (helper.skipPlaylist(country.url)) {
|
stats.playlists++
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Checking '${country.url}'...`)
|
console.log(`Processing '${country.url}'...`)
|
||||||
|
|
||||||
const playlist = helper.parsePlaylist(country.url)
|
const playlist = helper.parsePlaylist(country.url)
|
||||||
|
|
||||||
@ -37,9 +34,7 @@ async function test() {
|
|||||||
|
|
||||||
stats.channels++
|
stats.channels++
|
||||||
|
|
||||||
if(verbose) {
|
if(config.debug) { console.log(`Checking '${item.url}'...`) }
|
||||||
console.log(`Checking '${item.url}'...`)
|
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
|
|
||||||
@ -52,11 +47,13 @@ async function test() {
|
|||||||
ffmpeg(item.url, { timeout: 60 }).ffprobe((err) => {
|
ffmpeg(item.url, { timeout: 60 }).ffprobe((err) => {
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
const message = parseMessage(err, item.url)
|
const message = helper.parseMessage(err, item.url)
|
||||||
|
|
||||||
stats.failures++
|
stats.failures++
|
||||||
|
|
||||||
writeToLog(country.url, message, item.url)
|
helper.writeToLog(country.url, message, item.url)
|
||||||
|
|
||||||
|
console.log(`${message} '${item.url}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
@ -71,11 +68,11 @@ async function test() {
|
|||||||
|
|
||||||
if(stats.failures === 0) {
|
if(stats.failures === 0) {
|
||||||
|
|
||||||
console.log(`OK (${stats.tests} tests, ${stats.channels} channels)`)
|
console.log(`OK (${stats.playlists} playlists, ${stats.channels} channels)`)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
console.log(`FAILURES! (${stats.tests} tests, ${stats.channels} channels, ${stats.failures} failures)`)
|
console.log(`FAILURES! (${stats.playlists} playlists, ${stats.channels} channels, ${stats.failures} failures)`)
|
||||||
|
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
|
||||||
@ -86,26 +83,3 @@ async function test() {
|
|||||||
console.log('Test is running...')
|
console.log('Test is running...')
|
||||||
|
|
||||||
test()
|
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…
x
Reference in New Issue
Block a user