tubezero
v1.1.0
Published
Zero-dependency, ultra-lightweight YouTube InnerTube client optimized for client-side environments, browser extensions, and hybrid apps.
Downloads
25
Maintainers
Readme
TubeZero
📖 Full API Documentation & Snippets
A modular collection of JavaScript functions designed to scrape and reverse-engineer data from YouTube using its private internal API (InnerTube). This library is built to be ultra-lightweight, free of heavy external dependencies, and optimized for client-side environments (such as browser extensions or desktop applications).
⚖️ Comparison with Other Libraries
To ensure complete transparency, here is a comparison between TubeZero and the other main InnerTube libraries available on GitHub:
| Feature/Property | TubeZero (This Project) | LuanRT/YouTube.js (youtubei.js) | SuspiciousLookingOwl/youtubei |
| :--- | :--- | :--- | :--- |
| Architecture | Lite, pure fetch client, zero external dependencies | Full-featured monolithic SDK mapping almost all renderers | Object-oriented TypeScript query client |
| Optimization | Client-side & Web-Extension optimized | Heavy backend/server-side oriented | Node.js oriented with class-based queries |
| Pros & Use Cases | Extremely lightweight, fast, no compilation required. Native extraction of SAPISID and SAPISIDHASH via Web Crypto API for authenticated requests. | Complete coverage of features (deciphering video download signatures, live chat, dedicated interfaces for Music/Studio/Kids). | Class-based abstractions, clean TypeScript interface for querying videos, channels, and playlists. |
| Limitations | Lacks video download deciphering, full catalog of renderer schemas, and dedicated YT Music/Studio/Kids interfaces. | Large bundle size, complex codebase, requires polyfills/build tools to run in client/extension frontends. | Requires compilation, coupled with Node.js dependencies, not designed for direct client-side integration. |
⚠️ Important Note on CORS and Cookies
When this library is executed in a standard browser environment (e.g., on a standard website like myapp.com), requests to youtube.com/youtubei will be blocked due to browser CORS policies.
Recommended Execution Environments:
- Browser Extensions: Optimal. By granting host permissions for
https://*.youtube.com/*inmanifest.json, the extension bypasses CORS and can read session cookies directly to compute theSAPISIDHASHfor authenticated requests. - Desktop & Mobile Applications (Electron, Tauri, React Native): By controlling HTTP headers and disabling CORS, these applications can run the library natively.
- Server-side Environments (Node.js) with a CORS Proxy: Requests can be routed through a reverse proxy that removes header restrictions.
📦 Installation (Package Structure)
To prepare the package for local usage or NPM publishing:
# Initialize the package if exported into a dedicated folder
npm init -yAdd "type": "module" in your package.json to enable loading of ES modules.
💻 Usage Examples
The primary way to interact with TubeZero is through the Client class. For a full list of examples, check out the Documentation.
1. Initialization and Searching
Search for videos, playlists, or channels.
import { Client } from 'tubezero';
const youtube = new Client();
const results = await youtube.search("Rick Astley", { type: "video" });
console.log(results.items[0].title); // "Rick Astley - Never Gonna Give You Up"2. Fetching a Video and its Comments
Retrieve full metadata, streaming data, and comments for a video.
import { Client } from 'tubezero';
const youtube = new Client();
const video = await youtube.getVideo("dQw4w9WgXcQ");
console.log(`Title: ${video.title}`);
console.log(`Views: ${video.viewCount}`);
// Load the first page of comments
const comments = await video.comments.next();
comments.forEach(c => {
console.log(`[${c.author.name}]: ${c.content}`);
});3. Fetching a Playlist
Retrieve a playlist and paginate through its videos.
import { Client } from 'tubezero';
const youtube = new Client();
const playlist = await youtube.getPlaylist("PLtbcYJeD7QZ34kS_L8H-lV7J8xT6rU0k_");
// Load all pages
while (playlist.videos.hasMore) {
await playlist.videos.next();
}
console.log(`Total videos loaded: ${playlist.videos.items.length}`);🛡️ Legal Disclaimer
This tool is intended solely for educational, research, and study purposes regarding third-party web architectures. It is not associated, affiliated, sponsored, or endorsed by Google LLC or YouTube. The user assumes full civil and administrative liability arising from the use of these functions and any potential violation of YouTube's Terms of Service. The authors are not responsible for IP blocks, account bans, or other actions taken by YouTube as a result of using this library.
