I am exploring ytdl-core library to download youtube videos and works fine for me. The problem is when I try to download a video that has a single quote in the title, I am getting the following error from fs library.
{ [Error: ENOENT: no such file or directory, open 'C:\Users\ahmed\Documents\ProjectFolder\downloads\What's The Best Suspension - Soft or Stiff Springs? - video.mp4']
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path:
'C:\\Users\\ahmed\\Documents\\ProjectFolder\\downloads\\What\'s The Best Suspension - Soft or Stiff Springs? - video.mp4' }
I noticed that a backslash is automatically added before the single quote, so I thought it is looking for a folder called "What" but even after creating this folder, I am still getting the same error.
Here is my code:
const yt = ytdl.downloadFromInfo(info, {quality: itag}); //passing info object and options object to choose a format
yt.on('error', console.error);
yt.on('progress', onProgress); //calling a function to log the progress
let writeStream = fs.createWriteStream(videoTitle); //video title is stored in a variable from a previous fucntion
writeStream.on('error', console.error);
yt.pipe(writeStream);
I hope somebody can help me to overcome this problem.