Closed MrManiak closed 3 years ago
const RE_YOUTUBE = /(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/im;
/**
* Retrieve video id from url or string
* @param videoId video url or video id
*/
private static retrieveVideoId(videoId: string) {
if (videoId.length === 11) return videoId;
const matchId = videoId.match(RE_YOUTUBE);
if (matchId && matchId.length > 1) {
return matchId[1];
}
throw new YoutubeTranscriptError(
'Impossible to retrieve Youtube video ID.'
);
}
Tell me if you want a PR, I can do that
Hello ! Thanks for the bug, I released a new version with the fix !
Hi,
You can only use
YoutubeTranscript.fetchTranscript
once per process, becauseRE_YOUTUBE.exec
returnsnull
next time you callfetchTranscript
. You can replace it byvideoId.match(RE_YOUTUBE)
instead.