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

MinigetError: Status code: 403 #1289

Open
Namnp1521 opened this issue May 23, 2024 · 12 comments
Open

MinigetError: Status code: 403 #1289

Namnp1521 opened this issue May 23, 2024 · 12 comments

Comments

@Namnp1521
Copy link

I run on the local successfully but I got this error when run on the firebase function cloud.

image

version:
"axios": "^1.2.0",
"ytdl-core": "^4.11.5"

@shubham-ralli
Copy link

I have faces the same problem , I got this error when run on the server.

@shubham-ralli
Copy link

Is there any update

@mdanish1326
Copy link

on dev it works fine, but on prod it breaks, Is there any solution ?

@konsumer
Copy link

konsumer commented Jun 21, 2024

I ended up looking at yt-dlp to figure out why they do not get 403'd. I also needed to use fetch (which is built-in, now, and needed in places like cloudflare workers) instead of a http-lib. This javascript code works, without any deps:

export async function getInfo (videoId) {
  // hard-coded from https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/youtube.py
  const apiKey = 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc'

  const headers = {
    'X-YouTube-Client-Name': '5',
    'X-YouTube-Client-Version': '19.09.3',
    Origin: 'https://www.youtube.com',
    'User-Agent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
    'content-type': 'application/json'
  }

  const b = {
    context: {
      client: {
        clientName: 'IOS',
        clientVersion: '19.09.3',
        deviceModel: 'iPhone14,3',
        userAgent: 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
        hl: 'en',
        timeZone: 'UTC',
        utcOffsetMinutes: 0
      }
    },
    videoId,
    playbackContext: { contentPlaybackContext: { html5Preference: 'HTML5_PREF_WANTS' } },
    contentCheckOk: true,
    racyCheckOk: true
  }

  return fetch(`https://www.youtube.com/youtubei/v1/player?key${apiKey}&prettyPrint=false`, { method: 'POST', body: JSON.stringify(b), headers }).then(r => r.json())
}

Working URLs are in streamingData.adaptiveFormats. Here is usage-example:

import { getInfo } from './yt.js'
import { writeFile } from 'fs/promises'

const info = await getInfo('C0DPdy98e4c')
const video = info.streamingData.adaptiveFormats.find(f => f.mimeType.includes('video/mp4'))
await writeFile('test.mp4', await fetch(video.url).then(async r => new Uint8Array(await r.arrayBuffer())))

@makanakidev
Copy link

I ended up looking at yt-dlp to figure out why they do not get 403'd. I also needed to use fetch (which is built-in, now, and needed in places like cloudflare workers) instead of a http-lib. This javascript code works, without any deps:

export async function getInfo (videoId) {
  // hard-coded from https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/youtube.py
  const apiKey = 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc'

  const headers = {
    'X-YouTube-Client-Name': '5',
    'X-YouTube-Client-Version': '19.09.3',
    Origin: 'https://www.youtube.com',
    'User-Agent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
    'content-type': 'application/json'
  }

  const b = {
    context: {
      client: {
        clientName: 'IOS',
        clientVersion: '19.09.3',
        deviceModel: 'iPhone14,3',
        userAgent: 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
        hl: 'en',
        timeZone: 'UTC',
        utcOffsetMinutes: 0
      }
    },
    videoId,
    playbackContext: { contentPlaybackContext: { html5Preference: 'HTML5_PREF_WANTS' } },
    contentCheckOk: true,
    racyCheckOk: true
  }

  return fetch(`https://www.youtube.com/youtubei/v1/player?key${apiKey}&prettyPrint=false`, { method: 'POST', body: JSON.stringify(b), headers }).then(r => r.json())
}

Working URLs are in streamingData.adaptiveFormats. Here is usage-example:

import { getInfo } from './yt.js'
import { writeFile } from 'fs/promises'

const info = await getInfo('C0DPdy98e4c')
const video = info.streamingData.adaptiveFormats.find(f => f.mimeType.includes('video/mp4'))
await writeFile('test.mp4', await fetch(video.url).then(async r => new Uint8Array(await r.arrayBuffer())))

The video from stream url has no audio output. Appears to be muted in the video player and there's no way to unmute it!

@konsumer
Copy link

konsumer commented Jul 15, 2024

The video from stream url has no audio output. Appears to be muted in the video player and there's no way to unmute it!

@makanakidev yeh, it seems to separate them. I didn't notice because my test-video is silent. It does provide audio as well, though.

This is a complete download CLI (that can also be used as library for info) that grabs the first audio & video for a format (hd1080|hd720|large|medium|small|tiny) and merges them, including progress bars and stuff. I recommend looking at how it works and customizing it to your needs.

It's also published at @konsumer/ytdownload.

@elvismdev
Copy link

Hi everyone,

Is there a way yet to retrieve videos with audio included, similar to how it happens when sending the request with:

"context": {
    "client": {
        "clientName": "ANDROID_TESTSUITE",
        "clientVersion": "1.9"
    }
}

but being able to obtain different qualities of videos with audio included? Any guidance or updates on this would be greatly appreciated.

Thank you!

@konsumer
Copy link

@elvismdev see above. I am doing that. You need to merge the 2 streams.

@Piliponful
Copy link

this is unusable, it works insanely slow

I ended up looking at yt-dlp to figure out why they do not get 403'd. I also needed to use fetch (which is built-in, now, and needed in places like cloudflare workers) instead of a http-lib. This javascript code works, without any deps:

export async function getInfo (videoId) {
  // hard-coded from https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/youtube.py
  const apiKey = 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc'

  const headers = {
    'X-YouTube-Client-Name': '5',
    'X-YouTube-Client-Version': '19.09.3',
    Origin: 'https://www.youtube.com',
    'User-Agent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
    'content-type': 'application/json'
  }

  const b = {
    context: {
      client: {
        clientName: 'IOS',
        clientVersion: '19.09.3',
        deviceModel: 'iPhone14,3',
        userAgent: 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
        hl: 'en',
        timeZone: 'UTC',
        utcOffsetMinutes: 0
      }
    },
    videoId,
    playbackContext: { contentPlaybackContext: { html5Preference: 'HTML5_PREF_WANTS' } },
    contentCheckOk: true,
    racyCheckOk: true
  }

  return fetch(`https://www.youtube.com/youtubei/v1/player?key${apiKey}&prettyPrint=false`, { method: 'POST', body: JSON.stringify(b), headers }).then(r => r.json())
}

Working URLs are in streamingData.adaptiveFormats. Here is usage-example:

import { getInfo } from './yt.js'
import { writeFile } from 'fs/promises'

const info = await getInfo('C0DPdy98e4c')
const video = info.streamingData.adaptiveFormats.find(f => f.mimeType.includes('video/mp4'))
await writeFile('test.mp4', await fetch(video.url).then(async r => new Uint8Array(await r.arrayBuffer())))

The video from stream url has no audio output. Appears to be muted in the video player and there's no way to unmute it!

@konsumer
Copy link

konsumer commented Jul 16, 2024

this is unusable, it works insanely slow

@Piliponful It seems reasonably fast to me, but feel free to write it another way. This is a proof-of-concept. My method is the only working way to get video URLs from youtube, that I know of. If you figure it out, let the rest of us know.

@shubham-ralli
Copy link

MinigetError: Status code: 403
at ClientRequest. (/opt/render/project/src/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
}

@Namnp1521
Copy link
Author

Namnp1521 commented Jul 22, 2024

i use distubejs/ytdl-core library while waiting this library fix this bug, and it work fine.
Btw you guys can check this quick fix #1301 (comment)

import ytdl from "@distube/ytdl-core";

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

7 participants