Update cleaner.js

This commit is contained in:
Aleksandr Statciuk 2022-03-11 18:38:30 +03:00
parent 31bc995a3e
commit bde30c0010

View File

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