From 81a822ade2c894c1786dc0fcfbe36d147a550881 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Wed, 25 Mar 2026 12:20:21 +0300 Subject: [PATCH] Update format.ts --- scripts/commands/playlist/format.ts | 52 +++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/scripts/commands/playlist/format.ts b/scripts/commands/playlist/format.ts index 15b4bc017..442b1cdf2 100644 --- a/scripts/commands/playlist/format.ts +++ b/scripts/commands/playlist/format.ts @@ -1,13 +1,34 @@ import { Collection, Logger } from '@freearhey/core' +import { OptionValues, program } from 'commander' import { Stream, Playlist } from '../../models' import { Storage } from '@freearhey/storage-js' import { STREAMS_DIR } from '../../constants' import { PlaylistParser } from '../../core' +import { getStreamInfo } from '../../utils' +import cliProgress from 'cli-progress' import { loadData } from '../../api' -import { program } from 'commander' +import { eachLimit } from 'async' import path from 'node:path' +import os from 'node:os' -program.argument('[filepath...]', 'Path to file to format').parse(process.argv) +program + .argument('[filepath...]', 'Path to file to format') + .option( + '-p, --parallel ', + 'Batch size of streams to test concurrently', + (value: string) => parseInt(value), + os.cpus().length + ) + .option('-x, --proxy ', 'Use the specified proxy') + .option( + '-t, --timeout ', + 'The number of milliseconds before the request will be aborted', + (value: string) => parseInt(value), + 1000 + ) + .parse(process.argv) + +const options: OptionValues = program.opts() async function main() { const logger = new Logger() @@ -58,6 +79,33 @@ async function main() { return stream }) + logger.info('adding the missing quality...') + const progressBar = new cliProgress.SingleBar({ + clearOnComplete: true, + format: `[{bar}] {percentage}% | {value}/{total}` + }) + progressBar.start(streams.count(), 0) + await eachLimit(streams.all(), options.parallel, async (stream: Stream) => { + progressBar.increment() + if (stream.quality) return + + const streamInfo = await getStreamInfo(stream.url, { + httpUserAgent: stream.user_agent, + httpReferrer: stream.referrer, + timeout: options.timeout, + proxy: options.proxy + }) + + if (streamInfo) { + const height = streamInfo?.resolution?.height + + if (height) { + stream.quality = `${height}p` + } + } + }) + progressBar.stop() + logger.info('sorting links...') streams = streams.sortBy( [