fix: download args, show error, uploader fallback

This commit is contained in:
Savsis? 2026-08-30 18:26:18 +05:00
parent ff40a1b82d
commit 92bcc70728

23
bm.js
View file

@ -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()
})