From c396092bbf235d7453b0724b137b7e30507f73c4 Mon Sep 17 00:00:00 2001 From: freearhey Date: Thu, 6 May 2021 16:25:00 +0300 Subject: [PATCH] Update format.js --- scripts/format.js | 60 +---------------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/scripts/format.js b/scripts/format.js index 43e328352e..f0d29aa3f3 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -25,15 +25,12 @@ const instance = axios.create({ }) }) -let globalBuffer = [] - async function main() { const playlists = parseIndex() for (const playlist of playlists) { await loadPlaylist(playlist.url) .then(addToBuffer) - .then(removeDuplicates) .then(sortChannels) .then(filterChannels) .then(detectResolution) @@ -41,15 +38,6 @@ async function main() { .then(done) } - // if (playlists.length) { - // await loadPlaylist('channels/unsorted.m3u') - // .then(removeUnsortedDuplicates) - // .then(filterChannels) - // .then(sortChannels) - // .then(savePlaylist) - // .then(done) - // } - finish() } @@ -69,13 +57,6 @@ async function loadPlaylist(url) { return parser.parsePlaylist(url) } -async function addToBuffer(playlist) { - if (playlist.url === 'channels/unsorted.m3u') return playlist - globalBuffer = globalBuffer.concat(playlist.channels) - - return playlist -} - async function sortChannels(playlist) { console.info(` Sorting channels...`) playlist.channels = utils.sortBy(playlist.channels, ['name', 'url']) @@ -93,24 +74,6 @@ async function filterChannels(playlist) { return playlist } -async function removeDuplicates(playlist) { - console.info(` Looking for duplicates...`) - let buffer = {} - const channels = playlist.channels.filter(i => { - const url = utils.removeProtocol(i.url) - const result = typeof buffer[url] === 'undefined' - if (result) { - buffer[url] = true - } - - return result - }) - - playlist.channels = channels - - return playlist -} - async function detectResolution(playlist) { console.log(' Detecting resolution...') const bar = new ProgressBar(' Progress: [:bar] :current/:total (:percent) ', { @@ -158,30 +121,9 @@ function parseResolution(string) { : undefined } -async function removeUnsortedDuplicates(playlist) { - console.info(` Looking for duplicates...`) - // locally - let buffer = {} - let channels = playlist.channels.filter(i => { - const url = utils.removeProtocol(i.url) - const result = typeof buffer[url] === 'undefined' - if (result) buffer[url] = true - - return result - }) - // globally - const urls = globalBuffer.map(i => utils.removeProtocol(i.url)) - channels = channels.filter(i => !urls.includes(utils.removeProtocol(i.url))) - if (channels.length === playlist.channels.length) return playlist - - playlist.channels = channels - - return playlist -} - async function savePlaylist(playlist) { const original = utils.readFile(playlist.url) - const output = playlist.toString(true) + const output = playlist.toString() if (original === output) { console.info(`No changes have been made.`)