Mintplex-Labs/anything-llm · error
Failed to get youtube video id from the url
Error message
Failed to get youtube video id from the url
What it means
Thrown by the static `YoutubeLoader.getVideoID(url)` after `validYoutubeVideoUrl(url, true)` returns a falsy value — i.e. the input did not match any known YouTube URL shape. This is the URL-parsing counterpart to error 40: it rejects links the regex/validator cannot map to a video id before any transcript fetch is attempted.
Source
Thrown at collector/utils/extensions/YoutubeTranscript/YoutubeLoader/index.js:30
#language;
#addVideoInfo;
constructor({ videoId = null, language = null, addVideoInfo = false } = {}) {
if (!videoId) throw new Error("Invalid video id!");
this.#videoId = videoId;
this.#language = language;
this.#addVideoInfo = addVideoInfo;
}
/**
* Extracts the videoId from a YouTube video URL.
* @param url The URL of the YouTube video.
* @returns The videoId of the YouTube video.
*/
static getVideoID(url) {
const videoId = validYoutubeVideoUrl(url, true);
if (videoId) return videoId;
throw new Error("Failed to get youtube video id from the url");
}
/**
* Creates a new instance of the YoutubeLoader class from a YouTube video
* URL.
* @param url The URL of the YouTube video.
* @param config Optional configuration options for the YoutubeLoader instance, excluding the videoId.
* @returns A new instance of the YoutubeLoader class.
*/
static createFromUrl(url, config = {}) {
const videoId = YoutubeLoader.getVideoID(url);
return new YoutubeLoader({ ...config, videoId });
}
/**
* Loads the transcript and video metadata from the specified YouTube
* video. It uses the youtube-transcript library to fetch the transcript
* and the youtubei.js library to fetch the video metadata.View on GitHub (pinned to 526360e320)
Solutions
- Pre-validate with the same `validYoutubeVideoUrl(url, true)` helper before calling getVideoID, and reject early with a clear UI message.
- Trim whitespace and normalize the URL (decode, follow redirects) before extraction.
- If you already hold a bare 11-char id, pass it straight to the constructor instead of going through getVideoID.
- Expand or update `validYoutubeVideoUrl` to cover the URL shapes your users actually submit (shorts, embed, music subdomain).
Example fix
// before
const id = YoutubeLoader.getVideoID(rawUrl);
// after
const trimmed = String(rawUrl || '').trim();
if (!validYoutubeVideoUrl(trimmed, true)) {
throw new Error('Please paste a valid YouTube watch, share, or embed URL');
}
const id = YoutubeLoader.getVideoID(trimmed); Defensive patterns
Strategy: validation
Validate before calling
const { validYoutubeVideoUrl } = require('../path/to/validators');
function extractIdOrReject(url) {
const cleaned = String(url || '').trim();
const id = validYoutubeVideoUrl(cleaned, true);
if (!id) throw new Error('Please paste a valid YouTube watch, share, or embed URL');
return id;
} Type guard
function isLikelyYoutubeUrl(u) {
return typeof u === 'string' && /(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/shorts\/)[A-Za-z0-9_-]{11}/.test(u.trim());
} Try / catch
try {
const id = YoutubeLoader.getVideoID(url);
} catch (e) {
if (/Failed to get youtube video id/i.test(e.message)) {
return { error: 'That doesn\'t look like a YouTube video URL.' };
}
throw e;
} Prevention
- Trim and decode URLs before extraction.
- Reject playlist/channel URLs upstream; only accept single-video URLs.
- Keep validYoutubeVideoUrl's regex current with new YouTube URL shapes (shorts, music subdomain).
When it happens
Trigger: Calling `getVideoID('https://youtu.be/abc')` (too-short id), `getVideoID('not a url')`, `getVideoID('https://vimeo.com/...')`, short links that redirect but don't expose the id in the URL, or URLs with the `v=` query param stripped. Also triggered by `createFromUrl` which delegates here.
Common situations: Users paste a channel URL, a Shorts share link in an unexpected format, an embed URL, or a music.youtube.com link the validator doesn't recognize; copy-paste includes trailing whitespace or a stray Unicode character.
Related errors
- Invalid video id!
- Impossible to retrieve Youtube video ID.
- Type "${type}" is not a valid type to sync.
- Invalid link provided
- Failed to sync YouTube video transcript. ${reason}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/6b27fe793c833e04.
Report an issue: GitHub.