Added filter of unsorted channels

This commit is contained in:
freearhey 2020-04-22 16:41:54 +03:00
parent 855061bf29
commit 97b507b65f
1 changed files with 20 additions and 1 deletions

View File

@ -8,6 +8,7 @@ const config = {
}
let updated = 0
let items = []
async function main() {
console.log(`Parsing index...`)
@ -16,10 +17,13 @@ async function main() {
for (let item of index.items) {
console.log(`Processing '${item.url}'...`)
let playlist = parsePlaylist(item.url)
items = items.concat(playlist.items)
if (config.debug) {
console.log(`Sorting channels...`)
}
playlist = sortChannels(playlist)
if (config.debug) {
console.log(`Removing duplicates...`)
}
@ -51,6 +55,9 @@ async function main() {
}
}
console.log(`Processing 'channels/unsorted.m3u'...`)
filterUnsorted()
console.log(`Updated ${updated} playlist(s)`)
console.log('Done.\n')
@ -60,7 +67,7 @@ function parseIndex() {
const playlist = helper.parsePlaylist('index.m3u')
playlist.items = filterPlaylists(playlist.items, config.country, config.exclude)
console.log(`Found ${playlist.items.length} playlist(s)`)
console.log(`Found ${playlist.items.length + 1} playlist(s)`)
return playlist
}
@ -181,4 +188,16 @@ function filterPlaylists(arr, include = '', exclude = '') {
return arr
}
function filterUnsorted() {
const urls = items.map((i) => i.url)
const unsortedPlaylist = parsePlaylist('channels/unsorted.m3u')
const before = unsortedPlaylist.items.length
unsortedPlaylist.items = unsortedPlaylist.items.filter((i) => !urls.includes(i.url))
if (before !== unsortedPlaylist.items.length) {
updatePlaylist('channels/unsorted.m3u', unsortedPlaylist)
updated++
}
}
main()