feat: add yt-dlp argument builder

This commit is contained in:
2026-08-10 14:31:43 +02:00
parent 4766bb3a18
commit ab9235fe57
2 changed files with 102 additions and 0 deletions
+39
View File
@@ -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
}