From 08c5b93906f7899e938509dc82a35bfa75e93d8f Mon Sep 17 00:00:00 2001 From: freearhey Date: Wed, 7 Aug 2019 16:52:25 +0300 Subject: [PATCH] Updated to latest version util.js --- helpers/filter.js | 52 ++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/helpers/filter.js b/helpers/filter.js index 47a7eb85bd..374e12c904 100644 --- a/helpers/filter.js +++ b/helpers/filter.js @@ -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}`)