feat: add yt-dlp argument builder
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import path from 'path'
|
||||
import { config } from '../../config/app.config'
|
||||
|
||||
export type YtdlpParams = {
|
||||
url: string
|
||||
uuid: string
|
||||
format: string
|
||||
quality: string
|
||||
subtitles: boolean
|
||||
extraArgs: string | null
|
||||
}
|
||||
|
||||
export function buildYtdlpArgs(params: YtdlpParams): string[] {
|
||||
const { url, uuid, format, quality, subtitles, extraArgs } = params
|
||||
const outputTemplate = path.join(config.STORAGE_PATH, `${uuid}.%(ext)s`)
|
||||
|
||||
const args: string[] = ['--no-playlist', '-o', outputTemplate]
|
||||
|
||||
if (quality !== 'best') {
|
||||
const height = quality.replace('p', '')
|
||||
args.push('-f', `${format}[height<=?${height}]+bestaudio/best[height<=?${height}]`)
|
||||
}
|
||||
|
||||
if (subtitles) {
|
||||
args.push('--write-sub', '--sub-lang', 'fr,en')
|
||||
}
|
||||
|
||||
if (extraArgs) {
|
||||
try {
|
||||
const extra = JSON.parse(extraArgs) as string[]
|
||||
args.push(...extra)
|
||||
} catch {
|
||||
// malformed extraArgs — skip silently
|
||||
}
|
||||
}
|
||||
|
||||
args.push(url)
|
||||
return args
|
||||
}
|
||||
Reference in New Issue
Block a user