Struct FetchedTranscript

Source
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 client = reqwest::Client::new();
let fetched = transcript.fetch(&client, 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

Source

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);
Source

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
// Get the full text as a single string
let full_text = fetched.text();
println!("Transcript: {}", full_text);
Source

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
// 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);
    }
}
Source

pub fn language(&self) -> &str

Returns the language of this transcript.

§Returns

The human-readable language name (e.g., “English”, “Español”)

Source

pub fn language_code(&self) -> &str

Returns the language code of this transcript.

§Returns

The language code (e.g., “en”, “es”, “fr-CA”)

Source

pub fn is_generated(&self) -> bool

Returns whether this transcript was automatically generated.

§Returns

true if automatically generated by YouTube, false if manually created

Source

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
println!("Video duration: {:.2} seconds", fetched.duration());

Trait Implementations§

Source§

impl Clone for FetchedTranscript

Source§

fn clone(&self) -> FetchedTranscript

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FetchedTranscript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for FetchedTranscript

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> IntoIterator for &'a FetchedTranscript

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, FetchedTranscriptSnippet>

Which kind of iterator are we turning this into?
Source§

impl IntoIterator for FetchedTranscript

Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator that takes ownership of the transcript.

This allows iterating over and consuming the transcript segments.

Source§

type Item = FetchedTranscriptSnippet

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<FetchedTranscript as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

impl Serialize for FetchedTranscript

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T