distubejs / ytdl-core

YouTube video downloader in javascript.
MIT License
203 stars 43 forks source link

Support po_tokens (to resolve "Sign in to confirm you're not a bot") #87

Open Brainicism opened 1 month ago

Brainicism commented 1 month ago

Describe the bug

The other issue (https://github.com/distubejs/ytdl-core/issues/76) has been derailed with tech support questions. po_token and visitor_data is now required to bypass the bot confirmation screen. Details are documented in yt-dlp or Invidious' fix here: https://github.com/iv-org/invidious/pull/4789 && https://github.com/yt-dlp/yt-dlp/pull/10648.

The po_token/visitor_data can be generated using https://github.com/iv-org/youtube-trusted-session-generator, or presumably through inspecting your browser's HTTP request headers + cookies.

How difficult would it be able to support this?

Debug File

Working request body

{
  "context": {
    "client": {
      "clientName": "WEB",
      "clientVersion": "2.20240726.00.00",
      "hl": "en",
      "timeZone": "UTC",
      "utcOffsetMinutes": 0
    }
  },
  "videoId": "[VIDEO_ID]",
  "serviceIntegrityDimensions": {
    "poToken": "[PO_TOKEN]"
  },
  "playbackContext": {
    "contentPlaybackContext": {
      "html5Preference": "HTML5_PREF_WANTS",
      "signatureTimestamp": 19942
    }
  },
  "contentCheckOk": true,
  "racyCheckOk": true
}

Working Headers

{
    "X-YouTube-Client-Name": "1",
    "X-YouTube-Client-Version": "2.20240726.00.00",
    "Origin": "https://www.youtube.com",
    "X-Goog-Visitor-Id": "[VISITOR_ID]"
}

Environment

@distube/ytdl-core version: 4.14.4 Node.js version: v18.20.3 Operating system: Debian GNU/Linux 11

thind9xdev commented 1 month ago

You can use cookie for avoid it

  private async initializeAgent() {
    const cookiesPath = path.join(__dirname, '..', 'cookies.json');
    const cookiesContent = fs.readFileSync(cookiesPath, 'utf8');
    this.agent = ytdl.createAgent(JSON.parse(cookiesContent));
  }
  getAgent(): ytdl.Agent {
    return this.agent;
  }
Brainicism commented 1 month ago

You can use cookie for avoid it

  private async initializeAgent() {
    const cookiesPath = path.join(__dirname, '..', 'cookies.json');
    const cookiesContent = fs.readFileSync(cookiesPath, 'utf8');
    this.agent = ytdl.createAgent(JSON.parse(cookiesContent));
  }
  getAgent(): ytdl.Agent {
    return this.agent;
  }

Authentication doesn't always fix this issue. Main point of this issue is to figure out if unauthenticated requests can still be made to work. Risking Google account bans is not ideal

thind9xdev commented 1 month ago
cookies.json

Don't worry , because file cookies.json set at in your back-end, not in client (front-end)

Brainicism commented 1 month ago
cookies.json

Don't worry , because file cookies.json set at in your back-end, not in client (front-end) you can check here : https://phuongmychi.vn/watch?v=ZTbKpBzL7hE

My point still stands.. and this is not relevant to the issue I created. The maintainer can decide whether this approach is viable

thind9xdev commented 1 month ago
cookies.json

Don't worry , because file cookies.json set at in your back-end, not in client (front-end)

My point still stands.. and this is not relevant to the issue I created. The maintainer can decide whether this approach is viable

If you worry about that, you can create an youtube clone account for use cookie ^^, If you don't use cookie, you will be get error 403

ybd-project commented 1 month ago

Hey @Brainicism. Does it work without cookies or proxies if I set po_token etc as you say? I have deployed my API to Vercel Function, but cookies do not work on such a server and I am using a proxy at this time. (because I get a "Sign in to confirm you're not a bot" error)

fsholehan commented 1 month ago

Yes, it seems like an update is needed to be able to use po_tokens.

iRajatDas commented 3 weeks ago

Yes, it seems like an update is needed to be able to use po_tokens.

How to retrieve the po_token, is there any working version?

lltr commented 3 weeks ago

currently cookies doesn't work for live streams, seems like this is needed

fsholehan commented 3 weeks ago

Use Youtubei.js its working fine for me

ybd-project commented 3 weeks ago

Support for poToken is almost complete. Right now, the getBasicInfo function is not working due to a bot error, so I am fixing that. You can find it at @ybd-project/ytdl-core

ybd-project commented 3 weeks ago

@ybd-project/ytdl-core I have now released ytdl-core with the ability to specify poToken and visitorData. The iOS and Android players are experiencing bot errors, but we have been able to work around this by using the Web Creator player. These issues are being improved, so please wait. We are looking forward to receiving reports of issues.