Skip to content

Sometimes gives error for the same video #2

Description

@pookdeveloper

Sometimes the same video downloads it well and others gives error:

This is the video i try: https://www.youtube.com/watch?v=qS_2Tj7_RPw&list=PLT3fdhY8N7jiyQJZbzBAvPkHjgRm2gmot&index=3

Failed: Failed to extract transcript
Caused by: Failed to fetch transcript using yt-transcript-rs
Caused by: Could not retrieve a transcript for the video qS_2Tj7_RPw! This is most likely caused by:

The data required to fetch the transcript is not parsable: No captions found in InnerTube response. This should not happen, please open an issue (make sure to include the video ID)!

Add an example of use:

/// YouTube Transcript Debugging Tool
///
/// Simple example to test transcript extraction with hardcoded URL
///
/// Usage:
///   cargo run --example transcript_debug

use reader_rust::scraper::youtube::YouTubeScraper;
use std::error::Error as StdError;

#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();

    // URL hardcoded - cambia esta URL para probar otros videos
    let url = "https://www.youtube.com/watch?v=qS_2Tj7_RPw&list=PLT3fdhY8N7jiyQJZbzBAvPkHjgRm2gmot&index=3";
    let language = "es";

    println!("🔍 Testing YouTube Transcript Extraction");
    println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
    println!("📹 URL: {}", url);
    println!("🌍 Language: {}\n", language);

    // Create scraper with verbose mode to see all steps
    let scraper = YouTubeScraper::with_verbose(true);

    // Attempt to extract transcript
    println!("🚀 Extracting transcript...\n");

    match scraper.scrape_with_language(url, language).await {
        Ok(transcript) => {
            println!("\n✅ SUCCESS!\n");
            println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
            println!("\n📊 Transcript Information:\n");
            println!("   Title:        {}", transcript.metadata.title);
            println!("   Author:       {}", transcript.metadata.author);
            println!("   Duration:     {}", transcript.metadata.duration);
            println!("   Language:     {}", transcript.language);
            println!("   Segments:     {}", transcript.segments.len());
            
            if let Some(ref date) = transcript.metadata.upload_date {
                println!("   Upload Date:  {}", date);
            }
            
            if let Some(ref views) = transcript.metadata.view_count {
                println!("   Views:        {}", views);
            }

            println!("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
            println!("\n📝 First 5 segments:\n");
            
            for (i, segment) in transcript.segments.iter().take(5).enumerate() {
                println!(
                    "   {}. [{}] {}",
                    i + 1,
                    segment.format_timestamp(),
                    segment.text.trim()
                );
            }
            
            if transcript.segments.len() > 5 {
                println!("\n   ... and {} more segments", transcript.segments.len() - 5);
            }

            println!("\n🎉 Done!\n");
        }
        Err(e) => {
            eprintln!("\n❌ ERROR!\n");
            eprintln!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
            eprintln!("\n🔴 Error Details:\n");
            
            // Print main error
            eprintln!("   {}", e);
            
            // Print the full error chain
            let mut source: Option<&dyn StdError> = e.source();
            let mut level = 1;
            
            while let Some(err) = source {
                eprintln!("   {} Caused by: {}", "  ".repeat(level), err);
                source = err.source();
                level += 1;
            }
            
            eprintln!("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
            std::process::exit(1);
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions