Updated to latest version util.js

This commit is contained in:
freearhey 2019-08-07 16:52:25 +03:00
parent 34efa18658
commit 08c5b93906
1 changed files with 31 additions and 21 deletions

View File

@ -7,50 +7,60 @@ const blacklist = [
'189.216.247.113', // not working streams
]
let stats = {
total: 0,
channels: 0,
removed: 0
}
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) {
countries = countries.slice(0, 2)
console.log('Debug mode is turn on')
countries = countries.slice(0, 1)
}
let channels = []
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.file)
const url = new URL(item.url)
const host = url.hostname
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 {
stats.removed += 1
}
}
util.createFile(country.file, '#EXTM3U\n')
channels.forEach(item => {
const data = '#EXTINF:' + item.title + '\n' + item.file + '\n'
util.writeToFile(country.file, data)
console.log(`Updating '${country.url}'...`)
util.createFile(country.url, playlist.getHeader())
channels.forEach(channel => {
util.appendToFile(country.url, channel.toString())
})
stats.total += channels.length
channels = []
stats.channels += channels.length
}
}
console.log('Starting...')
init()
console.log(`Total: ${stats.total}. Removed: ${stats.removed}`)
console.log(`Total: ${stats.channels}. Removed: ${stats.removed}`)