tonhowtf/omniget · error

Invalid P2P URL

Error message

Invalid P2P URL: {}

What it means

get_media_info() requires URLs with the 'p2p:' scheme; any URL lacking this prefix is rejected. The scheme is the library's marker that a URL refers to a P2P share-code transfer. This is a strict input-format guard before the share code is validated.

Solutions

  1. Prefix the share code with 'p2p:' before calling get_media_info
  2. Route the URL to the correct platform handler if it is not a P2P transfer
  3. Trim whitespace/normalize the URL scheme before dispatching

Example fix

// before
platform.get_media_info("abcdef123").await?;
// after
platform.get_media_info("p2p:abcdef123").await?;
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_p2p_url(url: &str) -> Result<(), String> {
    if url.trim().starts_with("p2p:") { Ok(()) } else { Err(format!("URL must start with p2p:, got: {url}")) }
}

Try / catch

match platform.get_media_info(url).await {
    Err(e) if e.to_string().contains("Invalid P2P URL") => {
        eprintln!("Pass a 'p2p:<code>' URL, not: {url}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling get_media_info with a URL that does not start with 'p2p:' (e.g. a plain https URL, empty string, or a mistyped scheme like 'p2p//code').

Common situations: Passing a normal HTTP media URL into the P2P platform handler; user pastes code without the 'p2p:' prefix; upstream code that selects the wrong platform for a URL.

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


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

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/p2p.rs:76

}

#[async_trait]
impl PlatformDownloader for P2pDownloader {
    fn name(&self) -> &str {
        "p2p"
    }

    fn can_handle(&self, url: &str) -> bool {
        if let Some(code) = url.strip_prefix("p2p:") {
            return super::p2p_words::is_valid_code(code);
        }
        false
    }

    async fn get_media_info(&self, url: &str) -> anyhow::Result<MediaInfo> {
        let code = url
            .strip_prefix("p2p:")
            .ok_or_else(|| anyhow!("Invalid P2P URL: {}", url))?;

        if !super::p2p_words::is_valid_code(code) {
            anyhow::bail!("Invalid share code: {}", code);
        }

        let title = format!("P2P Transfer ({})", &code[..code.len().min(30)]);

        Ok(MediaInfo {
            title,
            author: "P2P Transfer".to_string(),
            platform: "p2p".to_string(),
            duration_seconds: None,
            thumbnail_url: None,
            available_qualities: vec![VideoQuality {
                label: "Original".to_string(),
                width: 0,
                height: 0,
                url: url.to_string(),

View on GitHub (pinned to 8600b91f42)