{"record":{"id":"6b27fe793c833e04","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-get-youtube-video-id-from-the-url","errorCode":null,"errorMessage":"Failed to get youtube video id from the url","messagePattern":"Failed to get youtube video id from the url","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/utils/extensions/YoutubeTranscript/YoutubeLoader/index.js","lineNumber":30,"sourceCode":"  #language;\n  #addVideoInfo;\n\n  constructor({ videoId = null, language = null, addVideoInfo = false } = {}) {\n    if (!videoId) throw new Error(\"Invalid video id!\");\n    this.#videoId = videoId;\n    this.#language = language;\n    this.#addVideoInfo = addVideoInfo;\n  }\n\n  /**\n   * Extracts the videoId from a YouTube video URL.\n   * @param url The URL of the YouTube video.\n   * @returns The videoId of the YouTube video.\n   */\n  static getVideoID(url) {\n    const videoId = validYoutubeVideoUrl(url, true);\n    if (videoId) return videoId;\n    throw new Error(\"Failed to get youtube video id from the url\");\n  }\n\n  /**\n   * Creates a new instance of the YoutubeLoader class from a YouTube video\n   * URL.\n   * @param url The URL of the YouTube video.\n   * @param config Optional configuration options for the YoutubeLoader instance, excluding the videoId.\n   * @returns A new instance of the YoutubeLoader class.\n   */\n  static createFromUrl(url, config = {}) {\n    const videoId = YoutubeLoader.getVideoID(url);\n    return new YoutubeLoader({ ...config, videoId });\n  }\n\n  /**\n   * Loads the transcript and video metadata from the specified YouTube\n   * video. It uses the youtube-transcript library to fetch the transcript\n   * and the youtubei.js library to fetch the video metadata.","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/utils/extensions/YoutubeTranscript/YoutubeLoader/index.js#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nconst id = YoutubeLoader.getVideoID(rawUrl);\n\n// after\nconst trimmed = String(rawUrl || '').trim();\nif (!validYoutubeVideoUrl(trimmed, true)) {\n  throw new Error('Please paste a valid YouTube watch, share, or embed URL');\n}\nconst id = YoutubeLoader.getVideoID(trimmed);","handlingStrategy":"validation","validationCode":"const { validYoutubeVideoUrl } = require('../path/to/validators');\nfunction extractIdOrReject(url) {\n  const cleaned = String(url || '').trim();\n  const id = validYoutubeVideoUrl(cleaned, true);\n  if (!id) throw new Error('Please paste a valid YouTube watch, share, or embed URL');\n  return id;\n}","typeGuard":"function isLikelyYoutubeUrl(u) {\n  return typeof u === 'string' && /(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/|youtube\\.com\\/shorts\\/)[A-Za-z0-9_-]{11}/.test(u.trim());\n}","tryCatchPattern":"try {\n  const id = YoutubeLoader.getVideoID(url);\n} catch (e) {\n  if (/Failed to get youtube video id/i.test(e.message)) {\n    return { error: 'That doesn\\'t look like a YouTube video URL.' };\n  }\n  throw e;\n}","preventionTips":["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)."],"tags":["youtube","validation","url-parsing"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}