microlinkhq / youtube-dl-exec

A simple Node.js wrapper for youtube-dl/yt-dlp.
MIT License
423 stars 75 forks source link

Can't seem to find location/actually download a youtube video #194

Closed IlyyA closed 5 months ago

IlyyA commented 5 months ago

I'm not sure whether it's failing to download, or just the location is set incorrectly.

Environment: VSCode Windows 11 Bash Shell

async function downloadYoutubeToFolder({ episode, url, title }) {
  const pathToDL = "D:/path/to/directory/";
  // Check if the directory exists
  if (!fs.existsSync(pathToDL)) {
    // If it doesn't exist, create the directory
    fs.mkdirSync(pathToDL);
  }
  const outputFilePath = `${pathToDL}/${title}.json`;
  const outputFilePathVid = `${pathToDL}/${title}`;
  const YT_OPTS = {
    dumpSingleJson: true,
    noCheckCertificates: true,
    preferFreeFormats: true,
    addHeader: ["referer:youtube.com", "user-agent:googlebot"],
    path: outputFilePathVid,
    output: title,
    writeInfoJson: true,
  };
  try {
    const promise = youtubeDl(url, YT_OPTS).then((output) =>
      fs.writeFileSync(outputFilePath, JSON.stringify(output, null, 2))
    );
    const result = await logger(promise, title);
  } catch (err) {
    console.log("error", err);
  }
  //console.log(result);
}

The result is here: image

With the following in the output in the JSON section under filename "_filename": "D:\\path\\to\\video", "filename": "D:\\path\\to\\video", "__write_download_archive": false

Attached is the JSON output. I'm really confused as to where it's downloading, or if it's failing to download, how to get it to download in a chosen directory. JSONOutput.json

Kikobeats commented 5 months ago

Hello, this library is a simple connector for https://github.com/yt-dlp/yt-dlp. I can't help there, try to use yt-dlp via CL and then do the same using this library.