Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YTDL is being blocked when tried to access the youtube video #1312

Open
vinitbhaiji opened this issue Sep 11, 2024 · 2 comments
Open

YTDL is being blocked when tried to access the youtube video #1312

vinitbhaiji opened this issue Sep 11, 2024 · 2 comments

Comments

@vinitbhaiji
Copy link

I am trying to access the youtube video and trying to download it for the use of my code and it is forbidding the process

  • Here's the ERROR
    let err = new Miniget.MinigetError(Status code: ${res.statusCode}, res.statusCode);
    ^

        MinigetError: Status code: 403
            at ClientRequest.<anonymous> (D:\Downloads\Technoid\Project-mars-Backend- 
            main\server\Backend\node_modules\miniget\dist\index.js:206:27)    
            at Object.onceWrapper (node:events:633:26)
            at ClientRequest.emit (node:events:518:28)
            at HTTPParser.parserOnIncomingClient (node:_http_client:698:27)
            at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
            at TLSSocket.socketOnData (node:_http_client:540:22)
            at TLSSocket.emit (node:events:518:28)
            at addChunk (node:internal/streams/readable:559:12)
            at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
            at Readable.push (node:internal/streams/readable:390:5) {
          statusCode: 403
        }
    

Can anyone help me out on this?

@EdWIN1021
Copy link

try this

const youtubedl = require("youtube-dl-exec");
const ffmpeg = require("fluent-ffmpeg");
const path = require("path");

// Set the path to your ffmpeg binary
const ffmpegPath = path.join(process.cwd(), "tmp", "ffmpeg");
ffmpeg.setFfmpegPath(ffmpegPath);

// Replace the URL with the desired YouTube video URL
const videoUrl = "";

async function convertWebMToMP3(inputFilePath) {
  const outputFilePath = `output.mp3`;

  return new Promise((resolve, reject) => {
    ffmpeg(inputFilePath)
      .audioBitrate(128)
      .toFormat("mp3")
      .on("end", () => {
        console.log("Conversion finished successfully");
        resolve(outputFilePath);
      })
      .on("error", (err) => {
        console.error("Error during conversion:", err);
        reject(err);
      })
      .save(outputFilePath);
  });
}

async function downloadAndConvert() {
  const webmFilePath = path.join(process.cwd(), "tmp", "output.webm");

  try {
    // Step 1: Download the audio as WebM
    const output = await youtubedl(videoUrl, {
      extractAudio: true,
      audioFormat: "mp3",
      preferFfmpeg: true,
      output: webmFilePath,
    });
    console.log("Download completed:", output);

    // Step 2: Convert WebM to MP3
    const mp3Path = await convertWebMToMP3(webmFilePath);
    console.log("MP3 saved to:", mp3Path);
  } catch (err) {
    console.error("Error:", err);
  }
}

downloadAndConvert();

@gitadam0
Copy link

did

try this

const youtubedl = require("youtube-dl-exec");
const ffmpeg = require("fluent-ffmpeg");
const path = require("path");

// Set the path to your ffmpeg binary
const ffmpegPath = path.join(process.cwd(), "tmp", "ffmpeg");
ffmpeg.setFfmpegPath(ffmpegPath);

// Replace the URL with the desired YouTube video URL
const videoUrl = "";

async function convertWebMToMP3(inputFilePath) {
  const outputFilePath = `output.mp3`;

  return new Promise((resolve, reject) => {
    ffmpeg(inputFilePath)
      .audioBitrate(128)
      .toFormat("mp3")
      .on("end", () => {
        console.log("Conversion finished successfully");
        resolve(outputFilePath);
      })
      .on("error", (err) => {
        console.error("Error during conversion:", err);
        reject(err);
      })
      .save(outputFilePath);
  });
}

async function downloadAndConvert() {
  const webmFilePath = path.join(process.cwd(), "tmp", "output.webm");

  try {
    // Step 1: Download the audio as WebM
    const output = await youtubedl(videoUrl, {
      extractAudio: true,
      audioFormat: "mp3",
      preferFfmpeg: true,
      output: webmFilePath,
    });
    console.log("Download completed:", output);

    // Step 2: Convert WebM to MP3
    const mp3Path = await convertWebMToMP3(webmFilePath);
    console.log("MP3 saved to:", mp3Path);
  } catch (err) {
    console.error("Error:", err);
  }
}

downloadAndConvert();

did you just use a whole different library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants