English | 中文
Simple script for downloading Youtube comments without using the Youtube API. The output is in line delimited JSON.
Node.js/TypeScript port of egbertbouman/youtube-comment-downloader with added proxy support.
Installation
Install this package via pnpm (recommended):
pnpm add youtube-comment-downloader
Or using npm:
npm install youtube-comment-downloader
For global CLI usage:
pnpm add -g youtube-comment-downloader
npm install -g youtube-comment-downloader
Usage as command-line interface
$ youtube-comment-downloader --help
Usage: youtube-comment-downloader [options]
Download Youtube comments without using the Youtube API
Options:
-y, --youtubeid <id> ID of Youtube video for which to download the comments
-u, --url <url> Youtube URL for which to download the comments
-o, --output <file> Output filename (output format is line delimited JSON)
-p, --pretty Change the output format to indented JSON
-l, --limit <number> Limit the number of comments
-a, --language <lang> Language for Youtube generated text (e.g. en)
--proxy <uri> Proxy URI (e.g. http://user:pass@proxy.example.com:8080)
-s, --sort <number> Whether to download popular (0) or recent comments (1). Defaults to 1
-h, --help display help for command
Examples
Download comments using video URL:
youtube-comment-downloader --url https://www.youtube.com/watch?v=ScMzIvxBSi4 --output ScMzIvxBSi4.json
Download comments using video ID:
youtube-comment-downloader --youtubeid ScMzIvxBSi4 --output ScMzIvxBSi4.json
Download with pretty formatting:
youtube-comment-downloader --youtubeid ScMzIvxBSi4 --output ScMzIvxBSi4.json --pretty
Download only first 100 comments:
youtube-comment-downloader --youtubeid ScMzIvxBSi4 --output ScMzIvxBSi4.json --limit 100
Download popular comments instead of recent:
youtube-comment-downloader --youtubeid ScMzIvxBSi4 --output ScMzIvxBSi4.json --sort 0
Download using proxy:
youtube-comment-downloader --youtubeid ScMzIvxBSi4 --output ScMzIvxBSi4.json --proxy http://proxy.example.com:8080
Download using proxy with authentication:
youtube-comment-downloader --youtubeid ScMzIvxBSi4 --output ScMzIvxBSi4.json --proxy http://username:password@proxy.example.com:8080
For Youtube IDs starting with -
(dash), use the =
syntax:
youtube-comment-downloader --youtubeid=-idwithdash --output output.json
Usage as library
You can also use this package programmatically in your Node.js/TypeScript projects:
JavaScript Example
const { YoutubeCommentDownloader, SORT_BY_POPULAR } = require('youtube-comment-downloader');
async function downloadComments() {
const downloader = new YoutubeCommentDownloader();
const comments = downloader.getCommentsFromUrl(
'https://www.youtube.com/watch?v=ScMzIvxBSi4',
SORT_BY_POPULAR
);
let count = 0;
for await (const comment of comments) {
console.log(comment);
if (++count >= 10) break;
}
}
downloadComments();
TypeScript Example
import { YoutubeCommentDownloader, SORT_BY_POPULAR, Comment } from 'youtube-comment-downloader';
async function downloadComments(): Promise<void> {
const downloader = new YoutubeCommentDownloader();
const comments = downloader.getComments('ScMzIvxBSi4', SORT_BY_POPULAR);
const allComments: Comment[] = [];
for await (const comment of comments) {
allComments.push(comment);
}
console.log(`Downloaded ${allComments.length} comments`);
}
downloadComments();
Download with proxy support
import { YoutubeCommentDownloader, SORT_BY_RECENT, Comment } from 'youtube-comment-downloader';
async function downloadWithProxy(): Promise<void> {
const downloader = new YoutubeCommentDownloader({
proxy: { uri: 'http://proxy.example.com:8080' }
});
const comments = downloader.getComments('ScMzIvxBSi4', SORT_BY_RECENT);
for await (const comment of comments) {
console.log(`${comment.author}: ${comment.text}`);
}
}
downloadWithProxy();
Download with language preference
const { YoutubeCommentDownloader, SORT_BY_RECENT } = require('youtube-comment-downloader');
async function downloadWithLanguage() {
const downloader = new YoutubeCommentDownloader();
const comments = downloader.getComments(
'ScMzIvxBSi4',
SORT_BY_RECENT,
'en'
);
for await (const comment of comments) {
console.log(`${comment.author}: ${comment.text}`);
}
}
API Reference
Main class for downloading YouTube comments.
Constructor
Creates a new instance of the YouTube comment downloader.
options
(DownloaderOptions, optional): Configuration options
proxy
(ProxyConfig, optional): Proxy configuration
uri
(string): Proxy URI (e.g., http://proxy.example.com:8080
or http://user:pass@proxy.example.com:8080
)
Methods
Downloads comments for a YouTube video by its ID.
youtubeId
(string): The YouTube video ID
sortBy
(number, optional): Sort order - SORT_BY_RECENT
(1) or SORT_BY_POPULAR
(0). Default: SORT_BY_RECENT
language
(string, optional): Language code for YouTube generated text (e.g., 'en', 'es', 'fr')
sleepTime
(number, optional): Sleep time in seconds between requests. Default: 0.1
Returns: AsyncGenerator<Comment>
- An async generator that yields comment objects
Downloads comments for a YouTube video by its URL.
youtubeUrl
(string): The full YouTube video URL
sortBy
(number, optional): Sort order - SORT_BY_RECENT
(1) or SORT_BY_POPULAR
(0). Default: SORT_BY_RECENT
language
(string, optional): Language code for YouTube generated text
sleepTime
(number, optional): Sleep time in seconds between requests. Default: 0.1
Returns: AsyncGenerator<Comment>
- An async generator that yields comment objects
Each comment yielded by the generator has the following structure:
interface Comment {
cid: string;
text: string;
time: string;
author: string;
channel: string;
votes: string;
replies: number;
photo: string;
heart: boolean;
reply: boolean;
time_parsed?: number;
paid?: string;
}
Constants
SORT_BY_POPULAR
(0): Sort comments by popularity
SORT_BY_RECENT
(1): Sort comments by recency (newest first)
Features
- No YouTube API key required
- Supports both video URLs and video IDs
- Download all comments including replies
- Sort by popular or recent
- Language preference support
- Proxy support - Use HTTP/HTTPS proxies for improved access
- Automatic retry on failure
- Handles consent pages automatically
- Supports paid comments/SuperChats
- Line-delimited JSON or pretty formatted output
- Full TypeScript support
Development
Building from source
git clone https://github.com/p697/node-youtube-comment-downloader.git
cd node-youtube-comment-downloader
pnpm install
pnpm run build
pnpm test
pnpm run watch
Running tests
pnpm test
pnpm run test:watch
pnpm test -- --coverage
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Disclaimer
This package is for educational purposes only. Please respect YouTube's Terms of Service and the rights of content creators and commenters when using this tool.