Retrieves the list of transcripts which are available for a given video. It returns a `TranscriptList` object which is iterable and provides methods to filter the list of transcripts for specific languages. While iterating over the `TranscriptList` the individual tra
(
self,
video_id: str,
)
| 74 | ) |
| 75 | |
| 76 | def list( |
| 77 | self, |
| 78 | video_id: str, |
| 79 | ) -> TranscriptList: |
| 80 | """ |
| 81 | Retrieves the list of transcripts which are available for a given video. It |
| 82 | returns a `TranscriptList` object which is iterable and provides methods to |
| 83 | filter the list of transcripts for specific languages. While iterating over |
| 84 | the `TranscriptList` the individual transcripts are represented by |
| 85 | `Transcript` objects, which provide metadata and can either be fetched by |
| 86 | calling `transcript.fetch()` or translated by calling `transcript.translate( |
| 87 | 'en')`. Example: |
| 88 | |
| 89 | ``` |
| 90 | ytt_api = YouTubeTranscriptApi() |
| 91 | |
| 92 | # retrieve the available transcripts |
| 93 | transcript_list = ytt_api.list('video_id') |
| 94 | |
| 95 | # iterate over all available transcripts |
| 96 | for transcript in transcript_list: |
| 97 | # the Transcript object provides metadata properties |
| 98 | print( |
| 99 | transcript.video_id, |
| 100 | transcript.language, |
| 101 | transcript.language_code, |
| 102 | # whether it has been manually created or generated by YouTube |
| 103 | transcript.is_generated, |
| 104 | # a list of languages the transcript can be translated to |
| 105 | transcript.translation_languages, |
| 106 | ) |
| 107 | |
| 108 | # fetch the actual transcript data |
| 109 | print(transcript.fetch()) |
| 110 | |
| 111 | # translating the transcript will return another transcript object |
| 112 | print(transcript.translate('en').fetch()) |
| 113 | |
| 114 | # you can also directly filter for the language you are looking for, using the transcript list |
| 115 | transcript = transcript_list.find_transcript(['de', 'en']) |
| 116 | |
| 117 | # or just filter for manually created transcripts |
| 118 | transcript = transcript_list.find_manually_created_transcript(['de', 'en']) |
| 119 | |
| 120 | # or automatically generated ones |
| 121 | transcript = transcript_list.find_generated_transcript(['de', 'en']) |
| 122 | ``` |
| 123 | |
| 124 | :param video_id: the ID of the video you want to retrieve the transcript for. |
| 125 | Make sure that this is the actual ID, NOT the full URL to the video! |
| 126 | """ |
| 127 | return self._fetcher.fetch(video_id) |