Skip to content
This repository was archived by the owner on Aug 16, 2025. It is now read-only.
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

Error: MinigetError: Status code: 403 #255

Description

@dawasherpa-ui

My code is :

const express = require('express');
const fs = require('fs');
const { pipeline } = require('stream/promises');
const ytdl = require('@distube/ytdl-core');
const app = express();

app.get('/download', async (req, res) => {
  const videoURL = 'https://www.youtube.com/watch?v=D4OETmw4HiI';
  
  // Set the headers to indicate the content is a file to be downloaded
  res.setHeader('Content-Disposition', 'attachment; filename="song.mp3"');
  res.setHeader('Content-Type', 'audio/mpeg');

  try {
    // Stream the audio
    const audioStream = ytdl(videoURL, {
      quality: 'highestaudio',
      highWaterMark: 1 << 25,  // 32 MB chunks
    });

    // Pipe the audio stream directly to the response, so it can be downloaded
    await pipeline(audioStream, res);
    
    console.log('Download started');
  } catch (err) {
    res.status(500).send('Error downloading video');
    console.error('Error:', err);
  }
});

app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

PS C:\Users\Dawa\Desktop\Music-backend> node test.js
Server is running on http://localhost:3000
WARNING: Could not parse decipher function.
Stream URLs will be missing.
Please report this issue by uploading the "1745995992503-player-script.js" file on https://github.com/distubejs/ytdl-core/issues/144.
WARNING: Could not parse n transform function.
Please report this issue by uploading the "1745995993565-player-script.js" file on https://github.com/distubejs/ytdl-core/issues/144.
Error: MinigetError: Status code: 403
    at ClientRequest.<anonymous> (C:\Users\Dawa\Desktop\Music-backend\node_modules\miniget\dist\index.js:206:27)
    at Object.onceWrapper (node:events:634:26)
    at ClientRequest.emit (node:events:519:28)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:702:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:118:17)
    at TLSSocket.socketOnData (node:_http_client:544:22)
    at TLSSocket.emit (node:events:519: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
}
Error: Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at ServerResponse.onclose (node:internal/streams/end-of-stream:159:30)
    at ServerResponse.emit (node:events:531:35)
    at emitCloseNT (node:_http_server:1021:10)
    at Socket.onServerResponseClose (node:_http_server:277:5)
    at Socket.emit (node:events:531:35)
    at TCP.<anonymous> (node:net:339:12) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}
Error: MinigetError: Status code: 403
    at ClientRequest.<anonymous> (C:\Users\Dawa\Desktop\Music-backend\node_modules\miniget\dist\index.js:206:27)
    at Object.onceWrapper (node:events:634:26)
    at ClientRequest.emit (node:events:519:28)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:702:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:118:17)
    at TLSSocket.socketOnData (node:_http_client:544:22)
    at TLSSocket.emit (node:events:519: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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions