From 92bcc70728a0de6470e9e51a30409ddb903b3b3d Mon Sep 17 00:00:00 2001 From: devsavsis Date: Sun, 30 Aug 2026 18:26:18 +0500 Subject: [PATCH] fix: download args, show error, uploader fallback --- bm.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/bm.js b/bm.js index f55da61..060797b 100644 --- a/bm.js +++ b/bm.js @@ -206,18 +206,19 @@ function doDownload(url, fmtIdx, retry403 = false) { const isSpotify = url.includes('spotify.com') const ffmpegDir = path.dirname(FFMPEG) - let args = [url, '--no-playlist', '--continue', '--ffmpeg-location', ffmpegDir, '--newline', '--no-colors'] + let args = [url, '--no-playlist', '--continue', '--ffmpeg-location', ffmpegDir, '--newline', '--progress'] if (isVideo) { - args.push('-f', 'bestvideo[height<=1080]+bestaudio/best', '-o', `${OUT_DIR}\\%(title)s.%(ext)s`, '--merge-output-format', 'mp4') + args.push('-f', 'bestvideo[height<=1080]+bestaudio/best', + '-o', `${OUT_DIR}\\%(title)s.%(ext)s`, + '--merge-output-format', 'mp4') } else { const audioFmt = { FLAC:'flac', WAV:'wav', MP3:'mp3', OPUS:'opus' }[fmt] || 'flac' args.push('-x', '--audio-format', audioFmt, '--audio-quality', '0', - '-o', `${OUT_DIR}\\%(uploader)s - %(title)s.%(ext)s`, - '--embed-thumbnail', '--embed-metadata', '--add-metadata') + '-o', `${OUT_DIR}\\%(uploader,channel|Unknown)s - %(title)s.%(ext)s`, + '--embed-metadata', '--embed-thumbnail') if (!isApple && !isSpotify) { - args.push('--extractor-args', 'youtube:player_client=web_creator,web', - '--user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36') + args.push('--extractor-args', 'youtube:player_client=web_creator,web') } } @@ -228,6 +229,7 @@ function doDownload(url, fmtIdx, retry403 = false) { render() let got403 = false + let lastErr = '' dlProc = spawn(YTDLP, args) const onData = d => { @@ -244,6 +246,11 @@ function doDownload(url, fmtIdx, retry403 = false) { dlProc.stderr.on('data', d => { const line = d.toString() if (parseProgress(line)) { render(); return } + if (line.includes('ERROR') || line.includes('error')) { + lastErr = line.replace(/\x1b\[[0-9;]*m/g, '').trim().slice(0, 80) + st.msg = lastErr + render() + } if (!got403 && (line.includes('HTTP Error 403') || line.includes('Sign in'))) { got403 = true dlProc.kill() @@ -257,10 +264,10 @@ function doDownload(url, fmtIdx, retry403 = false) { if (got403) return dlProc = null if (code === 0) { - st.mode = 'done'; st.progress = 100 + st.mode = 'done'; st.progress = 100; st.msg = '' } else if (code !== null) { st.mode = 'error' - st.msg = `ошибка (код ${code})` + st.msg = lastErr || `ошибка (код ${code})` } render() })