| 56 | const rootStorage = new Storage(ROOT_DIR) |
| 57 | |
| 58 | async function main() { |
| 59 | if (await isOffline()) { |
| 60 | logger.error(chalk.red('Internet connection is required for the script to work')) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | logger.info('loading data from api...') |
| 65 | await loadData() |
| 66 | |
| 67 | logger.info('loading streams...') |
| 68 | const parser = new PlaylistParser({ |
| 69 | storage: rootStorage |
| 70 | }) |
| 71 | const files = program.args.length ? program.args : await rootStorage.list(`${STREAMS_DIR}/*.m3u`) |
| 72 | streams = await parser.parse(files) |
| 73 | |
| 74 | logger.info(`found ${streams.count()} streams`) |
| 75 | if (streams.count() > LIVE_UPDATE_MAX_STREAMS) isLiveUpdateEnabled = false |
| 76 | |
| 77 | logger.info('starting...') |
| 78 | if (!isLiveUpdateEnabled) { |
| 79 | drawTable() |
| 80 | interval = setInterval(() => { |
| 81 | drawTable() |
| 82 | }, LIVE_UPDATE_INTERVAL) |
| 83 | } |
| 84 | |
| 85 | eachLimit( |
| 86 | streams.all(), |
| 87 | options.parallel, |
| 88 | async (stream: Stream) => { |
| 89 | await runTest(stream) |
| 90 | |
| 91 | if (isLiveUpdateEnabled) { |
| 92 | drawTable() |
| 93 | } |
| 94 | }, |
| 95 | onFinish |
| 96 | ) |
| 97 | } |
| 98 | |
| 99 | main() |
| 100 | |