youtube-scraper-api
v0.0.1
Published
Node.js client for the ScrapingBee YouTube API: search, video metadata, and subtitles as structured JSON.
Maintainers
Readme
youtube-scraper-api
Node.js client for the ScrapingBee YouTube scraper API. Search YouTube, read video metadata, and pull subtitles as parsed JSON, with proxies, headless rendering, and anti-bot handling done server-side. If you need a youtube scraping api in a Node service without running browsers yourself, this is the wrapper.
npm install youtube-scraper-apiFree tier: 1,000 credits, no card, at scrapingbee.com.
Build a YouTube scraper in three calls
A common flow: search a topic, pick a result, then enrich it with metadata and captions. Here it is end to end.
const { YouTubeScraper } = require('youtube-scraper-api');
const yt = new YouTubeScraper({ apiKey: 'YOUR-API-KEY' });
async function run() {
const hits = await yt.search({ search: 'python tutorial', type: 'video', sortBy: 'view_count' });
const videoId = hits.results[0].videoId;
const details = await yt.metadata({ videoId });
const captions = await yt.subtitles({ videoId, language: 'en' });
console.log(details, captions);
}
run();Every method returns a Promise that resolves to parsed JSON. Authentication is a Bearer token the client sets for you.
Each call on its own
Searching
const hits = await yt.search({ search: 'machine learning' });
console.log(hits.results);A search is the core of any youtube video scraper: it returns videos, channels, and playlists with titles, view counts, durations, and thumbnails.
Metadata
const details = await yt.metadata({ videoId: 'dQw4w9WgXcQ' });Returns duration, view count, like count, upload date, description, channel info, thumbnails, and available formats for one video.
Subtitles
const captions = await yt.subtitles({ videoId: 'dQw4w9WgXcQ', language: 'en' });Returns timestamped caption segments. Pass subtitleOrigin to choose auto-generated or uploader-provided captions when both exist.
Search filters
Add any of these to a search() call:
| Option | API parameter | Accepted values |
|---|---|---|
| type | type | video, channel, playlist, movie |
| uploadDate | upload_date | today, last_hour, this_week, this_month, this_year |
| duration | duration | <4, 4-20, >20 |
| sortBy | sort_by | rating, relevance, view_count, upload_date |
| hd, fourK, subtitles, creativeCommons, live | hd, 4k, subtitles, creative_commons, live | booleans |
| tag | tag | custom id echoed back in the response |
| extra | (any) | object for other documented flags: 360, 3d, hdr, vr180, location, purchased |
const filtered = await yt.search({
search: 'lo-fi',
type: 'video',
uploadDate: 'this_week',
duration: '>20',
live: true,
});What a search returns
{
"results": [
{
"videoId": "...",
"title": { },
"longBylineText": { },
"thumbnail": { },
"lengthText": { },
"shortViewCountText": { },
"publishedTimeText": { }
}
],
"search": "query string"
}Each result carries only the fields YouTube returned, so guard with optional chaining before reading.
Credits and pricing
ScrapingBee bills successful calls. search() is 5 credits per call. The cost for metadata() and subtitles() shows in the dashboard request builder. Plan tiers: scrapingbee.com/pricing.
FAQ
Is there a free youtube scraper api?
ScrapingBee gives 1,000 free credits with no card. Search is 5 credits per call, enough for a few hundred test queries.
How do I get a transcript?
Call subtitles({ videoId }). It returns timestamped caption segments, and subtitleOrigin picks auto-generated or uploader-provided captions.
Why does a plain fetch return no video data?
YouTube renders results in the browser, so the raw HTML is empty. These endpoints run a headless browser server-side and return parsed JSON.
Is scraping YouTube allowed?
Public data is generally collectible for research and monitoring, but YouTube's terms and local regulations apply. Scrape public content only.
Links
License
MIT. See LICENSE.
Disclaimer
Unofficial Node.js wrapper around the ScrapingBee YouTube API. Not affiliated with ScrapingBee or YouTube. Compliance with YouTube's terms of service and applicable data-protection law is the responsibility of the operator.
