Update format.js

Remove duplicates inside unsorted.m3u itself
This commit is contained in:
freearhey 2021-03-27 15:09:13 +03:00
parent e41f2e65e4
commit bd7c6dae49
1 changed files with 14 additions and 3 deletions

View File

@ -98,7 +98,7 @@ async function removeDuplicates(playlist) {
console.info(` Looking for duplicates...`) console.info(` Looking for duplicates...`)
let buffer = {} let buffer = {}
const channels = playlist.channels.filter(i => { const channels = playlist.channels.filter(i => {
const url = i.url.replace(/(^\w+:|^)\/\//, '') const url = utils.removeProtocol(i.url)
const result = typeof buffer[url] === 'undefined' const result = typeof buffer[url] === 'undefined'
if (result) { if (result) {
buffer[url] = true buffer[url] = true
@ -161,9 +161,20 @@ function parseResolution(string) {
async function removeUnsortedDuplicates(playlist) { async function removeUnsortedDuplicates(playlist) {
console.info(` Looking for duplicates...`) console.info(` Looking for duplicates...`)
const urls = globalBuffer.map(i => i.url.replace(/(^\w+:|^)\/\//, '')) // locally
const channels = playlist.channels.filter(i => !urls.includes(i.url.replace(/(^\w+:|^)\/\//, ''))) 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 if (channels.length === playlist.channels.length) return playlist
playlist.channels = channels playlist.channels = channels
return playlist return playlist