tonhowtf/omniget · error
Could not extract post ID
Error message
Could not extract post ID
What it means
After resolving the input URL to a canonical Reddit post URL, native_get_media_info calls extract_post_id; if the canonical URL does not match the expected post-ID patterns, it returns None and this anyhow error is thrown, stopping all downstream media extraction.
Solutions
- Validate the URL matches a /comments/{id} or /comments/{slug}/{id} pattern before calling the API.
- Confirm short/share links (v.redd.it, reddit.com/s/xxx) resolve successfully — check network and redirects.
- Log the canonical URL when this error occurs to see what resolve_to_canonical produced.
- Update extract_post_id's regex if Reddit changed permalink formats (e.g. new URL schemes).
Example fix
// caller-side pre-validation
fn looks_like_reddit_post(url: &str) -> bool {
url.contains("/comments/") || url.contains("v.redd.it")
}
if !looks_like_reddit_post(&user_url) {
return Err(anyhow!("Not a Reddit post URL: {}", user_url));
} Defensive patterns
Strategy: validation
Validate before calling
fn is_reddit_post_url(url: &str) -> bool {
let u = url.trim();
u.contains("/comments/")
|| u.contains("redd.it/")
|| regex::Regex::new(r"reddit\.com/(?:r/\w+/)?comments/[a-z0-9]{5,}")
.unwrap()
.is_match(u)
} Try / catch
match native_get_media_info(url).await {
Err(e) if e.to_string() == "Could not extract post ID" => {
show_user("This doesn't look like a Reddit post URL");
}
other => other,
} Prevention
- Validate URLs against /comments/{id} patterns before invoking the extractor.
- Expand share/short links (reddit.com/s/..., v.redd.it) with redirects before parsing.
- Log the canonical URL on failure to debug resolve_to_canonical.
- Reject subreddit/user/profile URLs early with a clear user message.
When it happens
Trigger: resolve_to_canonical returns a URL whose path does not contain a recognizable post ID — e.g. a short link that failed to resolve, a gallery/comment permalink with an unexpected shape, or a non-post Reddit URL (subreddit, user page).
Common situations: Users paste subreddit/user/gallery URLs or share links (reddit.com/s/...) that canonicalization cannot turn into /comments/{id}/ form, or Reddit changes its URL structure.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- não reconheci um vídeo do Bilibili em
- Failed to detect URL kind
- Could not extract pin ID
- Expected a JSON array of cookie objects.
- cor inválida
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/16ad75cf4cdb2c75.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/platforms/reddit.rs:415
}
}
self.native_download(info, opts, progress).await
}
}
impl RedditDownloader {
async fn fallback_ytdlp(&self, url: &str) -> anyhow::Result<MediaInfo> {
let ytdlp_path = crate::core::ytdlp::ensure_ytdlp().await?;
let json = crate::core::ytdlp::get_video_info(&ytdlp_path, url, &[]).await?;
crate::platforms::generic_ytdlp::GenericYtdlpDownloader::parse_video_info(&json)
}
async fn native_get_media_info(&self, url: &str) -> anyhow::Result<MediaInfo> {
let canonical = self.resolve_to_canonical(url).await?;
let post_id = Self::extract_post_id(&canonical)
.ok_or_else(|| anyhow!("Could not extract post ID"))?;
let subreddit = Self::extract_subreddit(&canonical).unwrap_or_default();
let data = self.fetch_post_data(&post_id).await?;
let media = Self::parse_media(&data).ok_or_else(|| anyhow!("No media found in post"))?;
let source_id = if subreddit.is_empty() {
post_id.clone()
} else {
format!("{}_{}", subreddit.to_lowercase(), post_id)
};
let title = format!("reddit_{}", source_id);
match media {
RedditMedia::Video {
video_url,View on GitHub (pinned to 8600b91f42)