Merge pull request #229 from nbonato/patch-1

Clarify language rules in README.md
This commit is contained in:
Jonas Depoix 2023-10-14 18:56:57 +02:00 committed by GitHub
commit f500cb5e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -31,6 +31,8 @@ from youtube_transcript_api import YouTubeTranscriptApi
YouTubeTranscriptApi.get_transcript(video_id) YouTubeTranscriptApi.get_transcript(video_id)
``` ```
> **Note:** By default, this will try to access the English transcript of the video. If your video has a different language, or you are interested in fetching a different language's transcript, please read the section below.
This will return a list of dictionaries looking somewhat like this: This will return a list of dictionaries looking somewhat like this:
```python ```python
@ -48,20 +50,27 @@ This will return a list of dictionaries looking somewhat like this:
# ... # ...
] ]
``` ```
### Translate transcript ### Retrieve different languages
You can add the `languages` param if you want to make sure the transcripts are retrieved in your desired language (it defaults to english). You can add the `languages` param if you want to make sure the transcripts are retrieved in your desired language (it defaults to english).
```python ```python
YouTubeTranscriptApi.get_transcripts(video_ids, languages=['de', 'en']) YouTubeTranscriptApi.get_transcript(video_id, languages=['de', 'en'])
``` ```
It's a list of language codes in a descending priority. In this example it will first try to fetch the german transcript (`'de'`) and then fetch the english transcript (`'en'`) if it fails to do so. If you want to find out which languages are available first, [have a look at `list_transcripts()`](#list-available-transcripts) It's a list of language codes in a descending priority. In this example it will first try to fetch the german transcript (`'de'`) and then fetch the english transcript (`'en'`) if it fails to do so. If you want to find out which languages are available first, [have a look at `list_transcripts()`](#list-available-transcripts).
If you only want one language, you still need to format the `languages` argument as a list
```python
YouTubeTranscriptApi.get_transcript(video_id, languages=['de'])
```
### Batch fetching of transcripts
To get transcripts for a list of video ids you can call: To get transcripts for a list of video ids you can call:
```python ```python
YouTubeTranscriptApi.get_transcripts(video_ids, languages=['de', 'en']) YouTubeTranscriptApi.get_transcripts(["video_id1", "video_id2"], languages=['de', 'en'])
``` ```
`languages` also is optional here. `languages` also is optional here.