Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

yt-search-lib

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yt-search-lib

Premium client-side YouTube search library using InnerTube API patterns. No API key required.

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

YouTube Search Library

A powerful, purely client-side JavaScript library for searching YouTube videos without an official API key. It uses YouTube's internal InnerTube API pattern and provides a high-performance, cached searching experience.

✨ Features

  • No API Key Required: Works by emulating the internal YouTube web client.
  • 100% Client-Side: No server-side code needed (bypasses CORS via configurable proxies).
  • Persistent LRU Cache: Automatically stores results in localStorage to save bandwidth and improve speed.
  • Rich Metadata: Returns titles, high-res thumbnails, watch links, durations, view counts, and channel names.
  • Modular & Lightweight: Zero dependencies, built with modern ES Modules.
  • Premium Demo: Includes a state-of-the-art, glassmorphic search interface.

🚀 Quick Start

1. Installation

npm install yt-search-lib

2. Usage

import YouTubeClient from 'yt-search-lib';

// Initialize the client
const client = new YouTubeClient({
  // Bypassing CORS is mandatory for browser usage
  proxyUrl: 'https://api.allorigins.win/raw?url=', 
  useCache: true,
  cacheMaxAge: 3600000 // 1 hour in ms
});

// Perform a search
async function search() {
  try {
    const results = await client.search('lofi hip hop', { limit: 5 });
    
    results.forEach(video => {
      console.log(`Title: ${video.title}`);
      console.log(`Link: ${video.link}`);
      console.log(`Thumbnail: ${video.thumbnail_url}`);
    });
  } catch (err) {
    console.error('Search failed:', err);
  }
}

search();

📂 Project Structure

  • src/index.js: Main library entry point.
  • src/lib/parser.js: Robust logic for parsing YouTube's complex JSON responses.
  • src/lib/transport.js: Network layer with proxy and error handling.
  • src/lib/cache.js: LocalStorage-based LRU caching mechanism.
  • src/lib/constants.js: InnerTube configuration and API keys.
  • index.html: A premium, responsive demo page.

⚙️ Configuration

The YouTubeClient constructor accepts an options object:

OptionTypeDefaultDescription
proxyUrlstring''Prefix URL for a CORS proxy.
useCachebooleantrueEnable or disable localStorage caching.
cacheMaxAgenumber3600000How long to keep results in cache (ms).
clientContextobjectWEBOverride the InnerTube client version/name.

⚠️ Important Note on CORS

Browsers block direct requests to YouTube. To use this library in a browser, you must use a CORS proxy.

  • For development: https://api.allorigins.win/raw?url= or https://cors-anywhere.herokuapp.com/
  • For production: It is highly recommended to host your own simple proxy server for stability and security.

📜 License

MIT

Keywords

youtube

FAQs

Package last updated on 12 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts