Updated to latest version util.js

This commit is contained in:
freearhey 2019-08-07 16:52:25 +03:00
parent 34efa18658
commit 08c5b93906

View File

@ -7,50 +7,60 @@ const blacklist = [
'189.216.247.113', // not working streams '189.216.247.113', // not working streams
] ]
let stats = { let stats = {
total: 0, channels: 0,
removed: 0 removed: 0
} }
function init() { function init() {
let countries = util.parsePlaylist('index.m3u') console.log(`Parsing 'index.m3u'...`)
const playlist = util.parsePlaylist('index.m3u')
let countries = playlist.items
if(debug) { if(debug) {
countries = countries.slice(0, 2) console.log('Debug mode is turn on')
countries = countries.slice(0, 1)
} }
let channels = []
for(let country of countries) { for(let country of countries) {
console.log(`Parsing '${country.url}'...`)
const playlist = util.parsePlaylist(country.url)
const playlist = util.parsePlaylist(country.file) if(debug) {
console.log(`Creating channels list...`)
}
let channels = []
for(let item of playlist.items) {
for(let item of playlist) { const url = new URL(item.url)
const url = new URL(item.file)
const host = url.hostname const host = url.hostname
if(blacklist.indexOf(host) === -1) { if(blacklist.indexOf(host) === -1) {
channels.push(item) let channel = util.createChannel({
id: item.inf['tvg-id'],
name: item.inf['tvg-name'],
logo: item.inf['tvg-logo'],
group: item.inf['group-title'],
url: item.url,
title: item.inf.title
})
channels.push(channel)
} else { } else {
stats.removed += 1 stats.removed += 1
} }
} }
util.createFile(country.file, '#EXTM3U\n') console.log(`Updating '${country.url}'...`)
util.createFile(country.url, playlist.getHeader())
channels.forEach(item => { channels.forEach(channel => {
const data = '#EXTINF:' + item.title + '\n' + item.file + '\n' util.appendToFile(country.url, channel.toString())
util.writeToFile(country.file, data)
}) })
stats.total += channels.length stats.channels += channels.length
}
}
channels = [] console.log('Starting...')
}
}
init() init()
console.log(`Total: ${stats.total}. Removed: ${stats.removed}`) console.log(`Total: ${stats.channels}. Removed: ${stats.removed}`)