joshunrau / ytdl-mp3

An npm package to facilitate downloading music from YouTube, including automatic retrieval of ID3 tags and album art via the iTunes public API
https://www.npmjs.com/package/ytdl-mp3
MIT License
24 stars 12 forks source link

403 for any download #65

Closed isaacs closed 2 months ago

isaacs commented 3 months ago

Getting a 403 error trying to download anything with this library. Maybe youtube changed something on their end?

Added a console.log to show the requests it's making, if that's helpful.

$ ytdl-mp3 https://www.youtube.com/watch?v=ZUJAxBIF1Yg
{
  host: 'api.github.com',
  hostname: 'api.github.com',
  path: '/repos/fent/node-ytdl-core/releases/latest',
  port: '',
  protocol: 'https:',
  maxRedirects: 10,
  maxRetries: 2,
  maxReconnects: 0,
  backoff: { inc: 100, max: 10000 },
  headers: { 'User-Agent': 'ytdl-core', referer: 'https://www.youtube.com/' }
}
{
  host: 'www.youtube.com',
  hostname: 'www.youtube.com',
  path: '/watch?v=ZUJAxBIF1Yg&hl=en',
  port: '',
  protocol: 'https:',
  maxRedirects: 10,
  maxRetries: 2,
  maxReconnects: 0,
  backoff: { inc: 100, max: 10000 },
  headers: {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36',
    referer: 'https://www.youtube.com/'
  }
}
{
  host: 'www.youtube.com',
  hostname: 'www.youtube.com',
  path: '/s/player/8eff86d5/player_ias.vflset/en_US/base.js',
  port: '',
  protocol: 'https:',
  maxRedirects: 10,
  maxRetries: 2,
  maxReconnects: 0,
  backoff: { inc: 100, max: 10000 },
  headers: {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36',
    referer: 'https://www.youtube.com/'
  }
}
{
  host: 'rr1---sn-nvopjoxu-nwjl.googlevideo.com',
  hostname: 'rr1---sn-nvopjoxu-nwjl.googlevideo.com',
  path: '/videoplayback?expire=1721337860&ei=pDOZZpyfGcP7sfIPpOeK0AM&ip=2001%3A5a8%3A4508%3Aa400%3A282d%3Ab7f8%3Ad8b%3Ac237&id=o-AM9sF5bFW5wzSpd87FK_WsuCorh6ZEnLt8uAjFoMg6aR&itag=251&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=65&mm=31%2C29&mn=sn-nvopjoxu-nwjl%2Csn-n4v7snl7&ms=au%2Crdu&mv=m&mvi=1&pcm2cms=yes&pl=45&gcr=us&initcwndbps=1045000&bui=AXc671INsYyR19a09z4bS6Vp6mqtHc0vO5yNRgkAsDS9-DVPJUplSjbg84vxyo61ZeLeJ4T_4vX1GGXC&spc=NO7bAWzsySKtexnZEJx4Y0sVF8aAhKHe5cZ7BfV0gfIGlniqGbfdTzAsLszu&vprv=1&svpuc=1&mime=audio%2Fwebm&ns=6iLCMa4W3-dw_sqZgjDJnTUQ&rqh=1&gir=yes&clen=2583419&dur=144.521&lmt=1714691630616388&mt=1721315819&fvip=4&keepalive=yes&c=WEB&sefc=1&txp=2318224&n=Xc6hwxNJApWVya2FYQs&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cgcr%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps&lsig=AHlkHjAwRgIhAOKRIZhQVKnUTBMWd9U5bMjlJzjTd9CvVCUZ2wM45QMnAiEA78X3UwmqTjO1kTiXfYc_iJ8ISj6OnDcTUWcN8ZACpiI%3D&sig=AJfQdSswRQIhAKb8HSpSPHci-7AliKrxzvw4zXYCdODzRqXWiKkZhw8-AiAPFptTayk7twq2tTxDESVcAETyqMIS4ei4Q8v7AEX_Tg%3D%3D',
  port: '',
  protocol: 'https:',
  maxRedirects: 10,
  maxRetries: 3,
  maxReconnects: 6,
  backoff: { inc: 500, max: 10000 },
  headers: { Range: 'bytes=0-', referer: 'https://www.youtube.com/' }
}
/Users/isaacs/Downloads/el-jan-2023/node_modules/miniget/dist/index.js:208
                let err = new Miniget.MinigetError(`Status code: ${res.statusCode}`, res.statusCode);
                          ^

MinigetError: Status code: 403
    at ClientRequest.<anonymous> (/Users/isaacs/Downloads/el-jan-2023/node_modules/miniget/dist/index.js:208:27)
    at Object.onceWrapper (node:events:634:26)
    at ClientRequest.emit (node:events:519: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: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
}

Node.js v20.13.1
isaacs commented 3 months ago

Ah, that's me also putting the referer there, in case that was the issue, but it apparently isn't.

joshunrau commented 3 months ago

Related to https://github.com/fent/node-ytdl-core/issues/1295

isaacs commented 3 months ago

The issue was user-agent. I hard coded in the UA header from my browser, and then it works.

Tony450 commented 3 months ago

I don't understand very well what you did. Where did you hard code the user agent header from the browser? In which source code file?

dench1k commented 2 months ago

Have the same problem basically. C:\Users\admin\AppData\Roaming\npm\node_modules\ytdl-mp3\node_modules\miniget\dist\index.js:206 let err = new Miniget.MinigetError(Status code: ${res.statusCode}`, res.statusCode); ^

MinigetError: Status code: 403 at ClientRequest. (C:\Users\admin\AppData\Roaming\npm\node_modules\ytdl-mp3\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 (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: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 }

Node.js v20.15.0`

Can you guys some solution for solving this problem?

dench1k commented 2 months ago

@joshunrau pls help if you know a solution. I've used your product for a while, you know ;)

ShaquilleSadiq commented 2 months ago

I've created a PR that should fix this error #67

joshunrau commented 2 months ago

Thanks @ShaquilleSadiq ! Just confirmed this is fixed. Sorry, was very busy lately and didn't have time to look at this. The new version is up on npm let me know if any further issues.