youtube-caption-node
v1.0.0
Published
A TypeScript-powered Node.js module to fetch and parse YouTube video transcripts
Maintainers
Readme
youtube-caption-node
A TypeScript-powered Node.js module to fetch and parse YouTube video transcripts/captions.
Installation
npm install youtube-caption-nodeUsage
TypeScript
import { getTranscriptFromUrl } from 'youtube-caption-node';
const result = await getTranscriptFromUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if ('error' in result) {
console.log('Error:', result.error);
} else {
console.log('Title:', result.title);
console.log('Video ID:', result.videoId);
console.log('Clean Transcript:', result.transcript_clean);
}JavaScript
import { getTranscriptFromUrl } from 'youtube-caption-node';
const result = await getTranscriptFromUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if (result.error) {
console.log('Error:', result.error);
} else {
console.log('Title:', result.title);
console.log('Clean Transcript:', result.transcript_clean);
}API
getTranscriptFromUrl(url: string): Promise<TranscriptResponse>
Parameters:
url- YouTube video URL or video ID
Success Response:
TypeScript interface:
interface TranscriptResult {
title: string;
videoId: string;
language: string;
languageName: string;
transcript_raw: string;
transcript_clean: string;
}Example:
{
"title": "Video Title",
"videoId": "dQw4w9WgXcQ",
"language": "en",
"languageName": "English",
"transcript_raw": "Full raw transcript text...",
"transcript_clean": "Cleaned and formatted transcript..."
}Error Response:
TypeScript interface:
interface TranscriptError {
error: string;
videoId: string | null;
}Example:
{
"error": "No transcript available",
"videoId": "dQw4w9WgXcQ"
}Supported URL Formats
https://www.youtube.com/watch?v=VIDEO_IDhttps://youtu.be/VIDEO_IDhttps://www.youtube.com/embed/VIDEO_IDVIDEO_ID(direct video ID)
TypeScript Types
import {
getTranscriptFromUrl,
TranscriptResponse,
TranscriptResult,
TranscriptError
} from 'youtube-caption-node';Author
Rohit Nishad
- Website: rohitnishad.com
- GitHub: @merohitnishad
- npm: rohitnishad
- Email: [email protected]
Links
License
MIT © Rohit Nishad
