Add custom http User-Agent and make code prettier

This commit is contained in:
freearhey 2020-04-11 03:54:32 +03:00
parent 07a6ac151f
commit 5ad89cf008
1 changed files with 24 additions and 31 deletions

View File

@ -17,67 +17,60 @@ let stats = {
} }
async function test() { async function test() {
const playlist = helper.parsePlaylist('index.m3u') const playlist = helper.parsePlaylist('index.m3u')
const countries = helper.filterPlaylists(playlist.items, config.country, config.exclude) const countries = helper.filterPlaylists(playlist.items, config.country, config.exclude)
for(let country of countries) { for (let country of countries) {
stats.playlists++ stats.playlists++
console.log(`Processing '${country.url}'...`) console.log(`Processing '${country.url}'...`)
const playlist = helper.parsePlaylist(country.url) const playlist = helper.parsePlaylist(country.url)
for(let item of playlist.items) { for (let item of playlist.items) {
stats.channels++ stats.channels++
if(config.debug) { console.log(`Checking '${item.url}'...`) } if (config.debug) {
console.log(`Checking '${item.url}'...`)
}
await new Promise(resolve => { await new Promise(resolve => {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
resolve() resolve()
}, config.timeout * 1000) }, config.timeout * 1000)
ffmpeg(item.url, { timeout: 60 }).ffprobe((err) => { ffmpeg(item.url, { timeout: 60 }).ffprobe(
['-user_agent', `"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"`],
if(err) { err => {
const message = helper.parseMessage(err, item.url) if (err) {
const message = helper.parseMessage(err, item.url)
stats.failures++ stats.failures++
helper.writeToLog(country.url, message, item.url) helper.writeToLog(country.url, message, item.url)
console.log(`${message} '${item.url}'`) console.log(`${message} '${item.url}'`)
}
clearTimeout(timeout)
resolve()
} }
)
clearTimeout(timeout)
resolve()
})
}) })
} }
} }
if(stats.failures === 0) { if (stats.failures === 0) {
console.log(`OK (${stats.playlists} playlists, ${stats.channels} channels)`) console.log(`OK (${stats.playlists} playlists, ${stats.channels} channels)`)
} else { } else {
console.log(
console.log(`FAILURES! (${stats.playlists} playlists, ${stats.channels} channels, ${stats.failures} failures)`) `FAILURES! (${stats.playlists} playlists, ${stats.channels} channels, ${stats.failures} failures)`
)
process.exit(1) process.exit(1)
} }
} }
console.log('Test is running...') console.log('Test is running...')