Update format.ts
This commit is contained in:
@@ -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 <number>',
|
||||
'Batch size of streams to test concurrently',
|
||||
(value: string) => parseInt(value),
|
||||
os.cpus().length
|
||||
)
|
||||
.option('-x, --proxy <url>', 'Use the specified proxy')
|
||||
.option(
|
||||
'-t, --timeout <number>',
|
||||
'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(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user