YouTube Caption Scraper Randomly Fails with “Could not find captions for video”

I’m trying to grab YouTube video captions using the youtube-captions-scraper package. Most of the time, it works perfectly, but sometimes it fails with the following error: Could not find captions for video: video-id

This error seems to occur randomly, even for videos where captions are available when checked manually.

const { getSubtitles } = require('youtube-captions-scraper');

const videoId = 'some-video-id';

getSubtitles({
  videoID: videoId, // YouTube video ID
  lang: 'en' // language code
})
.then(captions => {
  console.log(captions);
})
.catch(err => {
  console.error('Error:', err.message);
});
  • The video definitely has captions (I verified them on the YouTube).
  • The error does not always occur for the same video ID; sometimes the same video will work fine on subsequent attempts.
  • I have tried this on different networks and systems, but the behavior is inconsistent.

Has anyone faced this issue or know why this happens? Could it be related to rate-limiting or API throttling by YouTube? Any advice on how to handle this more gracefully or avoid the error altogether would be appreciated.