Sometimes the video downloads successfully, and sometimes not, despite the fact that the code does not change in any way, the Internet is stable. It gives this error when an attempt fails:
C:UsersGlebDesktopворк[email protected]:180
throw new Error(`No such format found: ${QUALITY}`);
^
Error: No such format found: highestaudio
at FormatUtils.chooseFormat (C:UsersGlebDesktopворк[email protected]:180:19)
at C:UsersGlebDesktopворк1.0.2node_modules@ybd-projectytdl-corepackagecoreDownloadDownload.js:92:51
at process.processTicksAndRejections (node:internal/process/task_queues:105:5).
Don’t mind that I use not original ytdl-core. I tried using “try” and “catch” to run the program in a circle until a successful attempt, but this error is not caught. How i can fix it?
my code:
import fs from 'fs';
import { YtdlCore, toPipeableStream } from '@ybd-project/ytdl-core';
const ytdl = new YtdlCore({});
let vidId = '';
ytdl
.download(`https://www.youtube.com/watch?v=${vidId}`, {
quality: 'highestaudio',
})
.then((stream) =>
toPipeableStream(stream).pipe(fs.createWriteStream(`${vidId}_audio.m4a`)),
);
ytdl
.download(`https://www.youtube.com/watch?v=${vidId}`, { quality: 'highest' })
.then((stream) =>
toPipeableStream(stream).pipe(fs.createWriteStream(`${vidId}.mp4`)),
);