diff --git a/scripts/format.js b/scripts/format.js index 92243901c4..3a26b8990f 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -4,7 +4,7 @@ const config = { debug: process.env.npm_config_debug || false, country: process.env.npm_config_country, exclude: process.env.npm_config_exclude, - epg: process.env.npm_config_epg || false + epg: process.env.npm_config_epg || false, } let updated = 0 @@ -58,7 +58,7 @@ async function main() { function parseIndex() { const playlist = helper.parsePlaylist('index.m3u') - playlist.items = helper.filterPlaylists(playlist.items, config.country, config.exclude) + playlist.items = filterPlaylists(playlist.items, config.country, config.exclude) console.log(`Found ${playlist.items.length} playlist(s)`) @@ -68,7 +68,7 @@ function parseIndex() { function parsePlaylist(url) { const playlist = helper.parsePlaylist(url) - playlist.items = playlist.items.map(item => { + playlist.items = playlist.items.map((item) => { return helper.createChannel(item) }) @@ -88,7 +88,7 @@ function sortChannels(playlist) { function removeDuplicates(playlist) { let buffer = {} const channels = JSON.stringify(playlist.items) - playlist.items = playlist.items.filter(i => { + playlist.items = playlist.items.filter((i) => { let result = typeof buffer[i.url] === 'undefined' if (result) { @@ -165,4 +165,20 @@ function updatePlaylist(filepath, playlist) { console.log(`Playlist '${filepath}' has been updated`) } +function filterPlaylists(arr, include = '', exclude = '') { + if (include) { + const included = include.split(',').map((filename) => `channels/${filename}.m3u`) + + return arr.filter((i) => included.indexOf(i.url) > -1) + } + + if (exclude) { + const excluded = exclude.split(',').map((filename) => `channels/${filename}.m3u`) + + return arr.filter((i) => excluded.indexOf(i.url) === -1) + } + + return arr +} + main() diff --git a/scripts/helper.js b/scripts/helper.js index 255d4c7972..a0e63c0127 100644 --- a/scripts/helper.js +++ b/scripts/helper.js @@ -65,7 +65,7 @@ helper.parseEPG = async function (url) { return Promise.resolve({ url, - channels + channels, }) } @@ -76,9 +76,9 @@ helper.getEPG = function (url) { method: 'get', url: url, responseType: 'stream', - timeout: 60000 + timeout: 60000, }) - .then(res => { + .then((res) => { let stream if (/\.gz$/i.test(url)) { let gunzip = zlib.createGunzip() @@ -99,7 +99,7 @@ helper.getEPG = function (url) { reject(e) }) }) - .catch(e => { + .catch((e) => { reject(e) }) }) @@ -129,22 +129,6 @@ helper.getUrlPath = function (u) { return path.toLowerCase() } -helper.filterPlaylists = function (arr, include = '', exclude = '') { - if (include) { - const included = include.split(',').map(filename => `channels/${filename}.m3u`) - - return arr.filter(i => included.indexOf(i.url) > -1) - } - - if (exclude) { - const excluded = exclude.split(',').map(filename => `channels/${filename}.m3u`) - - return arr.filter(i => excluded.indexOf(i.url) === -1) - } - - return arr -} - helper.generateTable = function (data, options) { let output = '