Update cleaner.js

This commit is contained in:
Aleksandr Statciuk 2022-03-11 18:38:30 +03:00
parent 31bc995a3e
commit bde30c0010
1 changed files with 8 additions and 2 deletions

View File

@ -13,7 +13,9 @@ async function main() {
for (const filepath of files) {
if (!filepath.endsWith('.m3u')) continue
logger.info(`${filepath}`)
const playlist = await parser.parsePlaylist(filepath)
const before = playlist.items.length
for (const stream of playlist.items) {
const [_, status] = stream.raw.match(/status="([a-z]+)"/) || [null, null]
stream.status = status
@ -22,6 +24,7 @@ async function main() {
const newStatus = parseStatus(result.error)
if (status === newStatus) {
stream.remove = true
logger.info(`removed "${stream.name}"`)
}
}
}
@ -42,8 +45,11 @@ async function main() {
}
}))
const output = m3u.create(items)
await file.create(filepath, output)
if (before !== items.length) {
const output = m3u.create(items)
await file.create(filepath, output)
logger.info(`saved`)
}
}
}