Skip to content

v0.1.0

Latest

Choose a tag to compare

@rudrodip rudrodip released this 15 May 18:28

v0.1.0 - 2024-05-16

Overview

ytranscript is a Rust crate that provides functionality to fetch YouTube video transcripts. It supports fetching transcripts in different languages and handles various error scenarios that might occur while retrieving the transcripts.

cargo: https://crates.io/crates/ytranscript
docs: https://docs.rs/ytranscript/0.1.0

Features

  • YouTube Video ID Extraction: Extracts YouTube video IDs from URLs or strings.
  • Transcript Fetching: Fetches transcripts for YouTube videos.
  • Language Support: Supports fetching transcripts in specific languages.
  • Error Handling: Handles common errors such as video unavailability, transcript unavailability, and too many requests.

Installation

Add ytranscript to your Cargo.toml:

[dependencies]
ytranscript = "0.1.0"

Ensure you also add the required dependencies:

[dependencies]
reqwest = { version = "0.11", features = ["json"] }
regex = "1"
serde = { version = "1", features = ["derive"] }
thiserror = "1"
tokio = { version = "1", features = ["full"] }
serde_json = "1"

Usage

Here is an example of how to use the ytranscript crate in a binary crate:

use ytranscript::YoutubeTranscript;
use std::env;

#[tokio::main]
async fn main() {
    // Get the video ID from command line arguments
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        eprintln!("Usage: ytranscript_bin <video_id>");
        return;
    }
    let video_id = &args[1];

    // Fetch the transcript
    match YoutubeTranscript::fetch_transcript(video_id, None).await {
        Ok(transcript) => {
            for entry in transcript {
                println!("{:?}", entry);
            }
        }
        Err(e) => {
            eprintln!("Error: {}", e);
        }
    }
}

Documentation

Documentation for the ytranscript crate can be found here.

Contribution

Feel free to contribute to this project by submitting issues or pull requests.

License

This project is licensed under the MIT License. See the LICENSE file for details.