Struct TranscriptList

Source
pub struct TranscriptList {
    pub video_id: String,
    pub manually_created_transcripts: HashMap<String, Transcript>,
    pub generated_transcripts: HashMap<String, Transcript>,
    pub translation_languages: Vec<TranslationLanguage>,
}
Expand description

§TranscriptList

A collection of available transcripts for a YouTube video.

This struct provides access to all transcripts available for a video, including:

  • Manually created transcripts (by the video owner or contributors)
  • Automatically generated transcripts (created by YouTube’s speech recognition)
  • Available translation languages for translatable transcripts

The TranscriptList differentiates between manually created and automatically generated transcripts, as the manually created ones tend to be more accurate. This allows you to prioritize manually created transcripts over automatically generated ones.

§Usage Example

let api = YouTubeTranscriptApi::new(None, None, None)?;

// Get a list of all available transcripts for a video
let transcript_list = api.list_transcripts("dQw4w9WgXcQ").await?;

// Print all available transcripts
println!("Available transcripts: {}", transcript_list);

// Find a transcript in a specific language (prioritizing English)
let transcript = transcript_list.find_transcript(&["en", "en-US"])?;

// Or specifically find a manually created transcript
let manual_transcript = transcript_list.find_manually_created_transcript(&["en"])?;

// Or retrieve an automatically generated transcript
let auto_transcript = transcript_list.find_generated_transcript(&["en"])?;

Fields§

§video_id: String

The YouTube video ID this transcript list belongs to

§manually_created_transcripts: HashMap<String, Transcript>

Map of language codes to manually created transcripts

§generated_transcripts: HashMap<String, Transcript>

Map of language codes to automatically generated transcripts

§translation_languages: Vec<TranslationLanguage>

List of languages available for translation

Implementations§

Source§

impl TranscriptList

Source

pub fn new( video_id: String, manually_created_transcripts: HashMap<String, Transcript>, generated_transcripts: HashMap<String, Transcript>, translation_languages: Vec<TranslationLanguage>, ) -> Self

Creates a new TranscriptList with the provided components.

§Parameters
  • video_id - The YouTube video ID this transcript list belongs to
  • manually_created_transcripts - Map of language codes to manually created transcripts
  • generated_transcripts - Map of language codes to automatically generated transcripts
  • translation_languages - List of languages available for translation
§Returns

A new TranscriptList instance

Source

pub fn build( video_id: String, video_page_html: &Value, ) -> Result<Self, CouldNotRetrieveTranscript>

Creates a TranscriptList from YouTube’s caption JSON data.

This method parses YouTube’s internal caption data structure to extract:

  • Available transcripts (both manual and automatic)
  • Their respective language codes and names
  • Information about available translation languages
§Parameters
  • video_id - The YouTube video ID
  • video_page_html - JSON data extracted from YouTube’s page containing caption information
§Returns
  • Result<Self, CouldNotRetrieveTranscript> - A transcript list or an error
§Errors

Returns an error if the caption data cannot be properly parsed.

Source

pub fn build_without_client( video_id: String, video_page_html: &Value, ) -> Result<Self, CouldNotRetrieveTranscript>

Creates a TranscriptList from YouTube’s caption JSON data without requiring a client.

This method is similar to build but doesn’t take a client parameter, making it suitable for use in serialization/deserialization contexts.

§Parameters
  • video_id - The YouTube video ID
  • video_page_html - JSON data extracted from YouTube’s page containing caption information
§Returns
  • Result<Self, CouldNotRetrieveTranscript> - A transcript list or an error
§Errors

Returns an error if the caption data cannot be properly parsed.

Source

pub fn find_transcript( &self, language_codes: &[&str], ) -> Result<Transcript, CouldNotRetrieveTranscript>

Finds a transcript matching one of the specified language codes.

This method searches for transcripts in the order of priority:

  1. Manually created transcripts with the specified language codes (in order)
  2. Automatically generated transcripts with the specified language codes (in order)
§Parameters
  • language_codes - Array of language codes to search for, in order of preference
§Returns
  • Result<Transcript, CouldNotRetrieveTranscript> - Matching transcript or an error
§Errors

Returns an error if no transcript is found for any of the specified language codes.

§Example
let api = YouTubeTranscriptApi::new(None, None, None)?;
let transcript_list = api.list_transcripts("dQw4w9WgXcQ").await?;

// Try to find English, fall back to Spanish, then auto-generated English
let transcript = transcript_list.find_transcript(&["en", "es", "en-US"])?;
Source

pub fn find_manually_created_transcript( &self, language_codes: &[&str], ) -> Result<Transcript, CouldNotRetrieveTranscript>

Finds a manually created transcript matching one of the specified language codes.

This method only searches the manually created transcripts, skipping any automatically generated ones. This is useful when you want to ensure you’re getting a human-created transcript for better accuracy.

§Parameters
  • language_codes - Array of language codes to search for, in order of preference
§Returns
  • Result<Transcript, CouldNotRetrieveTranscript> - Matching transcript or an error
§Errors

Returns an error if no manually created transcript is found for any of the specified language codes.

§Example
let api = YouTubeTranscriptApi::new(None, None, None)?;
let transcript_list = api.list_transcripts("dQw4w9WgXcQ").await?;

// Only look for manually created transcripts
match transcript_list.find_manually_created_transcript(&["en"]) {
    Ok(transcript) => {
        println!("Found manual transcript!");
    },
    Err(_) => {
        println!("No manual transcript available, falling back to auto-generated");
        let auto_transcript = transcript_list.find_generated_transcript(&["en"])?;
    }
}
Source

pub fn find_generated_transcript( &self, language_codes: &[&str], ) -> Result<Transcript, CouldNotRetrieveTranscript>

Finds an automatically generated transcript matching one of the specified language codes.

This method only searches the automatically generated transcripts, skipping any manually created ones. This might be useful in rare cases where you specifically want the auto-generated version.

§Parameters
  • language_codes - Array of language codes to search for, in order of preference
§Returns
  • Result<Transcript, CouldNotRetrieveTranscript> - Matching transcript or an error
§Errors

Returns an error if no automatically generated transcript is found for any of the specified language codes.

Source

pub fn transcripts(&self) -> impl Iterator<Item = &Transcript>

Returns a reference to all available transcripts.

This method provides access to both manually created and automatically generated transcripts as an iterator.

§Returns

An iterator over references to all available transcripts.

§Example
let api = YouTubeTranscriptApi::new(None, None, None)?;
let transcript_list = api.list_transcripts("dQw4w9WgXcQ").await?;

// Print info about all available transcripts
for transcript in transcript_list.transcripts() {
    println!("Language: {} ({}), Auto-generated: {}",
        transcript.language(),
        transcript.language_code(),
        transcript.is_generated());
}

Trait Implementations§

Source§

impl Clone for TranscriptList

Source§

fn clone(&self) -> TranscriptList

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 TranscriptList

Source§

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

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

impl<'de> Deserialize<'de> for TranscriptList

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 Display for TranscriptList

Source§

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

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

impl<'a> IntoIterator for &'a TranscriptList

Source§

type Item = &'a Transcript

The type of the elements being iterated over.
Source§

type IntoIter = Chain<Map<Values<'a, String, Transcript>, fn(&'a Transcript) -> &'a Transcript>, Map<Values<'a, String, Transcript>, fn(&'a Transcript) -> &'a Transcript>>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for TranscriptList

Source§

type Item = Transcript

The type of the elements being iterated over.
Source§

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

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Serialize for TranscriptList

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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