tonhowtf/omniget · error

Could not extract post ID

Error message

Could not extract post ID

What it means

native_get_media_info first canonicalizes the URL and then runs extract_post_id on it; if no post ID can be parsed from the canonical URL, the library aborts with this error before making any network request.

Solutions

  1. Log the canonical URL right before extract_post_id and extend its regex to cover the missed URL shape.
  2. Normalize common forms first: strip query strings, handle redd.it/<id>, /comments/<id> anywhere in the path, and old.reddit/locale prefixes.
  3. Reject non-post URLs early with a clear 'not a Reddit post URL' validation message.
  4. Resolve share/redirect links (follow HTTP redirects) to a canonical /comments/<id> URL before extraction.
  5. Add unit tests for the URL shapes your users actually paste.

Example fix

// before
let post_id = Self::extract_post_id(&canonical)
    .ok_or_else(|| anyhow!("Could not extract post ID"))?;
// after
let post_id = Self::extract_post_id(&canonical).or_else(|| {
    regex::Regex::new(r"(?:comments|redd\.it)/([a-z0-9]{4,10})")
        .ok()
        .and_then(|re| re.captures(&canonical))
        .and_then(|c| c.get(1).map(|m| m.as_str().to_string()))
}).ok_or_else(|| anyhow!("Could not extract post ID from URL: {}", canonical))?;
Defensive patterns

Strategy: validation

Validate before calling

// regex pre-check before calling the API
let re = regex::Regex::new(r"(?:comments/|redd\.it/)([a-z0-9]{4,10})").unwrap();
if !re.is_match(&url) { return Err("not a Reddit post URL"); }

Type guard

fn extract_post_id_url_guard(url: &str) -> Option<String> {
    regex::Regex::new(r"(?:comments/|redd\.it/)([a-z0-9]{4,10})")
        .ok()
        .and_then(|re| re.captures(url))
        .and_then(|c| c.get(1).map(|m| m.as_str().to_string()))
}

Try / catch

match get_media_info(&user_url).await {
    Err(e) if e.to_string().contains("Could not extract post ID") => notify("Please paste a direct Reddit post link"),
    other => other,
}

Prevention

When it happens

Trigger: Passing URLs that resolve to non-comment-permalink forms: subreddit pages, user pages, gallery/crosspost links where the ID is nested differently, old.reddit/share URLs with unexpected path shapes, or malformed input (empty string, non-Reddit URL).

Common situations: Users pasting a share link (reddit.com/share/...), a redd.it short link whose regex is unsupported, a live/thread URL, or a mobile app URL (reddit://); locale-prefixed or old.reddit variants the extractor misses.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/3a4907c008b3b614. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/platforms/reddit/mod.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)