tonhowtf/omniget · error

não reconheci o vídeo do YouTube

Error message

não reconheci o vídeo do YouTube

What it means

build_payload validates that the video ID string is exactly 11 characters, the canonical length of a YouTube video ID, before constructing the POST /api/skipSegments body. Anything else is rejected early so a malformed ID never reaches SponsorBlock.

Solutions

  1. Extract just the 11-character ID (e.g. from the v= query parameter or youtu.be path) before calling build_payload.
  2. Reuse the library's own video_id(&url) helper (as submit does) instead of manual parsing.
  3. Trim whitespace and strip query strings from the ID string.
  4. Log the ID and its length on failure; note this error is raised by build_payload, whereas submit raises the distinct 'nao reconheci um video do YouTube em: {}' message.

Example fix

// before
let id = "https://youtu.be/dQw4w9WgXcQ?t=1"; // 27 chars
// after
let id = video_id(url).ok_or_else(|| anyhow!("URL inválida"))?; // "dQw4w9WgXcQ"
Defensive patterns

Strategy: validation

Validate before calling

fn is_youtube_id(id: &str) -> bool {
    id.len() == 11 && id.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
}

Type guard

fn as_video_id(s: &str) -> Option<&str> {
    (s.len() == 11).then_some(s)
}

Try / catch

match build_payload(&id, &user, dur, &segs) {
    Err(e) if e.to_string().contains("não reconheci o vídeo") => eprintln!("ID inválido: {:?} (len={})", id, id.len()),
    other => other?,
}

Prevention

When it happens

Trigger: Passing a full URL, an 11+-character string with extra characters, a shortened youtu.be path, or an empty string as the video_id argument to build_payload (or as the ID resolved from submit's url).

Common situations: Extracting the ID with a regex that also captures query parameters (&t=90s); passing the whole watch?v= URL instead of the v parameter; IDs from oEmbed/short links with padding or whitespace.

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/a83d2140c6abd3c9. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/sponsorblock.rs:268

        .collect();
    cortes.sort_by(|a, b| a.start.total_cmp(&b.start));
    for par in cortes.windows(2) {
        if par[1].start < par[0].end {
            return Err(anyhow!("dois trechos se sobrepõem em {:.1}s", par[1].start));
        }
    }
    Ok(())
}

/// O corpo exato do `POST /api/skipSegments`.
pub fn build_payload(
    video_id: &str,
    user_id: &str,
    duration: f64,
    segments: &[NewSegment],
) -> anyhow::Result<serde_json::Value> {
    if video_id.len() != 11 {
        return Err(anyhow!("não reconheci o vídeo do YouTube"));
    }
    if user_id.trim().len() < 30 {
        return Err(anyhow!("a chave local do SponsorBlock está corrompida"));
    }
    validate_segments(segments, duration)?;
    let segs: Vec<serde_json::Value> = segments
        .iter()
        .map(|s| {
            let mut o = serde_json::json!({
                "segment": [s.start, s.end],
                "category": s.category,
                "actionType": s.action_type,
            });
            if !s.description.trim().is_empty() {
                o["description"] = serde_json::Value::String(s.description.trim().to_string());
            }
            o
        })

View on GitHub (pinned to 8600b91f42)