iptv/helpers/filter.js

67 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-07-22 16:57:53 +02:00
const util = require('./util')
const debug = false
const blacklist = [
'80.80.160.168', // repeats on a loop
2019-08-03 15:09:09 +02:00
'63.237.48.3', // not a live stream
'189.216.247.113', // not working streams
2019-07-22 16:57:53 +02:00
]
let stats = {
2019-08-07 15:52:25 +02:00
channels: 0,
2019-07-22 16:57:53 +02:00
removed: 0
}
function init() {
2019-08-07 15:52:25 +02:00
console.log(`Parsing 'index.m3u'...`)
const playlist = util.parsePlaylist('index.m3u')
let countries = playlist.items
2019-07-22 16:57:53 +02:00
if(debug) {
2019-08-07 15:52:25 +02:00
console.log('Debug mode is turn on')
countries = countries.slice(0, 1)
2019-07-22 16:57:53 +02:00
}
for(let country of countries) {
2019-08-07 15:52:25 +02:00
console.log(`Parsing '${country.url}'...`)
const playlist = util.parsePlaylist(country.url)
2019-07-22 16:57:53 +02:00
2019-08-07 15:52:25 +02:00
if(debug) {
console.log(`Creating channels list...`)
}
let channels = []
for(let item of playlist.items) {
2019-07-22 16:57:53 +02:00
2019-08-07 15:52:25 +02:00
const url = new URL(item.url)
2019-07-22 16:57:53 +02:00
const host = url.hostname
if(blacklist.indexOf(host) === -1) {
2019-08-07 15:52:25 +02:00
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)
2019-07-22 16:57:53 +02:00
} else {
stats.removed += 1
}
}
2019-08-07 15:52:25 +02:00
console.log(`Updating '${country.url}'...`)
util.createFile(country.url, playlist.getHeader())
channels.forEach(channel => {
util.appendToFile(country.url, channel.toString())
2019-07-22 16:57:53 +02:00
})
2019-08-07 15:52:25 +02:00
stats.channels += channels.length
2019-07-22 16:57:53 +02:00
}
}
2019-08-07 15:52:25 +02:00
console.log('Starting...')
2019-07-22 16:57:53 +02:00
init()
2019-08-07 15:52:25 +02:00
console.log(`Total: ${stats.channels}. Removed: ${stats.removed}`)