0

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.

  • check this answer https://stackoverflow.com/questions/36696605/nodejs-in-windows-file-system-path-error-4058-enoent – Ahmed ElMetwally Jun 16 '20 at 08:58
  • @AhmedElMetwally Thanks for the prompt reply. The problem in the question you provided was in using the colons in file name which is not my problem. My problem is that fs library automatically adds \ before the single quote mark which I don't want it to do so. – Ahmed Al Hammadi Jun 16 '20 at 09:10
  • why don't you remove all single quotes? ``videoTitle.split('"').join("")`` – kuso.sama Jun 16 '20 at 09:41

1 Answers1

0

It was the "?" mark which is not allowed in the file name in Windows and this was the same problem addressed by Ahmed ElMetwally. So after removing the "?" mark from the video title It worked perfectly.

Dharman
  • 30,962
  • 25
  • 85
  • 135