Update format.js
This commit is contained in:
parent
cc8f7546f8
commit
c396092bbf
|
@ -25,15 +25,12 @@ const instance = axios.create({
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
let globalBuffer = []
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const playlists = parseIndex()
|
const playlists = parseIndex()
|
||||||
|
|
||||||
for (const playlist of playlists) {
|
for (const playlist of playlists) {
|
||||||
await loadPlaylist(playlist.url)
|
await loadPlaylist(playlist.url)
|
||||||
.then(addToBuffer)
|
.then(addToBuffer)
|
||||||
.then(removeDuplicates)
|
|
||||||
.then(sortChannels)
|
.then(sortChannels)
|
||||||
.then(filterChannels)
|
.then(filterChannels)
|
||||||
.then(detectResolution)
|
.then(detectResolution)
|
||||||
|
@ -41,15 +38,6 @@ async function main() {
|
||||||
.then(done)
|
.then(done)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (playlists.length) {
|
|
||||||
// await loadPlaylist('channels/unsorted.m3u')
|
|
||||||
// .then(removeUnsortedDuplicates)
|
|
||||||
// .then(filterChannels)
|
|
||||||
// .then(sortChannels)
|
|
||||||
// .then(savePlaylist)
|
|
||||||
// .then(done)
|
|
||||||
// }
|
|
||||||
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,13 +57,6 @@ async function loadPlaylist(url) {
|
||||||
return parser.parsePlaylist(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) {
|
async function sortChannels(playlist) {
|
||||||
console.info(` Sorting channels...`)
|
console.info(` Sorting channels...`)
|
||||||
playlist.channels = utils.sortBy(playlist.channels, ['name', 'url'])
|
playlist.channels = utils.sortBy(playlist.channels, ['name', 'url'])
|
||||||
|
@ -93,24 +74,6 @@ async function filterChannels(playlist) {
|
||||||
return 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) {
|
async function detectResolution(playlist) {
|
||||||
console.log(' Detecting resolution...')
|
console.log(' Detecting resolution...')
|
||||||
const bar = new ProgressBar(' Progress: [:bar] :current/:total (:percent) ', {
|
const bar = new ProgressBar(' Progress: [:bar] :current/:total (:percent) ', {
|
||||||
|
@ -158,30 +121,9 @@ function parseResolution(string) {
|
||||||
: undefined
|
: 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) {
|
async function savePlaylist(playlist) {
|
||||||
const original = utils.readFile(playlist.url)
|
const original = utils.readFile(playlist.url)
|
||||||
const output = playlist.toString(true)
|
const output = playlist.toString()
|
||||||
|
|
||||||
if (original === output) {
|
if (original === output) {
|
||||||
console.info(`No changes have been made.`)
|
console.info(`No changes have been made.`)
|
||||||
|
|
Loading…
Reference in New Issue