pub struct FetchedTranscript {
pub snippets: Vec<FetchedTranscriptSnippet>,
pub video_id: String,
pub language: String,
pub language_code: String,
pub is_generated: bool,
}
Expand description
A complete transcript with all the snippets and metadata.
This struct represents a successfully fetched transcript from YouTube, containing both the full text content (divided into timed segments) and metadata about the transcript.
A FetchedTranscript
is typically obtained by calling fetch()
on a Transcript
object. It provides the actual transcript content, whereas Transcript
is more
like a handle for fetching.
§Features
- Contains all text segments with their timing information
- Provides metadata about the transcript (language, source, etc.)
- Can be iterated over to access individual segments
- Supports conversion to various formats for storage or display
§Example
let api = YouTubeTranscriptApi::new(None, None, None)?;
let transcript_list = api.list_transcripts("dQw4w9WgXcQ").await?;
let transcript = transcript_list.find_transcript(&["en"])?;
// Fetch the actual transcript content
let fetched = transcript.fetch(false).await?;
// Access the full text
println!("Full transcript: {}", fetched.text());
// Or work with individual segments
for segment in &fetched {
println!("[{:.1}s - {:.1}s]: {}",
segment.start,
segment.start + segment.duration,
segment.text);
}
Fields§
§snippets: Vec<FetchedTranscriptSnippet>
The list of transcript snippets (text segments with timing information).
video_id: String
YouTube video ID this transcript belongs to.
language: String
Human-readable language name (e.g., “English”, “Español”).
language_code: String
Language code (e.g., “en”, “fr”, “es-MX”).
is_generated: bool
Whether this transcript was automatically generated by YouTube.
true
indicates an auto-generated transcript (using speech recognition),
while false
indicates a manually created transcript (typically more accurate).
Implementations§
Source§impl FetchedTranscript
impl FetchedTranscript
Sourcepub fn to_raw_data(&self) -> Vec<HashMap<String, Value>>
pub fn to_raw_data(&self) -> Vec<HashMap<String, Value>>
Converts the transcript to a raw data format suitable for serialization.
This method transforms the transcript into a vector of hashmaps containing the text, start time, and duration for each segment. This format is useful for JSON serialization or for integrating with other systems.
§Returns
A vector of hashmaps, each representing one transcript segment with keys:
- “text”: The segment text
- “start”: The start time in seconds
- “duration”: The segment duration in seconds
§Example
// Convert to raw data (array of objects)
let raw_data = fetched.to_raw_data();
// Serialize to JSON
let json = serde_json::to_string_pretty(&raw_data)?;
println!("JSON transcript:\n{}", json);
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Returns the full transcript text as a single string.
This method combines all transcript segments into a single string, with each segment separated by a space.
§Returns
A String containing the full transcript text.
§Example
let fetched = transcript.fetch(false).await?;
// Get the full text as a single string
let full_text = fetched.text();
println!("Transcript: {}", full_text);
Sourcepub fn parts(&self) -> &[FetchedTranscriptSnippet]
pub fn parts(&self) -> &[FetchedTranscriptSnippet]
Returns a reference to the individual transcript segments.
This method provides access to the raw transcript segments, each containing text with its corresponding timing information.
§Returns
A slice of FetchedTranscriptSnippet
objects.
§Example
let fetched = transcript.fetch(false).await?;
// Access individual segments
for segment in fetched.parts() {
// Find segments mentioning a specific word
if segment.text.to_lowercase().contains("never") {
println!("Found at {}s: {}", segment.start, segment.text);
}
}
Sourcepub fn language(&self) -> &str
pub fn language(&self) -> &str
Returns the language of this transcript.
§Returns
The human-readable language name (e.g., “English”, “Español”)
Sourcepub fn language_code(&self) -> &str
pub fn language_code(&self) -> &str
Returns the language code of this transcript.
§Returns
The language code (e.g., “en”, “es”, “fr-CA”)
Sourcepub fn is_generated(&self) -> bool
pub fn is_generated(&self) -> bool
Returns whether this transcript was automatically generated.
§Returns
true
if automatically generated by YouTube, false
if manually created
Sourcepub fn duration(&self) -> f64
pub fn duration(&self) -> f64
Returns the total duration of the transcript in seconds.
This calculates the end time of the last segment in the transcript.
§Returns
The total duration in seconds as a f64, or 0.0 if the transcript is empty.
§Example
let fetched = transcript.fetch(false).await?;
println!("Video duration: {:.2} seconds", fetched.duration());
Trait Implementations§
Source§impl Clone for FetchedTranscript
impl Clone for FetchedTranscript
Source§fn clone(&self) -> FetchedTranscript
fn clone(&self) -> FetchedTranscript
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for FetchedTranscript
impl Debug for FetchedTranscript
Source§impl<'de> Deserialize<'de> for FetchedTranscript
impl<'de> Deserialize<'de> for FetchedTranscript
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a> IntoIterator for &'a FetchedTranscript
impl<'a> IntoIterator for &'a FetchedTranscript
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Creates an iterator that borrows the transcript.
This allows iterating over the transcript segments without taking ownership.
Source§type Item = &'a FetchedTranscriptSnippet
type Item = &'a FetchedTranscriptSnippet
Source§type IntoIter = Iter<'a, FetchedTranscriptSnippet>
type IntoIter = Iter<'a, FetchedTranscriptSnippet>
Source§impl IntoIterator for FetchedTranscript
impl IntoIterator for FetchedTranscript
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Creates an iterator that takes ownership of the transcript.
This allows iterating over and consuming the transcript segments.