|
|
Generate valid trusted sessions for YouTube including VisitorData, PoTokens & RolloutTokens. |
- Trusted Sessions: Generate sessions that pass YouTube’s anti-bot checks - unlock access to protected endpoints
- Easy to Use: Just a few lines of code required - no need to worry about the low-level details
- Configurable: Built for .NET with flexible config & pluggable JS environment support - no browser needed
# Install the latest version from NuGet
dotnet add package YouTubeSessionGeneratorusing YouTubeSessionGenerator;
using YouTubeSessionGenerator.Js.Environments;
using NodeEnvironment myCustomJsEnvironment = new(); // Make sure this gets disposed!
YouTubeSessionConfig config = new()
{
JsEnvironment = myCustomJsEnvironment, // Required when generating Proof of Origin Tokens
HttpClient = myCustomHttpClient, // Optional: Provide your own HttpClient
Logger = myCustomLogger // Optional: Enable logging
};
YouTubeSessionCreator creator = new(config);
string visitorData = await creator.VisitorDataAsync();
string poToken = await creator.ProofOfOriginTokenAsync(visitorData);
string rolloutToken = await creator.RolloutTokenAsync();To learn more, visit the full Getting Started & Configuration Guide.
YouTube uses several internal tokens to validate client requests. This library reverse-engineers the behavior of official YouTube clients to generate those tokens, including:
- Visitor Data: Session-level identity token
- Proof of Origin Token: BotGuard-validated, JS-signed token
- Rollout Token: Determines feature flags and experiments per session
Fore more details, see here.
This library was made possible thanks to the incredible reverse-engineering work and research by the open-source community, especially those who uncovered and shared insights into YouTube’s internal APIs.
Special thanks to the following projects and individuals:
- LuanRT/BgUtils - for their extensive description of how PoToken are generated.
- LuanRT/YouTube.js - for their detailed understanding of the InnerTube API.
- yt-dlp - for their research of when and where PoTokens are required.
- Hao Kuang - for their detailed explanation of YouTube's internal API design.