YouTube Transcript NPM પૅકેજ: JavaScript અને TypeScript SDK
તમારી Node.js એપ્લિકેશનમાં પ્રોગ્રામેટિકલી YouTube ટ્રાન્સક્રિપ્ટ કાઢો. NPM પરથી ઇન્સ્ટોલ કરો, તમારી API key વડે પ્રમાણીકરણ કરો અને મિનિટોમાં વિડિયો ટ્રાન્સક્રાઇબ કરવાનું શરૂ કરો.
ઇન્સ્ટોલેશન
npm install youtube-transcript-api pnpm add youtube-transcript-api yarn add youtube-transcript-api
ક્વિક સ્ટાર્ટ
import { YouTubeTranscript } from "youtube-transcript-api";
const yt = new YouTubeTranscript({ apiKey: "your_api_key" });
const result = await yt.getTranscript("dQw4w9WgXcQ");
console.log(result.data?.transcript.text);ફીચર્સ
સંપૂર્ણ V2 API કવરેજ
Transcribe, batch, jobs, polling: દરેક endpoint રૅપ કરેલો.
TypeScript-ફર્સ્ટ
IntelliSense સપોર્ટ સાથે સંપૂર્ણ ટાઇપ વ્યાખ્યાઓ.
શૂન્ય ડિપેન્ડન્સી
નેટિવ fetch વાપરે છે. ફક્ત Node 18+, કોઈ વધારાનો બોજ નહીં.
ટાઇપ્ડ એરર
દરેક API એરર કોડ માટે અલગ એરર ક્લાસ.
બિલ્ટ-ઇન પોલિંગ
async ASR ટ્રાન્સક્રિપ્શન માટે waitForJob હેલ્પર.
ESM અને CommonJS
કોઈ સેટઅપ વિના બંને મોડ્યુલ સિસ્ટમમાં કામ કરે છે.
વિકલ્પો સાથે ટ્રાન્સક્રાઇબ કરો
const result = await yt.transcribe({
video: "dQw4w9WgXcQ",
language: "fr",
source: "manual",
format: {
timestamp: true,
paragraphs: true,
words: false,
},
});
console.log(result.status); // "completed"
console.log(result.data?.transcript.text); // Full transcript text
console.log(result.data?.transcript.language); // "fr"
console.log(result.data?.transcript.segments); // Timestamped segments
console.log(result.credits_used); // Credits consumedબૅચ પ્રોસેસિંગ (100 વિડિયો સુધી)
const result = await yt.batch({
video_ids: ["dQw4w9WgXcQ", "jNQXAC9IVRw", "9bZkp7q19f0"],
format: { timestamp: true },
});
console.log(result.summary);
// { total: 3, succeeded: 3, failed: 0, processing: 0 }
for (const item of result.results) {
console.log(`${item.data?.video_id}: ${item.data?.transcript.text.slice(0, 100)}...`);
}ASR ઑડિયો ટ્રાન્સક્રિપ્શન
કૅપ્શન વગરના વિડિયો માટે સીધા ઑડિયોમાંથી ટ્રાન્સક્રાઇબ કરવા ASR વાપરો. webhook કૉલબૅક અથવા બિલ્ટ-ઇન પોલિંગ સપોર્ટેડ.
const result = await yt.transcribe({
video: "VIDEO_ID",
source: "asr",
allow_asr: true,
webhook_url: "https://yoursite.com/webhook",
});const result = await yt.transcribe({
video: "VIDEO_ID",
source: "asr",
allow_asr: true,
});
if (result.job_id) {
const final = await yt.waitForJob(result.job_id, {
interval: 5000,
maxAttempts: 60,
});
console.log(final.data?.transcript.text);
}const result = await yt.transcribe({
video: "VIDEO_WITHOUT_CAPTIONS",
source: "asr",
// allow_asr not set: V2 requires explicit confirmation
});
if (result.status === "requires_asr_confirmation") {
console.log(result.estimated_credits); // e.g. 5
console.log(result.duration_minutes); // e.g. 7.5
// User confirms → retry with allow_asr
const confirmed = await yt.transcribe({
video: "VIDEO_WITHOUT_CAPTIONS",
source: "asr",
allow_asr: true,
});
}એરર હેન્ડલિંગ
import {
YouTubeTranscript,
InvalidRequestError,
AuthenticationError,
InsufficientCreditsError,
NoCaptionsError,
RateLimitError,
} from "youtube-transcript-api";
try {
await yt.getTranscript("invalid");
} catch (error) {
if (error instanceof AuthenticationError) {
console.log("Bad API key");
} else if (error instanceof InsufficientCreditsError) {
console.log("Top up at https://youtubetranscript.dev/pricing");
} else if (error instanceof NoCaptionsError) {
console.log("No captions: try source: 'asr' with allow_asr: true");
} else if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${error.retryAfter}s`);
}
}કૉન્ફિગરેશન
const yt = new YouTubeTranscript({
apiKey: "your_api_key",
baseUrl: "https://...", // Override API base URL
timeout: 60_000, // Request timeout in ms (default: 30s)
});Node.js 18+ જરૂરી (નેટિવ fetch વાપરે છે). તમારી API key અહીંથી મેળવો: youtubetranscript.dev/dashboard/account.
અન્ય SDK અને ટૂલ્સ
ક્યારે શું વાપરવું
NPM પૅકેજ
Node.js એપ્લિકેશન, સર્વર-સાઇડ રેન્ડરિંગ, CLI ટૂલ્સ અને ઓટોમેટેડ સ્ક્રિપ્ટ માટે શ્રેષ્ઠ, જ્યાં પ્રોગ્રામેટિક ઍક્સેસ જોઈએ.
REST API
નૉન-JavaScript વાતાવરણ, એક વખતની વિનંતીઓ અને ભાષા-સ્વતંત્ર HTTP ઍક્સેસ માટે શ્રેષ્ઠ.
MCP સર્વર
Claude, Cursor અને VS Code Copilot જેવા AI કોડિંગ આસિસ્ટન્ટ માટે શ્રેષ્ઠ, જ્યાં તમે સામાન્ય ભાષામાં સંવાદ ઇચ્છો છો.
વારંવાર પૂછાતા પ્રશ્નો
શું NPM પૅકેજ વાપરવા માટે મફત છે?+
પૅકેજ ઇન્સ્ટોલ કરવું મફત છે. વિનંતીઓ મોકલવા માટે તમારે YouTubeTranscript.dev API key ની જરૂર છે. API keys બધા પેઇડ પ્લાનમાં ઉપલબ્ધ છે.
શું તે બ્રાઉઝરમાં કામ કરે છે?+
પૅકેજ Node.js સર્વર-સાઇડ ઉપયોગ માટે બનાવાયું છે. બ્રાઉઝર-આધારિત એક્સટ્રેક્શન માટે fetch અથવા axios સાથે સીધું અમારું REST API વાપરો.
કયા Node.js વર્ઝન સપોર્ટેડ છે?+
Node.js 18 અને તેથી ઉપર. પૅકેજ નેટિવ fetch અને આધુનિક JavaScript ફીચર્સ વાપરે છે.
શું હું તેને Deno અથવા Bun સાથે વાપરી શકું?+
હા, આ પૅકેજ NPM પૅકેજને સપોર્ટ કરતા Deno અને Bun રનટાઇમ સાથે સુસંગત છે.
NPM પૅકેજ સાથે બનાવવાનું શરૂ કરો
સેકન્ડોમાં ઇન્સ્ટોલ કરો. સંપૂર્ણ TypeScript સપોર્ટ. વ્યાપક ડૉક્યુમેન્ટેશન.
NPM પર જુઓ →