From aae44c900413b98864949844ebd95ad69f4c62be Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 15 Aug 2022 02:22:40 +0300 Subject: [PATCH] Delete cleaner.js --- scripts/commands/playlist/cleaner.js | 90 ---------------------------- 1 file changed, 90 deletions(-) delete mode 100644 scripts/commands/playlist/cleaner.js diff --git a/scripts/commands/playlist/cleaner.js b/scripts/commands/playlist/cleaner.js deleted file mode 100644 index 3389f5208..000000000 --- a/scripts/commands/playlist/cleaner.js +++ /dev/null @@ -1,90 +0,0 @@ -const { file, parser, logger, checker, m3u } = require('../../core') -const { program } = require('commander') - -program - .argument('[filepath]', 'Path to file to validate') - .option('-t, --timeout ', 'Set timeout for each request', parser.parseNumber, 60000) - .option('-d, --delay ', 'Set delay for each request', parser.parseNumber, 0) - .option('--debug', 'Enable debug mode') - .parse(process.argv) - -const options = program.opts() - -async function main() { - const files = program.args.length ? program.args : await file.list('streams/*.m3u') - - 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) { - if (options.debug) logger.info(stream.url) - const [_, status] = stream.raw.match(/status="([a-z]+)"/) || [null, null] - stream.status = status - if (status === 'error' && /^(http|https)/.test(stream.url)) { - const result = await checkStream(stream) - const newStatus = parseStatus(result.error) - if (status === newStatus) { - stream.remove = true - logger.info(`removed "${stream.name}"`) - } - } - } - - const items = playlist.items - .filter(i => !i.remove) - .map(item => ({ - attrs: { - 'tvg-id': item.tvg.id, - status: item.status, - 'user-agent': item.http['user-agent'] || undefined - }, - title: item.name, - url: item.url, - vlcOpts: { - 'http-referrer': item.http.referrer || undefined, - 'http-user-agent': item.http['user-agent'] || undefined - } - })) - - if (before !== items.length) { - const output = m3u.create(items) - await file.create(filepath, output) - logger.info(`saved`) - } - } -} - -main() - -async function checkStream(item) { - const config = { - timeout: options.timeout, - delay: options.delay, - debug: options.debug - } - - const request = { - url: item.url, - http: { - referrer: item.http.referrer, - 'user-agent': item.http['user-agent'] - } - } - - return checker.check(request, config) -} - -function parseStatus(error) { - if (!error) return 'online' - - switch (error) { - case 'Operation timed out': - return 'timeout' - case 'Server returned 403 Forbidden (access denied)': - return 'blocked' - default: - return 'error' - } -}