yt_transcript_rs/
lib.rs

1//! # yt-transcript-rs
2//!
3//! A Rust library for fetching YouTube video transcripts and metadata.
4//!
5//! This library provides a robust, feature-rich interface for retrieving transcripts
6//! from YouTube videos. It can fetch transcripts in various languages, auto-generated
7//! captions, and detailed video metadata, all without using YouTube's official API
8//! (which doesn't provide transcript access).
9//!
10//! ## Key Features
11//!
12//! - **Transcript Retrieval**: Fetch transcripts in any available language
13//! - **Multi-language Support**: Request transcripts in order of language preference
14//! - **Transcript Translation**: Translate transcripts to different languages
15//! - **Formatting Preservation**: Option to keep HTML formatting in transcripts
16//! - **Video Metadata**: Retrieve detailed information about videos (title, author, etc.)
17//! - **Advanced Authentication**: Support for cookies to access restricted content
18//! - **Proxy Support**: Route requests through proxies to bypass geo-restrictions
19//!
20//! ## Simple Usage Example
21//!
22//! ```rust,no_run
23//! use yt_transcript_rs::YouTubeTranscriptApi;
24//!
25//! #[tokio::main]
26//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
27//!     // Create a new API instance
28//!     let api = YouTubeTranscriptApi::new(None, None, None)?;
29//!
30//!     // Fetch an English transcript
31//!     let transcript = api.fetch_transcript(
32//!         "dQw4w9WgXcQ",  // Video ID
33//!         &["en"],        // Preferred languages
34//!         false           // Don't preserve formatting
35//!     ).await?;
36//!
37//!     // Print the full transcript text
38//!     println!("Transcript: {}", transcript.text());
39//!
40//!     // Or work with individual snippets
41//!     for snippet in transcript.parts() {
42//!         println!("[{:.1}s]: {}", snippet.start, snippet.text);
43//!     }
44//!
45//!     Ok(())
46//! }
47//! ```
48//!
49//! ## Advanced Use Cases
50//!
51//! ### Language Preferences
52//!
53//! ```rust,no_run
54//! # use yt_transcript_rs::YouTubeTranscriptApi;
55//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
56//! let api = YouTubeTranscriptApi::new(None, None, None)?;
57//!
58//! // Try English first, then Spanish, then auto-generated
59//! let transcript = api.fetch_transcript(
60//!     "dQw4w9WgXcQ",
61//!     &["en", "es", "en-US"],
62//!     false
63//! ).await?;
64//! # Ok(())
65//! # }
66//! ```
67//!
68//! ### List Available Transcripts
69//!
70//! ```rust,no_run
71//! # use yt_transcript_rs::YouTubeTranscriptApi;
72//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
73//! let api = YouTubeTranscriptApi::new(None, None, None)?;
74//!
75//! let transcript_list = api.list_transcripts("dQw4w9WgXcQ").await?;
76//!
77//! for transcript in transcript_list.transcripts() {
78//!     println!("Language: {} ({}) - {} generated",
79//!         transcript.language(),
80//!         transcript.language_code(),
81//!         if transcript.is_generated() { "Auto" } else { "Manually" });
82//! }
83//! # Ok(())
84//! # }
85//! ```
86//!
87//! ### Fetch Video Details
88//!
89//! ```rust,no_run
90//! # use yt_transcript_rs::YouTubeTranscriptApi;
91//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
92//! let api = YouTubeTranscriptApi::new(None, None, None)?;
93//!
94//! let details = api.fetch_video_details("dQw4w9WgXcQ").await?;
95//!
96//! println!("Title: {}", details.title);
97//! println!("Author: {}", details.author);
98//! println!("Views: {}", details.view_count);
99//! # Ok(())
100//! # }
101//! ```
102
103pub mod api;
104pub mod captions_extractor;
105pub mod cookie_jar_loader;
106pub mod errors;
107pub mod fetched_transcript;
108pub mod innertube_client;
109pub mod js_var_parser;
110pub mod microformat_extractor;
111pub mod models;
112pub mod playability_asserter;
113pub mod proxies;
114pub mod streaming_data_extractor;
115pub mod tests;
116pub mod transcript;
117pub mod transcript_list;
118pub mod transcript_parser;
119pub mod video_data_fetcher;
120pub mod video_details_extractor;
121pub mod youtube_page_fetcher;
122
123pub use api::YouTubeTranscriptApi;
124pub use cookie_jar_loader::CookieJarLoader;
125pub use errors::{
126    AgeRestricted, CookieError, CookieInvalid, CookiePathInvalid, CouldNotRetrieveTranscript,
127    FailedToCreateConsentCookie, InvalidVideoId, IpBlocked, NoTranscriptFound, NotTranslatable,
128    RequestBlocked, TranscriptsDisabled, TranslationLanguageNotAvailable, VideoUnavailable,
129    VideoUnplayable, YouTubeDataUnparsable, YouTubeRequestFailed, YouTubeTranscriptApiError,
130};
131
132pub use captions_extractor::CaptionsExtractor;
133pub use fetched_transcript::FetchedTranscript;
134pub use models::FetchedTranscriptSnippet;
135pub use models::VideoDetails;
136pub use models::VideoInfos;
137pub use models::VideoThumbnail;
138pub use models::{ColorInfo, Range, StreamingData, StreamingFormat};
139pub use models::{MicroformatData, MicroformatEmbed, MicroformatThumbnail};
140pub use playability_asserter::PlayabilityAsserter;
141pub use streaming_data_extractor::StreamingDataExtractor;
142pub use transcript::Transcript;
143pub use transcript_list::TranscriptList;
144pub use video_details_extractor::VideoDetailsExtractor;
145pub use youtube_page_fetcher::YoutubePageFetcher;