{"record":{"id":"4aa796bc06a16eef","repo":"tonhowtf/omniget","slug":"could-not-extract-youtube-video-id","errorCode":null,"errorMessage":"Could not extract YouTube video ID","messagePattern":"Could not extract YouTube video ID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/youtube.rs","lineNumber":115,"sourceCode":"                    url: entry.url,\n                    format: \"ytdlp_playlist\".to_string(),\n                })\n                .collect();\n\n            return Ok(MediaInfo {\n                title: sanitize_filename::sanitize(&playlist_title),\n                author: playlist_title,\n                platform: \"youtube\".to_string(),\n                duration_seconds: None,\n                thumbnail_url: None,\n                available_qualities: qualities,\n                media_type: MediaType::Playlist,\n                file_size_bytes: None,\n            });\n        }\n\n        let _video_id = Self::extract_video_id(url)\n            .ok_or_else(|| anyhow!(\"Could not extract YouTube video ID\"))?;\n\n        let json = ytdlp::get_video_info(ytdlp_path, url, &[]).await?;\n        Self::parse_video_info(&json)\n    }\n\n    fn extract_quality_height(quality_str: &str) -> Option<u32> {\n        let s = quality_str.trim().to_lowercase();\n        if s == \"best\" || s == \"highest\" {\n            return None;\n        }\n        s.trim_end_matches('p').parse::<u32>().ok()\n    }\n\n    pub fn parse_video_info(json: &serde_json::Value) -> anyhow::Result<MediaInfo> {\n        let video_id = json\n            .get(\"id\")\n            .and_then(|v| v.as_str())\n            .unwrap_or(\"unknown\")","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/youtube.rs#L97-L133","documentation":"Raised in fetch_with_ytdlp when Self::extract_video_id(url) returns None, i.e. the URL passed to the YouTube platform handler does not contain a recognizable video ID. The code checks for playlist/media-type results first; anything that falls through must be a single video, so a non-video URL aborts here before yt-dlp is invoked.","triggerScenarios":"Calling fetch_with_ytdlp with a YouTube URL that is not a watch/shorts/youtu.be video URL (e.g. a channel URL, a youtu.be link missing its ID, a URL with only a 'v=' parameter that is empty, or an already-extracted playlist that failed the earlier Playlist branch).","commonSituations":"Passing user-supplied URLs straight from a UI or clipboard without validation; passing youtube.com URLs for /feed, /channel, /c, /results (search) pages; truncated URLs pasted without the video ID; URLs to live-set or mix pages with unexpected path shapes.","solutions":["Validate the URL is a YouTube video URL (watch?v=, youtu.be/<id>, shorts/<id>) before calling fetch_with_ytdlp.","Check the URL for typos, missing query parameters, or surrounding whitespace/HTML markup from copy-paste.","If the target is a playlist or channel, use the playlist/media-type code path instead of the single-video path.","Extend extract_video_id if a legitimate new YouTube URL format (e.g. /live/<id>) is not being matched."],"exampleFix":"// before\nlet url = input.trim();\nplatform.fetch_with_ytdlp(url, &ytdlp).await?;\n\n// after\nlet url = input.trim();\nif extract_video_id(url).is_none() {\n    eprintln!(\"not a YouTube video URL: {url}\");\n    return Ok(()); // or route to playlist handling\n}\nplatform.fetch_with_ytdlp(url, &ytdlp).await?;","handlingStrategy":"validation","validationCode":"const YT_VIDEO_RE = /^https?:\\/\\/(www\\.|m\\.)?(youtube\\.com\\/(watch\\?v=|shorts\\/|live\\/)|youtu\\.be\\/)[\\w-]{11}/;\nif (!YT_VIDEO_RE.test(url.trim())) throw new Error(`not a YouTube video URL: ${url}`);","typeGuard":"function isYouTubeVideoUrl(url) {\n  try { const u = new URL(url); return u.hostname.endsWith('youtube.com') || u.hostname === 'youtu.be'; }\n  catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Validate YouTube URL shape before invoking platform handlers","Trim and sanitize pasted URLs (whitespace, HTML entities)","Route playlists/channels to their dedicated code paths instead of the video path","Keep extract_video_id updated for new YouTube URL formats like /live/<id>"],"tags":["youtube","url-parsing","invalid-url","video-id"],"backgroundTag":"invalid-url-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}