Skip to content

A lightweight Node.js/TypeScript library to generate YouTube trusted sessions without using a browser. This project provides similar functionality to YouTube "Proof of Origin Token" (poToken) generators but with a more efficient implementation that doesn't require a browser.

License

Notifications You must be signed in to change notification settings

idMJA/youtube-trusted-session-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YouTube Trusted Session Generator

A lightweight Node.js/TypeScript library to generate YouTube trusted sessions without using a browser. This project provides similar functionality to YouTube "Proof of Origin Token" (poToken) generators but with a more efficient implementation that doesn't require a browser.

About

This project is a TypeScript/Bun rewrite inspired by:

  1. YunzheZJU/youtube-po-token-generator - Original inspiration that generates a valid poToken with visitorData fetched from YouTube
  2. iv-org/youtube-trusted-session-generator - A Python-based YouTube session generator used by Invidious

This implementation provides similar functionality but is rewritten from the ground up in TypeScript and optimized for Bun as the runtime environment.

What is a poToken

poToken (Proof of Origin Token) is an attestation token generated by a complex anti-robot verification system created by Google named BotGuard/DroidGuard. It is used to confirm that requests to YouTube are coming from genuine clients.

These identity tokens (poToken and visitor_data) will make your YouTube session more easily traceable by YouTube because they are tied to a unique identifier. The benefit is that they allow applications to access YouTube content that would otherwise be blocked.

Features

  • Generate YouTube visitor data and poToken
  • No browser dependency
  • Lightweight and fast
  • Multi-threaded token generation
  • Easy to use
  • One-shot mode for direct token retrieval
  • API mode for programmatic access
  • Continuous token refreshing every 30 seconds
  • HTTP server with web interface and API endpoints
  • Automatic token management

Requirements

  • Node.js >= 18.0
  • Bun (recommended for best performance)

Installation

# Clone the repository
git clone https://github.com/your-username/youtube-trusted-session-generator.git
cd youtube-trusted-session-generator

# Install dependencies
bun install

Usage

Normal Mode (Continuous Updates)

In normal mode, the generator will:

  1. Start an HTTP server on port 3000 (configurable via PORT env variable)
  2. Generate tokens immediately
  3. Automatically refresh tokens every 30 seconds (configurable via REFRESH_INTERVAL env variable)
  4. Provide a web interface and API endpoints
bun start

Web Interface

Access the web interface by opening a browser and navigating to:

http://localhost:3000/

The interface allows you to:

  • View current tokens
  • Force update tokens with a single click
  • See success and error messages

API Endpoints

  • GET / - Web interface
  • GET /token - Get current tokens
  • GET /update - Force update tokens (returns success message)

The /update endpoint will return a success message when tokens are updated:

{
  "status": "success",
  "code": 200,
  "message": "Tokens have been successfully updated",
  "instructions": "Please get the updated tokens from the /token endpoint"
}

After receiving this success message, you should get the updated tokens from the /token endpoint.

One-shot Mode

Run the generator once and get tokens directly:

bun start --oneshot

This will output the tokens in JSON format:

{
  "visitorData": "visitor_data_string",
  "poToken": "po_token_string"
}

Response Format

The generator returns an object with the following structure:

{
    visitorData: "string", // YouTube visitor data
    poToken: "string"      // YouTube poToken
}

Token Management

  • Tokens are automatically refreshed every 30 seconds in normal mode (configurable via REFRESH_INTERVAL env variable)
  • Tokens can be force-refreshed using the /update endpoint
  • The API provides a forceUpdate option to bypass caching
  • Multi-threading is used for faster token generation

Error Handling

The library includes built-in error handling and will throw errors for:

  • Network connection issues
  • Invalid responses from YouTube
  • Parsing errors

Using with Invidious

You can use this library with Invidious by:

  1. Running the generator in either one-shot or normal mode
  2. Getting the poToken and visitorData values
  3. Adding these values to your Invidious config.yaml:
    po_token: XXX
    visitor_data: XXX
  4. Restarting Invidious

Using with Other Applications

You can also use this library with any other application that needs to communicate with YouTube's API:

  1. Run the generator in normal mode
  2. Use the API endpoint to fetch updated tokens when needed
  3. Include the tokens in your YouTube API requests

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A lightweight Node.js/TypeScript library to generate YouTube trusted sessions without using a browser. This project provides similar functionality to YouTube "Proof of Origin Token" (poToken) generators but with a more efficient implementation that doesn't require a browser.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •