npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

youtube-stream-extractor

v1.1.0

Published

Extract direct audio and video streams from YouTube search queries or URLs

Readme

YouTube Audio and Video Stream Extractor

NPM Version License

An ultra-fast, zero-dependency, lightweight JavaScript library built to extract direct audio and video stream URLs from YouTube. It utilizes YouTube's InnerTube player API (ANDROID_VR client payload) with a watch-page scraping fallback to deliver instant, high-quality media links (up to 320kbps audio).

Works out-of-the-box in Node.js (version 18+), browsers, and modern serverless/edge environments.

Documentation: Read the comprehensive General API Guide for full details on parameters and return types.

Discord Bot Integration: Want to use this in a Discord Music Bot without Lavalink? Check out our Discord Bot Guide.


Installation

Install the package via npm:

npm install youtube-stream-extractor

Features

  • Zero-Dependency and Fast: Extremely lightweight and fast.
  • No API Keys Required: Operates entirely without Google API keys, avoiding rate limits and setup friction.
  • High Quality Streams: Automatically resolves the best available formats, prioritizing 320kbps / 251 itag streams for crystal clear audio.
  • Integrated Keyword Search: Perform keyword searches that immediately resolve titles, durations, channel names, view counts, thumbnails, and direct streaming links.
  • Direct URL Resolver: Pass any standard or short YouTube URL to get parsed media streams in seconds.
  • Dual Build: Fully supports both ES Modules (import) and CommonJS (require).

Usage Examples

1. Search YouTube by Keyword

Search for videos and extract their metadata along with stream links:

ES Modules (ESM):

import { searchYouTube } from 'youtube-stream-extractor';

const results = await searchYouTube('lofi hip hop', { limit: 3 });
console.log(results);

CommonJS (CJS):

const { searchYouTube } = require('youtube-stream-extractor');

async function run() {
  const results = await searchYouTube('lofi hip hop', { limit: 3 });
  console.log(results);
}
run();

2. Extract Streams from YouTube URL

Extract information and direct audio/video streams from a specific YouTube watch URL:

import { extractFromUrl } from 'youtube-stream-extractor';

const info = await extractFromUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ');

console.log(info.title);      // "Rick Astley - Never Gonna Give You Up"
console.log(info.audioUrl);   // Direct Google Video audio stream URL
console.log(info.videoUrl);   // Direct Google Video video stream URL

3. Get Stream URLs directly by Video ID

If you already have the 11-character YouTube video ID, you can fetch its stream URLs directly:

import { getStreamUrls } from 'youtube-stream-extractor';

const streams = await getStreamUrls('dQw4w9WgXcQ');
console.log(streams.audioUrl);
console.log(streams.videoUrl);

API Reference

ExtractorOptions

Many functions accept an optional options object with the following parameters:

  • poToken (string, optional): A Proof of Origin token used to bypass bot enforcement on copyrighted/VEVO videos.
  • visitorData (string, optional): A unique session identifier.
  • client (string, optional): Innertube client layout, e.g. 'WEB', 'ANDROID', 'TVHTML5', or 'YTM'.
  • fetchStreams (boolean, optional): Set to false in searches to speed up queries by skipping immediate stream resolution.

searchYouTube(query, options)

Searches for videos on YouTube.

  • query (string, required): The search keyword (e.g. lofi hip hop).
  • options (object, optional):
    • limit (number, default 3): Number of search results to return (Min 1, Max 20).
    • Extractor options (poToken, visitorData, fetchStreams).

Returns: Promise<Array>


extractFromUrl(url, options)

Resolves a YouTube URL to extract video details and stream links.

  • url (string, required): Full YouTube video URL.
  • options (object, optional): Extractor options.

Returns: Promise


getStreamUrls(videoId, options)

Fetches streaming URLs directly for a given YouTube video ID.

  • videoId (string, required): The 11-character YouTube video ID.
  • options (object, optional): Extractor options.

Returns: Promise<{ audioUrl: string, videoUrl: string, playerResponse: object }>


getAutoplay(videoId, options)

Fetches a list of related/recommended videos for a given video ID to enable autoplay lists.

  • videoId (string, required): The video ID to base recommendations on.
  • options (object, optional): Extractor options.

Returns: Promise<Array>


getSearchSuggestions(query, options)

Fetches autocomplete search suggestions from YouTube.

  • query (string, required): The text query entered by the user.

Returns: Promise<Array>


getPlaylist(playlistId, options)

Extracts info and all tracks/videos from a YouTube Playlist.

  • playlistId (string, required): The YouTube playlist ID.
  • options (object, optional): Extractor options.

Returns: Promise


License and Credits

Distributed under the MIT License. Developed and maintained by iy3k.