po-token-generator
is a utility package designed to help you access YouTube data without logging in (Most of the cases). It leverages Puppeteer with puppeteer-extra
plugins (Stealth and Adblocker) to bypass restrictions and generate a poToken
, which can be used to make requests to YouTube as if you were authenticated.
- YouTube Data Scraping: Scrapes YouTube for
poToken
andvisitorData
using Puppeteer. - Stealth Mode: Uses the Puppeteer Stealth plugin to avoid detection by anti-bot systems.
- Adblocker Integration: Blocks ads and trackers for faster and cleaner scraping.
- Concurrent Scraping: Supports scraping multiple YouTube video IDs concurrently.
- Caching: Built-in caching to avoid redundant requests and improve efficiency.
- Flexible Configuration: Highly configurable with support for custom browser options, viewports, and more.
The po_token
is an essential token that allows access to certain YouTube resources without requiring a login. By using po_token
, you can bypass login requirements and access metadata, comments, and other public resources without triggering CAPTCHA or other anti-bot mechanisms.
You can install the package via npm or pnpm:
# Using npm
npm install po-token-generator
# Using pnpm
pnpm add po-token-generator
Here’s how to use po-token-generator
to scrape YouTube video data:
import { scrapeYouTubeData } from "po-token-generator";
const videoId = "CEARgJ74WPU";
(async () => {
try {
const data = await scrapeYouTubeData(videoId);
console.log(data);
} catch (error) {
console.error("Failed to scrape data:", error);
}
})();
The scrapeYouTubeData
function is highly configurable. Here’s an example using advanced options:
import { scrapeYouTubeData, Config } from "po-token-generator";
const config: Config = {
headless: true,
requestInterception: true,
blockResources: ["image", "stylesheet", "font"],
cacheOptions: { stdTTL: 600 }, // Cache results for 10 minutes
viewport: { width: 1280, height: 720 },
};
const videoId = "CEARgJ74WPU";
(async () => {
try {
const data = await scrapeYouTubeData(videoId, config);
console.log(data);
} catch (error) {
console.error("Failed to scrape data:", error);
}
})();
Scrapes YouTube for the specified videoId
and returns the poToken
and visitorData
.
videoId
(string): The ID of the YouTube video you want to scrape.config
(Config): Optional configuration object.
Promise<ScrapeResult>
: Resolves with an object containingpoToken
andvisitorData
.
interface Config {
headless?: boolean; // Run Puppeteer in headless mode
requestInterception?: boolean; // Enable request interception to block certain resources
blockResources?: ResourceType[]; // Specify resource types to block (e.g., 'image', 'stylesheet')
stealthPlugin?: boolean; // Use Puppeteer stealth plugin
adblockerPlugin?: boolean; // Use Puppeteer adblocker plugin
adblockerPluginOptions?: Record<string, any>; // Options for adblocker plugin
cacheOptions?: NodeCache.Options; // Cache options for NodeCache
viewport?: puppeteer.Viewport; // Set custom viewport dimensions
launchArgs?: string[]; // Additional launch arguments for Puppeteer
waitUntil?: "load" | "domcontentloaded" | "networkidle0" | "networkidle2"; // When to consider navigation done
executablePath?: string; // Path to the Chromium or Chrome executable
}
interface ScrapeResult {
poToken: string; // The poToken extracted from YouTube
visitorData: string; // The visitorData extracted from YouTube
}
- Metadata Collection: Collect metadata from YouTube videos without needing to log in.
- Comment Analysis: Access and analyze comments from YouTube videos.
- Data Scraping: Scrape YouTube data at scale using multiple video IDs concurrently.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Fork the repository.
- Clone your fork.
- Install dependencies:
pnpm install
- Make your changes and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.