fix: download args, show error, uploader fallback
This commit is contained in:
parent
ff40a1b82d
commit
92bcc70728
1 changed files with 15 additions and 8 deletions
23
bm.js
23
bm.js
|
|
@ -206,18 +206,19 @@ function doDownload(url, fmtIdx, retry403 = false) {
|
||||||
const isSpotify = url.includes('spotify.com')
|
const isSpotify = url.includes('spotify.com')
|
||||||
const ffmpegDir = path.dirname(FFMPEG)
|
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) {
|
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 {
|
} else {
|
||||||
const audioFmt = { FLAC:'flac', WAV:'wav', MP3:'mp3', OPUS:'opus' }[fmt] || 'flac'
|
const audioFmt = { FLAC:'flac', WAV:'wav', MP3:'mp3', OPUS:'opus' }[fmt] || 'flac'
|
||||||
args.push('-x', '--audio-format', audioFmt, '--audio-quality', '0',
|
args.push('-x', '--audio-format', audioFmt, '--audio-quality', '0',
|
||||||
'-o', `${OUT_DIR}\\%(uploader)s - %(title)s.%(ext)s`,
|
'-o', `${OUT_DIR}\\%(uploader,channel|Unknown)s - %(title)s.%(ext)s`,
|
||||||
'--embed-thumbnail', '--embed-metadata', '--add-metadata')
|
'--embed-metadata', '--embed-thumbnail')
|
||||||
if (!isApple && !isSpotify) {
|
if (!isApple && !isSpotify) {
|
||||||
args.push('--extractor-args', 'youtube:player_client=web_creator,web',
|
args.push('--extractor-args', 'youtube:player_client=web_creator,web')
|
||||||
'--user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,6 +229,7 @@ function doDownload(url, fmtIdx, retry403 = false) {
|
||||||
render()
|
render()
|
||||||
|
|
||||||
let got403 = false
|
let got403 = false
|
||||||
|
let lastErr = ''
|
||||||
dlProc = spawn(YTDLP, args)
|
dlProc = spawn(YTDLP, args)
|
||||||
|
|
||||||
const onData = d => {
|
const onData = d => {
|
||||||
|
|
@ -244,6 +246,11 @@ function doDownload(url, fmtIdx, retry403 = false) {
|
||||||
dlProc.stderr.on('data', d => {
|
dlProc.stderr.on('data', d => {
|
||||||
const line = d.toString()
|
const line = d.toString()
|
||||||
if (parseProgress(line)) { render(); return }
|
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'))) {
|
if (!got403 && (line.includes('HTTP Error 403') || line.includes('Sign in'))) {
|
||||||
got403 = true
|
got403 = true
|
||||||
dlProc.kill()
|
dlProc.kill()
|
||||||
|
|
@ -257,10 +264,10 @@ function doDownload(url, fmtIdx, retry403 = false) {
|
||||||
if (got403) return
|
if (got403) return
|
||||||
dlProc = null
|
dlProc = null
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
st.mode = 'done'; st.progress = 100
|
st.mode = 'done'; st.progress = 100; st.msg = ''
|
||||||
} else if (code !== null) {
|
} else if (code !== null) {
|
||||||
st.mode = 'error'
|
st.mode = 'error'
|
||||||
st.msg = `ошибка (код ${code})`
|
st.msg = lastErr || `ошибка (код ${code})`
|
||||||
}
|
}
|
||||||
render()
|
render()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue